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_uniq_id = NULL;
69 klass->get_label = NULL;
70 klass->get_tilesize_x = NULL;
71 klass->get_tilesize_y = NULL;
72 klass->get_drawmode = NULL;
73 klass->is_direct_file_access = NULL;
74 klass->is_mbtiles = NULL;
75 klass->supports_download_only_new = _supports_download_only_new;
76 klass->coord_to_mapcoord = NULL;
77 klass->mapcoord_to_center_coord = NULL;
78 klass->download = NULL;
79 klass->download_handle_init = NULL;
80 klass->download_handle_cleanup = NULL;
82 object_class->finalize = vik_map_source_finalize;
86 _supports_download_only_new (VikMapSource *self)
88 // Default feature: does not support
93 * vik_map_source_get_copyright:
94 * @self: the VikMapSource of interest.
95 * @bbox: bounding box of interest.
96 * @zoom: the zoom level of interest.
97 * @fct: the callback function to use to return matching copyrights.
98 * @data: the user data to use to call the callbaack function.
100 * Retrieve copyright(s) for the corresponding bounding box and zoom level.
103 vik_map_source_get_copyright (VikMapSource *self, LatLonBBox bbox, gdouble zoom, void (*fct)(VikViewport*,const gchar*), void *data)
105 VikMapSourceClass *klass;
106 g_return_if_fail (self != NULL);
107 g_return_if_fail (VIK_IS_MAP_SOURCE (self));
108 klass = VIK_MAP_SOURCE_GET_CLASS(self);
110 g_return_if_fail (klass->get_copyright != NULL);
112 (*klass->get_copyright)(self, bbox, zoom, fct, data);
116 vik_map_source_get_license (VikMapSource *self)
118 VikMapSourceClass *klass;
119 g_return_val_if_fail (self != NULL, NULL);
120 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
121 klass = VIK_MAP_SOURCE_GET_CLASS(self);
123 g_return_val_if_fail (klass->get_license != NULL, NULL);
125 return (*klass->get_license)(self);
129 vik_map_source_get_license_url (VikMapSource *self)
131 VikMapSourceClass *klass;
132 g_return_val_if_fail (self != NULL, NULL);
133 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
134 klass = VIK_MAP_SOURCE_GET_CLASS(self);
136 g_return_val_if_fail (klass->get_license_url != NULL, NULL);
138 return (*klass->get_license_url)(self);
142 vik_map_source_get_logo (VikMapSource *self)
144 VikMapSourceClass *klass;
145 g_return_val_if_fail (self != NULL, NULL);
146 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
147 klass = VIK_MAP_SOURCE_GET_CLASS(self);
149 g_return_val_if_fail (klass->get_logo != NULL, NULL);
151 return (*klass->get_logo)(self);
155 vik_map_source_get_uniq_id (VikMapSource *self)
157 VikMapSourceClass *klass;
158 g_return_val_if_fail (self != NULL, (guint16 )0);
159 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
160 klass = VIK_MAP_SOURCE_GET_CLASS(self);
162 g_return_val_if_fail (klass->get_uniq_id != NULL, (guint16 )0);
164 return (*klass->get_uniq_id)(self);
168 vik_map_source_get_label (VikMapSource *self)
170 VikMapSourceClass *klass;
171 g_return_val_if_fail (self != NULL, NULL);
172 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
173 klass = VIK_MAP_SOURCE_GET_CLASS(self);
175 g_return_val_if_fail (klass->get_label != NULL, NULL);
177 return (*klass->get_label)(self);
181 vik_map_source_get_tilesize_x (VikMapSource *self)
183 VikMapSourceClass *klass;
184 g_return_val_if_fail (self != NULL, (guint16 )0);
185 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
186 klass = VIK_MAP_SOURCE_GET_CLASS(self);
188 g_return_val_if_fail (klass->get_tilesize_x != NULL, (guint16 )0);
190 return (*klass->get_tilesize_x)(self);
194 vik_map_source_get_tilesize_y (VikMapSource *self)
196 VikMapSourceClass *klass;
197 g_return_val_if_fail (self != NULL, (guint16 )0);
198 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
199 klass = VIK_MAP_SOURCE_GET_CLASS(self);
201 g_return_val_if_fail (klass->get_tilesize_y != NULL, (guint16 )0);
203 return (*klass->get_tilesize_y)(self);
207 vik_map_source_get_drawmode (VikMapSource *self)
209 VikMapSourceClass *klass;
210 g_return_val_if_fail (self != NULL, (VikViewportDrawMode )0);
211 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (VikViewportDrawMode )0);
212 klass = VIK_MAP_SOURCE_GET_CLASS(self);
214 g_return_val_if_fail (klass->get_drawmode != NULL, (VikViewportDrawMode )0);
216 return (*klass->get_drawmode)(self);
220 * vik_map_source_is_direct_file_access:
221 * @self: the VikMapSource of interest.
223 * Return true when we can bypass all this download malarky
224 * Treat the files as a pre generated data set in OSM tile server layout: tiledir/%d/%d/%d.png
227 vik_map_source_is_direct_file_access (VikMapSource * self)
229 VikMapSourceClass *klass;
230 g_return_val_if_fail (self != NULL, 0);
231 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
232 klass = VIK_MAP_SOURCE_GET_CLASS(self);
234 g_return_val_if_fail (klass->is_direct_file_access != NULL, 0);
236 return (*klass->is_direct_file_access)(self);
240 * vik_map_source_is_mbtiles:
241 * @self: the VikMapSource of interest.
243 * Return true when the map is in an MB Tiles format.
244 * See http://github.com/mapbox/mbtiles-spec
248 vik_map_source_is_mbtiles (VikMapSource * self)
250 VikMapSourceClass *klass;
251 g_return_val_if_fail (self != NULL, 0);
252 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
253 klass = VIK_MAP_SOURCE_GET_CLASS(self);
255 g_return_val_if_fail (klass->is_mbtiles != NULL, 0);
257 return (*klass->is_mbtiles)(self);
261 vik_map_source_supports_download_only_new (VikMapSource * self)
263 VikMapSourceClass *klass;
264 g_return_val_if_fail (self != NULL, 0);
265 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
266 klass = VIK_MAP_SOURCE_GET_CLASS(self);
268 g_return_val_if_fail (klass->supports_download_only_new != NULL, 0);
270 return (*klass->supports_download_only_new)(self);
274 vik_map_source_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
276 VikMapSourceClass *klass;
277 g_return_val_if_fail (self != NULL, FALSE);
278 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), FALSE);
279 klass = VIK_MAP_SOURCE_GET_CLASS(self);
281 g_return_val_if_fail (klass->coord_to_mapcoord != NULL, FALSE);
283 return (*klass->coord_to_mapcoord)(self, src, xzoom, yzoom, dest);
287 vik_map_source_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest)
289 VikMapSourceClass *klass;
290 g_return_if_fail (self != NULL);
291 g_return_if_fail (VIK_IS_MAP_SOURCE (self));
292 klass = VIK_MAP_SOURCE_GET_CLASS(self);
294 g_return_if_fail (klass->mapcoord_to_center_coord != NULL);
296 (*klass->mapcoord_to_center_coord)(self, src, dest);
300 * vik_map_source_download:
301 * @self: The VikMapSource of interest.
302 * @src: The map location to download
303 * @dest_fn: The filename to save the result in
304 * @handle: Potential reusable Curl Handle (may be NULL)
306 * Returns: How successful the download was as per the type #DownloadResult_t
309 vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void *handle)
311 VikMapSourceClass *klass;
312 g_return_val_if_fail (self != NULL, 0);
313 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
314 klass = VIK_MAP_SOURCE_GET_CLASS(self);
316 g_return_val_if_fail (klass->download != NULL, 0);
318 return (*klass->download)(self, src, dest_fn, handle);
322 vik_map_source_download_handle_init (VikMapSource *self)
324 VikMapSourceClass *klass;
325 g_return_val_if_fail (self != NULL, 0);
326 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
327 klass = VIK_MAP_SOURCE_GET_CLASS(self);
329 g_return_val_if_fail (klass->download_handle_init != NULL, 0);
331 return (*klass->download_handle_init)(self);
335 vik_map_source_download_handle_cleanup (VikMapSource * self, void * handle)
337 VikMapSourceClass *klass;
338 g_return_if_fail (self != NULL);
339 g_return_if_fail (VIK_IS_MAP_SOURCE (self));
340 klass = VIK_MAP_SOURCE_GET_CLASS(self);
342 g_return_if_fail (klass->download_handle_cleanup != NULL);
344 (*klass->download_handle_cleanup)(self, handle);