]>
Commit | Line | Data |
---|---|---|
820c59f4 GB |
1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ |
2 | /* | |
3 | * viking | |
82aa018d | 4 | * Copyright (C) 2009-2010, Guilhem Bonnefille <guilhem.bonnefille@gmail.com> |
820c59f4 GB |
5 | * |
6 | * viking is free software: you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation, either version 3 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * viking is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
14 | * See the GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License along | |
17 | * with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
aa69d106 GB |
19 | |
20 | /** | |
21 | * SECTION:vikmapsource | |
22 | * @short_description: the base class to describe map source | |
23 | * | |
24 | * The #VikMapSource class is both the interface and the base class | |
25 | * for the hierarchie of map source. | |
26 | */ | |
820c59f4 GB |
27 | #ifdef HAVE_CONFIG_H |
28 | #include "config.h" | |
29 | #endif | |
30 | ||
31 | #include "vikviewport.h" | |
32 | #include "vikcoord.h" | |
33 | #include "mapcoord.h" | |
4e815e90 | 34 | #include "download.h" |
820c59f4 GB |
35 | #include "vikmapsource.h" |
36 | ||
37 | static void vik_map_source_init (VikMapSource *object); | |
38 | static void vik_map_source_finalize (GObject *object); | |
39 | static void vik_map_source_class_init (VikMapSourceClass *klass); | |
40 | ||
c81ded98 | 41 | static gboolean _supports_download_only_new (VikMapSource *object); |
0f08bd0d | 42 | |
d840e6de | 43 | G_DEFINE_ABSTRACT_TYPE (VikMapSource, vik_map_source, G_TYPE_OBJECT); |
820c59f4 | 44 | |
820c59f4 GB |
45 | static void |
46 | vik_map_source_init (VikMapSource *object) | |
47 | { | |
48 | /* TODO: Add initialization code here */ | |
49 | } | |
50 | ||
51 | static void | |
52 | vik_map_source_finalize (GObject *object) | |
53 | { | |
54 | /* TODO: Add deinitalization code here */ | |
55 | ||
56 | G_OBJECT_CLASS (vik_map_source_parent_class)->finalize (object); | |
57 | } | |
58 | ||
59 | static void | |
60 | vik_map_source_class_init (VikMapSourceClass *klass) | |
61 | { | |
62 | GObjectClass* object_class = G_OBJECT_CLASS (klass); | |
63 | ||
82aa018d | 64 | klass->get_copyright = NULL; |
53ac8302 GB |
65 | klass->get_license = NULL; |
66 | klass->get_license_url = NULL; | |
26336cf0 | 67 | klass->get_logo = NULL; |
2eb18edc | 68 | klass->get_name = NULL; |
820c59f4 | 69 | klass->get_uniq_id = NULL; |
db03733a | 70 | klass->get_label = NULL; |
820c59f4 GB |
71 | klass->get_tilesize_x = NULL; |
72 | klass->get_tilesize_y = NULL; | |
73 | klass->get_drawmode = NULL; | |
2673b29d | 74 | klass->is_direct_file_access = NULL; |
0fb11294 | 75 | klass->is_mbtiles = NULL; |
c81ded98 | 76 | klass->supports_download_only_new = _supports_download_only_new; |
e633ddef RN |
77 | klass->get_zoom_min = NULL; |
78 | klass->get_zoom_max = NULL; | |
2113a507 RN |
79 | klass->get_lat_min = NULL; |
80 | klass->get_lat_max = NULL; | |
81 | klass->get_lon_min = NULL; | |
82 | klass->get_lon_max = NULL; | |
820c59f4 GB |
83 | klass->coord_to_mapcoord = NULL; |
84 | klass->mapcoord_to_center_coord = NULL; | |
85 | klass->download = NULL; | |
825413ba SW |
86 | klass->download_handle_init = NULL; |
87 | klass->download_handle_cleanup = NULL; | |
820c59f4 GB |
88 | |
89 | object_class->finalize = vik_map_source_finalize; | |
90 | } | |
91 | ||
e8cf3d97 | 92 | gboolean |
c81ded98 | 93 | _supports_download_only_new (VikMapSource *self) |
0f08bd0d GB |
94 | { |
95 | // Default feature: does not support | |
96 | return FALSE; | |
97 | } | |
820c59f4 | 98 | |
68b1d6c0 GB |
99 | /** |
100 | * vik_map_source_get_copyright: | |
101 | * @self: the VikMapSource of interest. | |
102 | * @bbox: bounding box of interest. | |
103 | * @zoom: the zoom level of interest. | |
104 | * @fct: the callback function to use to return matching copyrights. | |
105 | * @data: the user data to use to call the callbaack function. | |
106 | * | |
17281ebd | 107 | * Retrieve copyright(s) for the corresponding bounding box and zoom level. |
68b1d6c0 GB |
108 | */ |
109 | void | |
551ee033 | 110 | vik_map_source_get_copyright (VikMapSource *self, LatLonBBox bbox, gdouble zoom, void (*fct)(VikViewport*,const gchar*), void *data) |
82aa018d GB |
111 | { |
112 | VikMapSourceClass *klass; | |
68b1d6c0 GB |
113 | g_return_if_fail (self != NULL); |
114 | g_return_if_fail (VIK_IS_MAP_SOURCE (self)); | |
82aa018d GB |
115 | klass = VIK_MAP_SOURCE_GET_CLASS(self); |
116 | ||
68b1d6c0 | 117 | g_return_if_fail (klass->get_copyright != NULL); |
82aa018d | 118 | |
68b1d6c0 | 119 | (*klass->get_copyright)(self, bbox, zoom, fct, data); |
82aa018d GB |
120 | } |
121 | ||
53ac8302 GB |
122 | const gchar * |
123 | vik_map_source_get_license (VikMapSource *self) | |
124 | { | |
125 | VikMapSourceClass *klass; | |
126 | g_return_val_if_fail (self != NULL, NULL); | |
127 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); | |
128 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
129 | ||
130 | g_return_val_if_fail (klass->get_license != NULL, NULL); | |
131 | ||
132 | return (*klass->get_license)(self); | |
133 | } | |
134 | ||
135 | const gchar * | |
136 | vik_map_source_get_license_url (VikMapSource *self) | |
137 | { | |
138 | VikMapSourceClass *klass; | |
139 | g_return_val_if_fail (self != NULL, NULL); | |
140 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); | |
141 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
142 | ||
143 | g_return_val_if_fail (klass->get_license_url != NULL, NULL); | |
144 | ||
145 | return (*klass->get_license_url)(self); | |
146 | } | |
147 | ||
26336cf0 GB |
148 | const GdkPixbuf * |
149 | vik_map_source_get_logo (VikMapSource *self) | |
150 | { | |
151 | VikMapSourceClass *klass; | |
152 | g_return_val_if_fail (self != NULL, NULL); | |
153 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); | |
154 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
155 | ||
156 | g_return_val_if_fail (klass->get_logo != NULL, NULL); | |
157 | ||
158 | return (*klass->get_logo)(self); | |
159 | } | |
160 | ||
2eb18edc RN |
161 | const gchar * |
162 | vik_map_source_get_name (VikMapSource *self) | |
163 | { | |
164 | VikMapSourceClass *klass; | |
165 | g_return_val_if_fail (self != NULL, NULL); | |
166 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); | |
167 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
168 | ||
169 | g_return_val_if_fail (klass->get_name != NULL, NULL); | |
170 | ||
171 | return (*klass->get_name)(self); | |
172 | } | |
173 | ||
d7e495b2 | 174 | guint16 |
820c59f4 GB |
175 | vik_map_source_get_uniq_id (VikMapSource *self) |
176 | { | |
177 | VikMapSourceClass *klass; | |
d7e495b2 RN |
178 | g_return_val_if_fail (self != NULL, (guint16 )0); |
179 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0); | |
820c59f4 GB |
180 | klass = VIK_MAP_SOURCE_GET_CLASS(self); |
181 | ||
d7e495b2 | 182 | g_return_val_if_fail (klass->get_uniq_id != NULL, (guint16 )0); |
820c59f4 GB |
183 | |
184 | return (*klass->get_uniq_id)(self); | |
185 | } | |
186 | ||
db03733a GB |
187 | const gchar * |
188 | vik_map_source_get_label (VikMapSource *self) | |
189 | { | |
190 | VikMapSourceClass *klass; | |
191 | g_return_val_if_fail (self != NULL, NULL); | |
192 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); | |
193 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
194 | ||
195 | g_return_val_if_fail (klass->get_label != NULL, NULL); | |
196 | ||
197 | return (*klass->get_label)(self); | |
198 | } | |
199 | ||
820c59f4 GB |
200 | guint16 |
201 | vik_map_source_get_tilesize_x (VikMapSource *self) | |
202 | { | |
203 | VikMapSourceClass *klass; | |
204 | g_return_val_if_fail (self != NULL, (guint16 )0); | |
205 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0); | |
206 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
207 | ||
208 | g_return_val_if_fail (klass->get_tilesize_x != NULL, (guint16 )0); | |
209 | ||
210 | return (*klass->get_tilesize_x)(self); | |
211 | } | |
212 | ||
213 | guint16 | |
214 | vik_map_source_get_tilesize_y (VikMapSource *self) | |
215 | { | |
216 | VikMapSourceClass *klass; | |
217 | g_return_val_if_fail (self != NULL, (guint16 )0); | |
218 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0); | |
219 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
220 | ||
221 | g_return_val_if_fail (klass->get_tilesize_y != NULL, (guint16 )0); | |
222 | ||
223 | return (*klass->get_tilesize_y)(self); | |
224 | } | |
225 | ||
226 | VikViewportDrawMode | |
227 | vik_map_source_get_drawmode (VikMapSource *self) | |
228 | { | |
229 | VikMapSourceClass *klass; | |
230 | g_return_val_if_fail (self != NULL, (VikViewportDrawMode )0); | |
231 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (VikViewportDrawMode )0); | |
232 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
233 | ||
234 | g_return_val_if_fail (klass->get_drawmode != NULL, (VikViewportDrawMode )0); | |
235 | ||
236 | return (*klass->get_drawmode)(self); | |
237 | } | |
238 | ||
2673b29d RN |
239 | /** |
240 | * vik_map_source_is_direct_file_access: | |
241 | * @self: the VikMapSource of interest. | |
242 | * | |
243 | * Return true when we can bypass all this download malarky | |
0314a439 | 244 | * Treat the files as a pre generated data set in OSM tile server layout: tiledir/%d/%d/%d.png |
2673b29d RN |
245 | */ |
246 | gboolean | |
247 | vik_map_source_is_direct_file_access (VikMapSource * self) | |
248 | { | |
249 | VikMapSourceClass *klass; | |
250 | g_return_val_if_fail (self != NULL, 0); | |
251 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
252 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
253 | ||
254 | g_return_val_if_fail (klass->is_direct_file_access != NULL, 0); | |
255 | ||
256 | return (*klass->is_direct_file_access)(self); | |
257 | } | |
258 | ||
0fb11294 RN |
259 | /** |
260 | * vik_map_source_is_mbtiles: | |
261 | * @self: the VikMapSource of interest. | |
262 | * | |
263 | * Return true when the map is in an MB Tiles format. | |
264 | * See http://github.com/mapbox/mbtiles-spec | |
265 | * (Read Only ATM) | |
266 | */ | |
267 | gboolean | |
268 | vik_map_source_is_mbtiles (VikMapSource * self) | |
269 | { | |
270 | VikMapSourceClass *klass; | |
271 | g_return_val_if_fail (self != NULL, 0); | |
272 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
273 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
274 | ||
275 | g_return_val_if_fail (klass->is_mbtiles != NULL, 0); | |
276 | ||
277 | return (*klass->is_mbtiles)(self); | |
278 | } | |
279 | ||
99f0d7df RN |
280 | /** |
281 | * vik_map_source_is_osm_meta_tiles: | |
282 | * @self: the VikMapSource of interest. | |
283 | * | |
284 | * Treat the files as a pre generated data set directly by tirex or renderd | |
285 | * tiledir/Z/[xxxxyyyy]/[xxxxyyyy]/[xxxxyyyy]/[xxxxyyyy]/[xxxxyyyy].meta | |
286 | */ | |
287 | gboolean vik_map_source_is_osm_meta_tiles (VikMapSource * self) | |
288 | { | |
289 | VikMapSourceClass *klass; | |
290 | g_return_val_if_fail (self != NULL, 0); | |
291 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
292 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
293 | ||
294 | g_return_val_if_fail (klass->is_osm_meta_tiles != NULL, 0); | |
295 | ||
296 | return (*klass->is_osm_meta_tiles)(self); | |
297 | } | |
298 | ||
0f08bd0d | 299 | gboolean |
c81ded98 | 300 | vik_map_source_supports_download_only_new (VikMapSource * self) |
0f08bd0d GB |
301 | { |
302 | VikMapSourceClass *klass; | |
303 | g_return_val_if_fail (self != NULL, 0); | |
304 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
305 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
306 | ||
c81ded98 | 307 | g_return_val_if_fail (klass->supports_download_only_new != NULL, 0); |
0f08bd0d | 308 | |
c81ded98 | 309 | return (*klass->supports_download_only_new)(self); |
0f08bd0d GB |
310 | } |
311 | ||
e633ddef RN |
312 | /** |
313 | * | |
314 | */ | |
315 | guint8 | |
316 | vik_map_source_get_zoom_min (VikMapSource * self) | |
317 | { | |
318 | VikMapSourceClass *klass; | |
319 | g_return_val_if_fail (self != NULL, 0); | |
320 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
321 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
322 | g_return_val_if_fail (klass->get_zoom_min != NULL, 0); | |
323 | return (*klass->get_zoom_min)(self); | |
324 | } | |
325 | ||
326 | /** | |
327 | * | |
328 | */ | |
329 | guint8 | |
330 | vik_map_source_get_zoom_max (VikMapSource * self) | |
331 | { | |
332 | VikMapSourceClass *klass; | |
333 | g_return_val_if_fail (self != NULL, 18); | |
334 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 18); | |
335 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
336 | g_return_val_if_fail (klass->get_zoom_max != NULL, 18); | |
337 | return (*klass->get_zoom_max)(self); | |
338 | } | |
339 | ||
2113a507 RN |
340 | /** |
341 | * | |
342 | */ | |
343 | gdouble | |
344 | vik_map_source_get_lat_max (VikMapSource * self) | |
345 | { | |
346 | VikMapSourceClass *klass; | |
347 | g_return_val_if_fail (self != NULL, 90.0); | |
348 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 90.0); | |
349 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
350 | g_return_val_if_fail (klass->get_lat_max != NULL, 90.0); | |
351 | return (*klass->get_lat_max)(self); | |
352 | } | |
353 | ||
354 | /** | |
355 | * | |
356 | */ | |
357 | gdouble | |
358 | vik_map_source_get_lat_min (VikMapSource * self) | |
359 | { | |
360 | VikMapSourceClass *klass; | |
361 | g_return_val_if_fail (self != NULL, -90.0); | |
362 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), -90.0); | |
363 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
364 | g_return_val_if_fail (klass->get_lat_min != NULL, -90.0); | |
365 | return (*klass->get_lat_min)(self); | |
366 | } | |
367 | ||
368 | /** | |
369 | * | |
370 | */ | |
371 | gdouble | |
372 | vik_map_source_get_lon_max (VikMapSource * self) | |
373 | { | |
374 | VikMapSourceClass *klass; | |
375 | g_return_val_if_fail (self != NULL, 180.0); | |
376 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 180.0); | |
377 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
378 | g_return_val_if_fail (klass->get_lon_max != NULL, 180.0); | |
379 | return (*klass->get_lon_max)(self); | |
380 | } | |
381 | ||
382 | /** | |
383 | * | |
384 | */ | |
385 | gdouble | |
386 | vik_map_source_get_lon_min (VikMapSource * self) | |
387 | { | |
388 | VikMapSourceClass *klass; | |
389 | g_return_val_if_fail (self != NULL, -180.0); | |
390 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), -180.0); | |
391 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
392 | g_return_val_if_fail (klass->get_lon_min != NULL, -180.0); | |
393 | return (*klass->get_lon_min)(self); | |
394 | } | |
14b57d17 RN |
395 | |
396 | /** | |
397 | * vik_map_source_get_file_extension: | |
398 | * @self: the VikMapSource of interest. | |
399 | * | |
400 | * Returns the file extension of files held on disk. | |
401 | * Typically .png but may be .jpg or whatever the user defines | |
402 | * | |
403 | */ | |
404 | const gchar * | |
405 | vik_map_source_get_file_extension (VikMapSource * self) | |
406 | { | |
407 | VikMapSourceClass *klass; | |
408 | g_return_val_if_fail (self != NULL, NULL); | |
409 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); | |
410 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
411 | ||
412 | g_return_val_if_fail (klass->get_file_extension != NULL, NULL); | |
413 | ||
414 | return (*klass->get_file_extension)(self); | |
415 | } | |
416 | ||
820c59f4 GB |
417 | gboolean |
418 | vik_map_source_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest ) | |
419 | { | |
420 | VikMapSourceClass *klass; | |
421 | g_return_val_if_fail (self != NULL, FALSE); | |
422 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), FALSE); | |
423 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
424 | ||
425 | g_return_val_if_fail (klass->coord_to_mapcoord != NULL, FALSE); | |
426 | ||
427 | return (*klass->coord_to_mapcoord)(self, src, xzoom, yzoom, dest); | |
428 | } | |
429 | ||
430 | void | |
431 | vik_map_source_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest) | |
432 | { | |
433 | VikMapSourceClass *klass; | |
434 | g_return_if_fail (self != NULL); | |
435 | g_return_if_fail (VIK_IS_MAP_SOURCE (self)); | |
436 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
437 | ||
438 | g_return_if_fail (klass->mapcoord_to_center_coord != NULL); | |
439 | ||
41810542 | 440 | (*klass->mapcoord_to_center_coord)(self, src, dest); |
820c59f4 GB |
441 | } |
442 | ||
4e815e90 RN |
443 | /** |
444 | * vik_map_source_download: | |
445 | * @self: The VikMapSource of interest. | |
446 | * @src: The map location to download | |
447 | * @dest_fn: The filename to save the result in | |
448 | * @handle: Potential reusable Curl Handle (may be NULL) | |
449 | * | |
450 | * Returns: How successful the download was as per the type #DownloadResult_t | |
451 | */ | |
452 | DownloadResult_t | |
825413ba | 453 | vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void *handle) |
820c59f4 GB |
454 | { |
455 | VikMapSourceClass *klass; | |
456 | g_return_val_if_fail (self != NULL, 0); | |
457 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
458 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
459 | ||
460 | g_return_val_if_fail (klass->download != NULL, 0); | |
461 | ||
825413ba SW |
462 | return (*klass->download)(self, src, dest_fn, handle); |
463 | } | |
464 | ||
465 | void * | |
466 | vik_map_source_download_handle_init (VikMapSource *self) | |
467 | { | |
468 | VikMapSourceClass *klass; | |
469 | g_return_val_if_fail (self != NULL, 0); | |
470 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
471 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
472 | ||
473 | g_return_val_if_fail (klass->download_handle_init != NULL, 0); | |
474 | ||
475 | return (*klass->download_handle_init)(self); | |
476 | } | |
477 | ||
478 | void | |
479 | vik_map_source_download_handle_cleanup (VikMapSource * self, void * handle) | |
480 | { | |
481 | VikMapSourceClass *klass; | |
2949dd77 GB |
482 | g_return_if_fail (self != NULL); |
483 | g_return_if_fail (VIK_IS_MAP_SOURCE (self)); | |
825413ba SW |
484 | klass = VIK_MAP_SOURCE_GET_CLASS(self); |
485 | ||
2949dd77 | 486 | g_return_if_fail (klass->download_handle_cleanup != NULL); |
825413ba | 487 | |
2949dd77 | 488 | (*klass->download_handle_cleanup)(self, handle); |
820c59f4 | 489 | } |