1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) 2009-2010, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
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.
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.
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/>.
21 * SECTION:vikmapsource
22 * @short_description: the base class to describe map source
24 * The #VikMapSource class is both the interface and the base class
25 * for the hierarchie of map source.
31 #include "vikviewport.h"
35 #include "vikmapsource.h"
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);
41 static gboolean _supports_download_only_new (VikMapSource *object);
43 G_DEFINE_ABSTRACT_TYPE (VikMapSource, vik_map_source, G_TYPE_OBJECT);
46 vik_map_source_init (VikMapSource *object)
48 /* TODO: Add initialization code here */
52 vik_map_source_finalize (GObject *object)
54 /* TODO: Add deinitalization code here */
56 G_OBJECT_CLASS (vik_map_source_parent_class)->finalize (object);
60 vik_map_source_class_init (VikMapSourceClass *klass)
62 GObjectClass* object_class = G_OBJECT_CLASS (klass);
64 klass->get_copyright = NULL;
65 klass->get_license = NULL;
66 klass->get_license_url = NULL;
67 klass->get_logo = NULL;
68 klass->get_name = NULL;
69 klass->get_uniq_id = NULL;
70 klass->get_label = NULL;
71 klass->get_tilesize_x = NULL;
72 klass->get_tilesize_y = NULL;
73 klass->get_drawmode = NULL;
74 klass->is_direct_file_access = NULL;
75 klass->is_mbtiles = NULL;
76 klass->supports_download_only_new = _supports_download_only_new;
77 klass->get_zoom_min = NULL;
78 klass->get_zoom_max = NULL;
79 klass->coord_to_mapcoord = NULL;
80 klass->mapcoord_to_center_coord = NULL;
81 klass->download = NULL;
82 klass->download_handle_init = NULL;
83 klass->download_handle_cleanup = NULL;
85 object_class->finalize = vik_map_source_finalize;
89 _supports_download_only_new (VikMapSource *self)
91 // Default feature: does not support
96 * vik_map_source_get_copyright:
97 * @self: the VikMapSource of interest.
98 * @bbox: bounding box of interest.
99 * @zoom: the zoom level of interest.
100 * @fct: the callback function to use to return matching copyrights.
101 * @data: the user data to use to call the callbaack function.
103 * Retrieve copyright(s) for the corresponding bounding box and zoom level.
106 vik_map_source_get_copyright (VikMapSource *self, LatLonBBox bbox, gdouble zoom, void (*fct)(VikViewport*,const gchar*), void *data)
108 VikMapSourceClass *klass;
109 g_return_if_fail (self != NULL);
110 g_return_if_fail (VIK_IS_MAP_SOURCE (self));
111 klass = VIK_MAP_SOURCE_GET_CLASS(self);
113 g_return_if_fail (klass->get_copyright != NULL);
115 (*klass->get_copyright)(self, bbox, zoom, fct, data);
119 vik_map_source_get_license (VikMapSource *self)
121 VikMapSourceClass *klass;
122 g_return_val_if_fail (self != NULL, NULL);
123 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
124 klass = VIK_MAP_SOURCE_GET_CLASS(self);
126 g_return_val_if_fail (klass->get_license != NULL, NULL);
128 return (*klass->get_license)(self);
132 vik_map_source_get_license_url (VikMapSource *self)
134 VikMapSourceClass *klass;
135 g_return_val_if_fail (self != NULL, NULL);
136 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
137 klass = VIK_MAP_SOURCE_GET_CLASS(self);
139 g_return_val_if_fail (klass->get_license_url != NULL, NULL);
141 return (*klass->get_license_url)(self);
145 vik_map_source_get_logo (VikMapSource *self)
147 VikMapSourceClass *klass;
148 g_return_val_if_fail (self != NULL, NULL);
149 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
150 klass = VIK_MAP_SOURCE_GET_CLASS(self);
152 g_return_val_if_fail (klass->get_logo != NULL, NULL);
154 return (*klass->get_logo)(self);
158 vik_map_source_get_name (VikMapSource *self)
160 VikMapSourceClass *klass;
161 g_return_val_if_fail (self != NULL, NULL);
162 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
163 klass = VIK_MAP_SOURCE_GET_CLASS(self);
165 g_return_val_if_fail (klass->get_name != NULL, NULL);
167 return (*klass->get_name)(self);
171 vik_map_source_get_uniq_id (VikMapSource *self)
173 VikMapSourceClass *klass;
174 g_return_val_if_fail (self != NULL, (guint16 )0);
175 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
176 klass = VIK_MAP_SOURCE_GET_CLASS(self);
178 g_return_val_if_fail (klass->get_uniq_id != NULL, (guint16 )0);
180 return (*klass->get_uniq_id)(self);
184 vik_map_source_get_label (VikMapSource *self)
186 VikMapSourceClass *klass;
187 g_return_val_if_fail (self != NULL, NULL);
188 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
189 klass = VIK_MAP_SOURCE_GET_CLASS(self);
191 g_return_val_if_fail (klass->get_label != NULL, NULL);
193 return (*klass->get_label)(self);
197 vik_map_source_get_tilesize_x (VikMapSource *self)
199 VikMapSourceClass *klass;
200 g_return_val_if_fail (self != NULL, (guint16 )0);
201 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
202 klass = VIK_MAP_SOURCE_GET_CLASS(self);
204 g_return_val_if_fail (klass->get_tilesize_x != NULL, (guint16 )0);
206 return (*klass->get_tilesize_x)(self);
210 vik_map_source_get_tilesize_y (VikMapSource *self)
212 VikMapSourceClass *klass;
213 g_return_val_if_fail (self != NULL, (guint16 )0);
214 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
215 klass = VIK_MAP_SOURCE_GET_CLASS(self);
217 g_return_val_if_fail (klass->get_tilesize_y != NULL, (guint16 )0);
219 return (*klass->get_tilesize_y)(self);
223 vik_map_source_get_drawmode (VikMapSource *self)
225 VikMapSourceClass *klass;
226 g_return_val_if_fail (self != NULL, (VikViewportDrawMode )0);
227 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (VikViewportDrawMode )0);
228 klass = VIK_MAP_SOURCE_GET_CLASS(self);
230 g_return_val_if_fail (klass->get_drawmode != NULL, (VikViewportDrawMode )0);
232 return (*klass->get_drawmode)(self);
236 * vik_map_source_is_direct_file_access:
237 * @self: the VikMapSource of interest.
239 * Return true when we can bypass all this download malarky
240 * Treat the files as a pre generated data set in OSM tile server layout: tiledir/%d/%d/%d.png
243 vik_map_source_is_direct_file_access (VikMapSource * self)
245 VikMapSourceClass *klass;
246 g_return_val_if_fail (self != NULL, 0);
247 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
248 klass = VIK_MAP_SOURCE_GET_CLASS(self);
250 g_return_val_if_fail (klass->is_direct_file_access != NULL, 0);
252 return (*klass->is_direct_file_access)(self);
256 * vik_map_source_is_mbtiles:
257 * @self: the VikMapSource of interest.
259 * Return true when the map is in an MB Tiles format.
260 * See http://github.com/mapbox/mbtiles-spec
264 vik_map_source_is_mbtiles (VikMapSource * self)
266 VikMapSourceClass *klass;
267 g_return_val_if_fail (self != NULL, 0);
268 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
269 klass = VIK_MAP_SOURCE_GET_CLASS(self);
271 g_return_val_if_fail (klass->is_mbtiles != NULL, 0);
273 return (*klass->is_mbtiles)(self);
277 vik_map_source_supports_download_only_new (VikMapSource * self)
279 VikMapSourceClass *klass;
280 g_return_val_if_fail (self != NULL, 0);
281 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
282 klass = VIK_MAP_SOURCE_GET_CLASS(self);
284 g_return_val_if_fail (klass->supports_download_only_new != NULL, 0);
286 return (*klass->supports_download_only_new)(self);
293 vik_map_source_get_zoom_min (VikMapSource * self)
295 VikMapSourceClass *klass;
296 g_return_val_if_fail (self != NULL, 0);
297 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
298 klass = VIK_MAP_SOURCE_GET_CLASS(self);
299 g_return_val_if_fail (klass->get_zoom_min != NULL, 0);
300 return (*klass->get_zoom_min)(self);
307 vik_map_source_get_zoom_max (VikMapSource * self)
309 VikMapSourceClass *klass;
310 g_return_val_if_fail (self != NULL, 18);
311 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 18);
312 klass = VIK_MAP_SOURCE_GET_CLASS(self);
313 g_return_val_if_fail (klass->get_zoom_max != NULL, 18);
314 return (*klass->get_zoom_max)(self);
318 vik_map_source_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
320 VikMapSourceClass *klass;
321 g_return_val_if_fail (self != NULL, FALSE);
322 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), FALSE);
323 klass = VIK_MAP_SOURCE_GET_CLASS(self);
325 g_return_val_if_fail (klass->coord_to_mapcoord != NULL, FALSE);
327 return (*klass->coord_to_mapcoord)(self, src, xzoom, yzoom, dest);
331 vik_map_source_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest)
333 VikMapSourceClass *klass;
334 g_return_if_fail (self != NULL);
335 g_return_if_fail (VIK_IS_MAP_SOURCE (self));
336 klass = VIK_MAP_SOURCE_GET_CLASS(self);
338 g_return_if_fail (klass->mapcoord_to_center_coord != NULL);
340 (*klass->mapcoord_to_center_coord)(self, src, dest);
344 * vik_map_source_download:
345 * @self: The VikMapSource of interest.
346 * @src: The map location to download
347 * @dest_fn: The filename to save the result in
348 * @handle: Potential reusable Curl Handle (may be NULL)
350 * Returns: How successful the download was as per the type #DownloadResult_t
353 vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void *handle)
355 VikMapSourceClass *klass;
356 g_return_val_if_fail (self != NULL, 0);
357 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
358 klass = VIK_MAP_SOURCE_GET_CLASS(self);
360 g_return_val_if_fail (klass->download != NULL, 0);
362 return (*klass->download)(self, src, dest_fn, handle);
366 vik_map_source_download_handle_init (VikMapSource *self)
368 VikMapSourceClass *klass;
369 g_return_val_if_fail (self != NULL, 0);
370 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
371 klass = VIK_MAP_SOURCE_GET_CLASS(self);
373 g_return_val_if_fail (klass->download_handle_init != NULL, 0);
375 return (*klass->download_handle_init)(self);
379 vik_map_source_download_handle_cleanup (VikMapSource * self, void * handle)
381 VikMapSourceClass *klass;
382 g_return_if_fail (self != NULL);
383 g_return_if_fail (VIK_IS_MAP_SOURCE (self));
384 klass = VIK_MAP_SOURCE_GET_CLASS(self);
386 g_return_if_fail (klass->download_handle_cleanup != NULL);
388 (*klass->download_handle_cleanup)(self, handle);