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->supports_download_only_new = _supports_download_only_new;
75 klass->coord_to_mapcoord = NULL;
76 klass->mapcoord_to_center_coord = NULL;
77 klass->download = NULL;
78 klass->download_handle_init = NULL;
79 klass->download_handle_cleanup = NULL;
81 object_class->finalize = vik_map_source_finalize;
85 _supports_download_only_new (VikMapSource *self)
87 // Default feature: does not support
92 * vik_map_source_get_copyright:
93 * @self: the VikMapSource of interest.
94 * @bbox: bounding box of interest.
95 * @zoom: the zoom level of interest.
96 * @fct: the callback function to use to return matching copyrights.
97 * @data: the user data to use to call the callbaack function.
99 * Retrieve copyright(s) for the corresponding bounding box and zoom level.
102 vik_map_source_get_copyright (VikMapSource *self, LatLonBBox bbox, gdouble zoom, void (*fct)(VikViewport*,const gchar*), void *data)
104 VikMapSourceClass *klass;
105 g_return_if_fail (self != NULL);
106 g_return_if_fail (VIK_IS_MAP_SOURCE (self));
107 klass = VIK_MAP_SOURCE_GET_CLASS(self);
109 g_return_if_fail (klass->get_copyright != NULL);
111 (*klass->get_copyright)(self, bbox, zoom, fct, data);
115 vik_map_source_get_license (VikMapSource *self)
117 VikMapSourceClass *klass;
118 g_return_val_if_fail (self != NULL, NULL);
119 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
120 klass = VIK_MAP_SOURCE_GET_CLASS(self);
122 g_return_val_if_fail (klass->get_license != NULL, NULL);
124 return (*klass->get_license)(self);
128 vik_map_source_get_license_url (VikMapSource *self)
130 VikMapSourceClass *klass;
131 g_return_val_if_fail (self != NULL, NULL);
132 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
133 klass = VIK_MAP_SOURCE_GET_CLASS(self);
135 g_return_val_if_fail (klass->get_license_url != NULL, NULL);
137 return (*klass->get_license_url)(self);
141 vik_map_source_get_logo (VikMapSource *self)
143 VikMapSourceClass *klass;
144 g_return_val_if_fail (self != NULL, NULL);
145 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
146 klass = VIK_MAP_SOURCE_GET_CLASS(self);
148 g_return_val_if_fail (klass->get_logo != NULL, NULL);
150 return (*klass->get_logo)(self);
154 vik_map_source_get_uniq_id (VikMapSource *self)
156 VikMapSourceClass *klass;
157 g_return_val_if_fail (self != NULL, (guint16 )0);
158 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
159 klass = VIK_MAP_SOURCE_GET_CLASS(self);
161 g_return_val_if_fail (klass->get_uniq_id != NULL, (guint16 )0);
163 return (*klass->get_uniq_id)(self);
167 vik_map_source_get_label (VikMapSource *self)
169 VikMapSourceClass *klass;
170 g_return_val_if_fail (self != NULL, NULL);
171 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
172 klass = VIK_MAP_SOURCE_GET_CLASS(self);
174 g_return_val_if_fail (klass->get_label != NULL, NULL);
176 return (*klass->get_label)(self);
180 vik_map_source_get_tilesize_x (VikMapSource *self)
182 VikMapSourceClass *klass;
183 g_return_val_if_fail (self != NULL, (guint16 )0);
184 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
185 klass = VIK_MAP_SOURCE_GET_CLASS(self);
187 g_return_val_if_fail (klass->get_tilesize_x != NULL, (guint16 )0);
189 return (*klass->get_tilesize_x)(self);
193 vik_map_source_get_tilesize_y (VikMapSource *self)
195 VikMapSourceClass *klass;
196 g_return_val_if_fail (self != NULL, (guint16 )0);
197 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
198 klass = VIK_MAP_SOURCE_GET_CLASS(self);
200 g_return_val_if_fail (klass->get_tilesize_y != NULL, (guint16 )0);
202 return (*klass->get_tilesize_y)(self);
206 vik_map_source_get_drawmode (VikMapSource *self)
208 VikMapSourceClass *klass;
209 g_return_val_if_fail (self != NULL, (VikViewportDrawMode )0);
210 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (VikViewportDrawMode )0);
211 klass = VIK_MAP_SOURCE_GET_CLASS(self);
213 g_return_val_if_fail (klass->get_drawmode != NULL, (VikViewportDrawMode )0);
215 return (*klass->get_drawmode)(self);
219 * vik_map_source_is_direct_file_access:
220 * @self: the VikMapSource of interest.
222 * Return true when we can bypass all this download malarky
223 * Treat the files as a pre generated data set in OSM tile server layout: tiledir/%d/%d/%d.png
226 vik_map_source_is_direct_file_access (VikMapSource * self)
228 VikMapSourceClass *klass;
229 g_return_val_if_fail (self != NULL, 0);
230 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
231 klass = VIK_MAP_SOURCE_GET_CLASS(self);
233 g_return_val_if_fail (klass->is_direct_file_access != NULL, 0);
235 return (*klass->is_direct_file_access)(self);
239 vik_map_source_supports_download_only_new (VikMapSource * self)
241 VikMapSourceClass *klass;
242 g_return_val_if_fail (self != NULL, 0);
243 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
244 klass = VIK_MAP_SOURCE_GET_CLASS(self);
246 g_return_val_if_fail (klass->supports_download_only_new != NULL, 0);
248 return (*klass->supports_download_only_new)(self);
252 vik_map_source_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
254 VikMapSourceClass *klass;
255 g_return_val_if_fail (self != NULL, FALSE);
256 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), FALSE);
257 klass = VIK_MAP_SOURCE_GET_CLASS(self);
259 g_return_val_if_fail (klass->coord_to_mapcoord != NULL, FALSE);
261 return (*klass->coord_to_mapcoord)(self, src, xzoom, yzoom, dest);
265 vik_map_source_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest)
267 VikMapSourceClass *klass;
268 g_return_if_fail (self != NULL);
269 g_return_if_fail (VIK_IS_MAP_SOURCE (self));
270 klass = VIK_MAP_SOURCE_GET_CLASS(self);
272 g_return_if_fail (klass->mapcoord_to_center_coord != NULL);
274 (*klass->mapcoord_to_center_coord)(self, src, dest);
278 vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void *handle)
280 VikMapSourceClass *klass;
281 g_return_val_if_fail (self != NULL, 0);
282 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
283 klass = VIK_MAP_SOURCE_GET_CLASS(self);
285 g_return_val_if_fail (klass->download != NULL, 0);
287 return (*klass->download)(self, src, dest_fn, handle);
291 vik_map_source_download_handle_init (VikMapSource *self)
293 VikMapSourceClass *klass;
294 g_return_val_if_fail (self != NULL, 0);
295 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
296 klass = VIK_MAP_SOURCE_GET_CLASS(self);
298 g_return_val_if_fail (klass->download_handle_init != NULL, 0);
300 return (*klass->download_handle_init)(self);
304 vik_map_source_download_handle_cleanup (VikMapSource * self, void * handle)
306 VikMapSourceClass *klass;
307 g_return_if_fail (self != NULL);
308 g_return_if_fail (VIK_IS_MAP_SOURCE (self));
309 klass = VIK_MAP_SOURCE_GET_CLASS(self);
311 g_return_if_fail (klass->download_handle_cleanup != NULL);
313 (*klass->download_handle_cleanup)(self, handle);