]> git.street.me.uk Git - andy/viking.git/blame - src/vikmapsource.c
Enable Cache conversion in the Python tool viking-cache.py
[andy/viking.git] / src / vikmapsource.c
CommitLineData
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
37static void vik_map_source_init (VikMapSource *object);
38static void vik_map_source_finalize (GObject *object);
39static void vik_map_source_class_init (VikMapSourceClass *klass);
40
c81ded98 41static gboolean _supports_download_only_new (VikMapSource *object);
0f08bd0d 42
d840e6de 43G_DEFINE_ABSTRACT_TYPE (VikMapSource, vik_map_source, G_TYPE_OBJECT);
820c59f4 44
820c59f4
GB
45static void
46vik_map_source_init (VikMapSource *object)
47{
48 /* TODO: Add initialization code here */
49}
50
51static void
52vik_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
59static void
60vik_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;
820c59f4
GB
77 klass->coord_to_mapcoord = NULL;
78 klass->mapcoord_to_center_coord = NULL;
79 klass->download = NULL;
825413ba
SW
80 klass->download_handle_init = NULL;
81 klass->download_handle_cleanup = NULL;
820c59f4
GB
82
83 object_class->finalize = vik_map_source_finalize;
84}
85
e8cf3d97 86gboolean
c81ded98 87_supports_download_only_new (VikMapSource *self)
0f08bd0d
GB
88{
89 // Default feature: does not support
90 return FALSE;
91}
820c59f4 92
68b1d6c0
GB
93/**
94 * vik_map_source_get_copyright:
95 * @self: the VikMapSource of interest.
96 * @bbox: bounding box of interest.
97 * @zoom: the zoom level of interest.
98 * @fct: the callback function to use to return matching copyrights.
99 * @data: the user data to use to call the callbaack function.
100 *
17281ebd 101 * Retrieve copyright(s) for the corresponding bounding box and zoom level.
68b1d6c0
GB
102 */
103void
551ee033 104vik_map_source_get_copyright (VikMapSource *self, LatLonBBox bbox, gdouble zoom, void (*fct)(VikViewport*,const gchar*), void *data)
82aa018d
GB
105{
106 VikMapSourceClass *klass;
68b1d6c0
GB
107 g_return_if_fail (self != NULL);
108 g_return_if_fail (VIK_IS_MAP_SOURCE (self));
82aa018d
GB
109 klass = VIK_MAP_SOURCE_GET_CLASS(self);
110
68b1d6c0 111 g_return_if_fail (klass->get_copyright != NULL);
82aa018d 112
68b1d6c0 113 (*klass->get_copyright)(self, bbox, zoom, fct, data);
82aa018d
GB
114}
115
53ac8302
GB
116const gchar *
117vik_map_source_get_license (VikMapSource *self)
118{
119 VikMapSourceClass *klass;
120 g_return_val_if_fail (self != NULL, NULL);
121 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
122 klass = VIK_MAP_SOURCE_GET_CLASS(self);
123
124 g_return_val_if_fail (klass->get_license != NULL, NULL);
125
126 return (*klass->get_license)(self);
127}
128
129const gchar *
130vik_map_source_get_license_url (VikMapSource *self)
131{
132 VikMapSourceClass *klass;
133 g_return_val_if_fail (self != NULL, NULL);
134 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
135 klass = VIK_MAP_SOURCE_GET_CLASS(self);
136
137 g_return_val_if_fail (klass->get_license_url != NULL, NULL);
138
139 return (*klass->get_license_url)(self);
140}
141
26336cf0
GB
142const GdkPixbuf *
143vik_map_source_get_logo (VikMapSource *self)
144{
145 VikMapSourceClass *klass;
146 g_return_val_if_fail (self != NULL, NULL);
147 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
148 klass = VIK_MAP_SOURCE_GET_CLASS(self);
149
150 g_return_val_if_fail (klass->get_logo != NULL, NULL);
151
152 return (*klass->get_logo)(self);
153}
154
2eb18edc
RN
155const gchar *
156vik_map_source_get_name (VikMapSource *self)
157{
158 VikMapSourceClass *klass;
159 g_return_val_if_fail (self != NULL, NULL);
160 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
161 klass = VIK_MAP_SOURCE_GET_CLASS(self);
162
163 g_return_val_if_fail (klass->get_name != NULL, NULL);
164
165 return (*klass->get_name)(self);
166}
167
d7e495b2 168guint16
820c59f4
GB
169vik_map_source_get_uniq_id (VikMapSource *self)
170{
171 VikMapSourceClass *klass;
d7e495b2
RN
172 g_return_val_if_fail (self != NULL, (guint16 )0);
173 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
820c59f4
GB
174 klass = VIK_MAP_SOURCE_GET_CLASS(self);
175
d7e495b2 176 g_return_val_if_fail (klass->get_uniq_id != NULL, (guint16 )0);
820c59f4
GB
177
178 return (*klass->get_uniq_id)(self);
179}
180
db03733a
GB
181const gchar *
182vik_map_source_get_label (VikMapSource *self)
183{
184 VikMapSourceClass *klass;
185 g_return_val_if_fail (self != NULL, NULL);
186 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
187 klass = VIK_MAP_SOURCE_GET_CLASS(self);
188
189 g_return_val_if_fail (klass->get_label != NULL, NULL);
190
191 return (*klass->get_label)(self);
192}
193
820c59f4
GB
194guint16
195vik_map_source_get_tilesize_x (VikMapSource *self)
196{
197 VikMapSourceClass *klass;
198 g_return_val_if_fail (self != NULL, (guint16 )0);
199 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
200 klass = VIK_MAP_SOURCE_GET_CLASS(self);
201
202 g_return_val_if_fail (klass->get_tilesize_x != NULL, (guint16 )0);
203
204 return (*klass->get_tilesize_x)(self);
205}
206
207guint16
208vik_map_source_get_tilesize_y (VikMapSource *self)
209{
210 VikMapSourceClass *klass;
211 g_return_val_if_fail (self != NULL, (guint16 )0);
212 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
213 klass = VIK_MAP_SOURCE_GET_CLASS(self);
214
215 g_return_val_if_fail (klass->get_tilesize_y != NULL, (guint16 )0);
216
217 return (*klass->get_tilesize_y)(self);
218}
219
220VikViewportDrawMode
221vik_map_source_get_drawmode (VikMapSource *self)
222{
223 VikMapSourceClass *klass;
224 g_return_val_if_fail (self != NULL, (VikViewportDrawMode )0);
225 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (VikViewportDrawMode )0);
226 klass = VIK_MAP_SOURCE_GET_CLASS(self);
227
228 g_return_val_if_fail (klass->get_drawmode != NULL, (VikViewportDrawMode )0);
229
230 return (*klass->get_drawmode)(self);
231}
232
2673b29d
RN
233/**
234 * vik_map_source_is_direct_file_access:
235 * @self: the VikMapSource of interest.
236 *
237 * Return true when we can bypass all this download malarky
0314a439 238 * Treat the files as a pre generated data set in OSM tile server layout: tiledir/%d/%d/%d.png
2673b29d
RN
239 */
240gboolean
241vik_map_source_is_direct_file_access (VikMapSource * self)
242{
243 VikMapSourceClass *klass;
244 g_return_val_if_fail (self != NULL, 0);
245 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
246 klass = VIK_MAP_SOURCE_GET_CLASS(self);
247
248 g_return_val_if_fail (klass->is_direct_file_access != NULL, 0);
249
250 return (*klass->is_direct_file_access)(self);
251}
252
0fb11294
RN
253/**
254 * vik_map_source_is_mbtiles:
255 * @self: the VikMapSource of interest.
256 *
257 * Return true when the map is in an MB Tiles format.
258 * See http://github.com/mapbox/mbtiles-spec
259 * (Read Only ATM)
260 */
261gboolean
262vik_map_source_is_mbtiles (VikMapSource * self)
263{
264 VikMapSourceClass *klass;
265 g_return_val_if_fail (self != NULL, 0);
266 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
267 klass = VIK_MAP_SOURCE_GET_CLASS(self);
268
269 g_return_val_if_fail (klass->is_mbtiles != NULL, 0);
270
271 return (*klass->is_mbtiles)(self);
272}
273
0f08bd0d 274gboolean
c81ded98 275vik_map_source_supports_download_only_new (VikMapSource * self)
0f08bd0d
GB
276{
277 VikMapSourceClass *klass;
278 g_return_val_if_fail (self != NULL, 0);
279 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
280 klass = VIK_MAP_SOURCE_GET_CLASS(self);
281
c81ded98 282 g_return_val_if_fail (klass->supports_download_only_new != NULL, 0);
0f08bd0d 283
c81ded98 284 return (*klass->supports_download_only_new)(self);
0f08bd0d
GB
285}
286
820c59f4
GB
287gboolean
288vik_map_source_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
289{
290 VikMapSourceClass *klass;
291 g_return_val_if_fail (self != NULL, FALSE);
292 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), FALSE);
293 klass = VIK_MAP_SOURCE_GET_CLASS(self);
294
295 g_return_val_if_fail (klass->coord_to_mapcoord != NULL, FALSE);
296
297 return (*klass->coord_to_mapcoord)(self, src, xzoom, yzoom, dest);
298}
299
300void
301vik_map_source_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest)
302{
303 VikMapSourceClass *klass;
304 g_return_if_fail (self != NULL);
305 g_return_if_fail (VIK_IS_MAP_SOURCE (self));
306 klass = VIK_MAP_SOURCE_GET_CLASS(self);
307
308 g_return_if_fail (klass->mapcoord_to_center_coord != NULL);
309
41810542 310 (*klass->mapcoord_to_center_coord)(self, src, dest);
820c59f4
GB
311}
312
4e815e90
RN
313/**
314 * vik_map_source_download:
315 * @self: The VikMapSource of interest.
316 * @src: The map location to download
317 * @dest_fn: The filename to save the result in
318 * @handle: Potential reusable Curl Handle (may be NULL)
319 *
320 * Returns: How successful the download was as per the type #DownloadResult_t
321 */
322DownloadResult_t
825413ba 323vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void *handle)
820c59f4
GB
324{
325 VikMapSourceClass *klass;
326 g_return_val_if_fail (self != NULL, 0);
327 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
328 klass = VIK_MAP_SOURCE_GET_CLASS(self);
329
330 g_return_val_if_fail (klass->download != NULL, 0);
331
825413ba
SW
332 return (*klass->download)(self, src, dest_fn, handle);
333}
334
335void *
336vik_map_source_download_handle_init (VikMapSource *self)
337{
338 VikMapSourceClass *klass;
339 g_return_val_if_fail (self != NULL, 0);
340 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
341 klass = VIK_MAP_SOURCE_GET_CLASS(self);
342
343 g_return_val_if_fail (klass->download_handle_init != NULL, 0);
344
345 return (*klass->download_handle_init)(self);
346}
347
348void
349vik_map_source_download_handle_cleanup (VikMapSource * self, void * handle)
350{
351 VikMapSourceClass *klass;
2949dd77
GB
352 g_return_if_fail (self != NULL);
353 g_return_if_fail (VIK_IS_MAP_SOURCE (self));
825413ba
SW
354 klass = VIK_MAP_SOURCE_GET_CLASS(self);
355
2949dd77 356 g_return_if_fail (klass->download_handle_cleanup != NULL);
825413ba 357
2949dd77 358 (*klass->download_handle_cleanup)(self, handle);
820c59f4 359}