Some providers use different copyright at different zoom levels or different world region.
This is an initial implementation. By some aspect it is a rude patch. Currently, VikViewport asks VikMapsLayer which asks VikMapSouce which calls back VikViewport via function callback. This seems the simplest solution to transmit many copyright per map provider without affecting performances and without changing too many interfaces. A better/cleaner solution could be to add a get_copyright method on VikLayer. By this way, VikViewport can pick copyright directly from owner (Vikayer) and only when needed (for example only when showing or hiding a Layer). Signed-off-by: Guilhem Bonnefille <guilhem.bonnefi...@gmail.com> --- src/Makefile.am | 1 + src/bbox.h | 42 ++++++++++++++++++++++++++++++++++++++++++ src/vikmapslayer.c | 6 ++++-- src/vikmapsource.c | 22 ++++++++++++++++------ src/vikmapsource.h | 5 +++-- src/vikmapsourcedefault.c | 13 +++++++++---- 6 files changed, 75 insertions(+), 14 deletions(-) create mode 100644 src/bbox.h diff --git a/src/Makefile.am b/src/Makefile.am index 2d1a271..d9094af 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -47,6 +47,7 @@ ENUM_H_FILES = \ vikviewport.h libviking_a_SOURCES = \ + bbox.h \ modules.h modules.c \ curl_download.c curl_download.h \ menu.xml.h \ diff --git a/src/bbox.h b/src/bbox.h new file mode 100644 index 0000000..2ccc69b --- /dev/null +++ b/src/bbox.h @@ -0,0 +1,42 @@ +/* + * viking -- GPS Data and Topo Analyzer, Explorer, and Manager + * + * Copyright (C) 2011, Guilhem Bonnefille <guilhem.bonnefi...@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef __BOUNDING_BOX_H +#define __BOUNDING_BOX_H + +typedef struct { + gdouble south, north; + gdouble east, west; +} LatLonBBox; + +/** + * +--------+ + * |a | + * | +--+----+ + * | | | | + * +-----+--+ | + * | b| + * +-------+ + */ +#define BBOX_INTERSECT(a,b) ((a).south < (b).north && (a).north > (b).south && (a).east > (b).west && (a).west < (b).east) + +#endif + diff --git a/src/vikmapslayer.c b/src/vikmapslayer.c index 2fda822..fa6b5d7 100644 --- a/src/vikmapslayer.c +++ b/src/vikmapslayer.c @@ -845,8 +845,10 @@ static void maps_layer_draw ( VikMapsLayer *vml, VikViewport *vvp ) VikCoord ul, br; /* Copyright */ - const gchar *copyright = vik_map_source_get_copyright ( MAPS_LAYER_NTH_TYPE(vml->maptype) ); - vik_viewport_add_copyright ( vvp, copyright ); + gdouble level = vik_viewport_get_zoom ( vvp ); + LatLonBBox bbox; + vik_viewport_get_min_max_lat_lon ( vvp, &bbox.south, &bbox.north, &bbox.west, &bbox.east ); + vik_map_source_get_copyright ( MAPS_LAYER_NTH_TYPE(vml->maptype), bbox, level, vik_viewport_add_copyright, vvp ); /* Logo */ GdkPixbuf *logo = vik_map_source_get_logo ( MAPS_LAYER_NTH_TYPE(vml->maptype) ); diff --git a/src/vikmapsource.c b/src/vikmapsource.c index 26e55ec..0feefd8 100644 --- a/src/vikmapsource.c +++ b/src/vikmapsource.c @@ -79,17 +79,27 @@ _supports_download_only_new (VikMapSource *self) return FALSE; } -const gchar * -vik_map_source_get_copyright (VikMapSource *self) +/** + * vik_map_source_get_copyright: + * @self: the VikMapSource of interest. + * @bbox: bounding box of interest. + * @zoom: the zoom level of interest. + * @fct: the callback function to use to return matching copyrights. + * @data: the user data to use to call the callbaack function. + * + * retreive copyright(s) for the corresponding bounding box and zoom level. + */ +void +vik_map_source_get_copyright (VikMapSource *self, LatLonBBox bbox, gdouble zoom, void (*fct)(void*,const gchar*), void *data) { VikMapSourceClass *klass; - g_return_val_if_fail (self != NULL, NULL); - g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); + g_return_if_fail (self != NULL); + g_return_if_fail (VIK_IS_MAP_SOURCE (self)); klass = VIK_MAP_SOURCE_GET_CLASS(self); - g_return_val_if_fail (klass->get_copyright != NULL, NULL); + g_return_if_fail (klass->get_copyright != NULL); - return (*klass->get_copyright)(self); + (*klass->get_copyright)(self, bbox, zoom, fct, data); } const gchar * diff --git a/src/vikmapsource.h b/src/vikmapsource.h index 2400fec..1de2b01 100644 --- a/src/vikmapsource.h +++ b/src/vikmapsource.h @@ -25,6 +25,7 @@ #include "vikviewport.h" #include "vikcoord.h" #include "mapcoord.h" +#include "bbox.h" G_BEGIN_DECLS @@ -43,7 +44,7 @@ struct _VikMapSourceClass GObjectClass parent_class; /* Legal info */ - const gchar *(* get_copyright) (VikMapSource * self); + void (* get_copyright) (VikMapSource * self, LatLonBBox bbox, gdouble zoom, void (*fct)(void*,const gchar*), void *data); const gchar *(* get_license) (VikMapSource * self); const gchar *(* get_license_url) (VikMapSource * self); const GdkPixbuf *(* get_logo) (VikMapSource * self); @@ -68,7 +69,7 @@ struct _VikMapSource GType vik_map_source_get_type (void) G_GNUC_CONST; -const gchar *vik_map_source_get_copyright (VikMapSource * self); +void vik_map_source_get_copyright (VikMapSource * self, LatLonBBox bbox, gdouble zoom, void (*fct)(void*,const gchar*), void *data); const gchar *vik_map_source_get_license (VikMapSource * self); const gchar *vik_map_source_get_license_url (VikMapSource * self); const GdkPixbuf *vik_map_source_get_logo (VikMapSource * self); diff --git a/src/vikmapsourcedefault.c b/src/vikmapsourcedefault.c index a85bba9..6834998 100644 --- a/src/vikmapsourcedefault.c +++ b/src/vikmapsourcedefault.c @@ -21,7 +21,7 @@ #include "vikenumtypes.h" #include "download.h" -static const gchar *map_source_get_copyright (VikMapSource *self); +static void map_source_get_copyright (VikMapSource *self, LatLonBBox bbox, gdouble zoom, void (*fct)(void*,const gchar*), void *data); static const gchar *map_source_get_license (VikMapSource *self); static const gchar *map_source_get_license_url (VikMapSource *self); static const GdkPixbuf *map_source_get_logo (VikMapSource *self); @@ -305,14 +305,19 @@ vik_map_source_default_class_init (VikMapSourceDefaultClass *klass) object_class->finalize = vik_map_source_default_finalize; } -static const gchar * -map_source_get_copyright (VikMapSource *self) +static void +map_source_get_copyright (VikMapSource *self, LatLonBBox bbox, gdouble zoom, void (*fct)(void*,const gchar*), void *data) { + /* Just ignore bbox and zoom level */ g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT(self), NULL); + + g_debug ("%s: %g %g %g %g %g", __FUNCTION__, + bbox.south, bbox.north, bbox.east, bbox.west, + zoom); VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE(self); - return priv->copyright; + (*fct) (data, priv->copyright); } static const gchar * -- 1.7.2.3 ------------------------------------------------------------------------------ The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE: Pinpoint memory and threading errors before they happen. Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance. http://p.sf.net/sfu/intel-dev2devfeb _______________________________________________ Viking-devel mailing list Viking-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/viking-devel Viking home page: http://viking.sf.net/