Re: [Viking-devel] Request for comment for Bing maps support

2011-02-13 Thread Robert Norris


> Date: Sun, 13 Feb 2011 11:27:50 -0800
> From: miker...@lacklustre.net
> To: viking-devel@lists.sourceforge.net
> Subject: Re: [Viking-devel] Request for comment for Bing maps support
>
> Quickie: the copyright notice is displayed twice if you enable
> auto-downloading of maps after you add the layer.
>
> To reproduce:
>
> 1) add a new bing map layer
> 2) copyright notice appears, click OK
> 3) right click map, go to properties
> 4) check "autodownload maps", click OK
> 5) copyright notice reappears
>

I think you might mean the 'map license dialog' is shown more than once.

This is not just in the Bing maps effort  - in fact it is shown any time one 
changes the map layer properties, and thus is unfortunately in the 1.1 release 
:(

The attached quick hack should solve the issue by maintaining an internal flag 
per map layer about whether the license has been shown.

May need to consider if this is best way to resolve this problem...



  diff --git a/src/vikmapslayer.c b/src/vikmapslayer.c
index b72bad6..b415c89 100644
--- a/src/vikmapslayer.c
+++ b/src/vikmapslayer.c
@@ -211,6 +211,9 @@ struct _VikMapsLayer {
   GtkMenu *dl_right_click_menu;
   VikCoord redownload_ul, redownload_br; /* right click menu only */
   VikViewport *redownload_vvp;
+
+  gboolean license_notice_shown; // FALSE for new maps only, otherwise
+ // TRUE for saved maps & other layer changes as we don't need to show it again
 };
 
 enum { REDOWNLOAD_NONE = 0,/* download only missing maps */
@@ -455,6 +458,10 @@ static guint map_uniq_id_to_index ( guint uniq_id )
 
 static gboolean maps_layer_set_param ( VikMapsLayer *vml, guint16 id, VikLayerParamData data, VikViewport *vvp, gboolean is_file_operation )
 {
+  // When loading from a file don't need the license reminder
+  if ( is_file_operation )
+vml->license_notice_shown = TRUE;
+
   switch ( id )
   {
 case PARAM_CACHE_DIR: maps_layer_set_cache_dir ( vml, data.s ); break;
@@ -510,6 +517,7 @@ static VikMapsLayer *maps_layer_new ( VikViewport *vvp )
   vml->last_ympp = 0.0;
 
   vml->dl_right_click_menu = NULL;
+  vml->license_notice_shown = FALSE;
 
   return vml;
 }
@@ -545,8 +553,11 @@ static void maps_layer_post_read (VikLayer *vl, VikViewport *vp, gboolean from_f
 }
 
 if (vik_map_source_get_license (map) != NULL) {
-  a_dialog_license (VIK_GTK_WINDOW_FROM_WIDGET(vp), vik_map_source_get_label (map),
-vik_map_source_get_license (map), vik_map_source_get_license_url (map) );
+  if ( ! vml->license_notice_shown ) {
+	a_dialog_license (VIK_GTK_WINDOW_FROM_WIDGET(vp), vik_map_source_get_label (map),
+			  vik_map_source_get_license (map), vik_map_source_get_license_url (map) );
+	vml->license_notice_shown = TRUE;
+  }
 }
   }
 }
--
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/

Re: [Viking-devel] Request for comment for Bing maps support

2011-02-13 Thread Mike Ryan
Quickie: the copyright notice is displayed twice if you enable
auto-downloading of maps after you add the layer.

To reproduce:

1) add a new bing map layer
2) copyright notice appears, click OK
3) right click map, go to properties
4) check "autodownload maps", click OK
5) copyright notice reappears

--
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/


[Viking-devel] Request for comment for Bing maps support

2011-02-13 Thread Guilhem Bonnefille
Hi,

As you certainly noticed, I sent some patches to the mailing list.
These patches are my work for Bing maps support in viking. I think
this work is quite complete: maps appear, logo and copyright are
displayed. So I'm ready to commit them on master branch.

Nevertheless, I took some shortcuts in these implementations (as
commented on log messages).

So, before commiting them, I prefer to expose them to your comments.
Furthermore, you can experiment easily the resulting work by using the
following branch:
http://repo.or.cz/w/viking/guyou.git/shortlog/refs/heads/t/map/bing-maps
This branch is managed with topgit, so it is quite complex. It is the
reason why I pushed patches on the list: easier to comment.

Happy testing!
-- 
Guilhem BONNEFILLE
-=- JID: gu...@im.apinc.org MSN: guilhem_bonnefi...@hotmail.com
-=- mailto:guilhem.bonnefi...@gmail.com
-=- http://nathguil.free.fr/

--
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/


[Viking-devel] [PATCH 3/3] Add support for Bing maps

2011-02-13 Thread Guilhem Bonnefille
Add support for Bing maps.

This implementation is quite rude as:
* logo is built-in, while a right solution would be to download
  the logo and caching the result in viking's cache.
* attributions are downloaded at starting time, while a right
  solution would be to cache the file in viking's cache.

Signed-off-by: Guilhem Bonnefille 
---
 configure.ac  |   14 ++
 src/Makefile.am   |6 +
 src/bing.c|   42 
 src/bing.h|   28 +++
 src/bingmapsource.c   |  459 +
 src/bingmapsource.h   |   55 ++
 src/icons/Makefile.am |1 +
 src/icons/bing_maps.png   |  Bin 0 -> 4295 bytes
 src/modules.c |4 +
 src/vikmapsourcedefault.c |8 +-
 src/vikslippymapsource.c  |9 +-
 src/vikslippymapsource.h  |2 +
 12 files changed, 620 insertions(+), 8 deletions(-)
 create mode 100644 src/bing.c
 create mode 100644 src/bing.h
 create mode 100644 src/bingmapsource.c
 create mode 100644 src/bingmapsource.h
 create mode 100644 src/icons/bing_maps.png

diff --git a/configure.ac b/configure.ac
index bb282ee..b29d2bb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -114,6 +114,19 @@ case $ac_cv_enable_alpha_trw in
 ;;
 esac
 
+AC_ARG_ENABLE(bing, AC_HELP_STRING([--enable-bing],
+  [enable Bing stuff (default is enable)]),
+  [ac_cv_enable_bing=$enableval],
+  [ac_cv_enable_bing=yes])
+AC_CACHE_CHECK([whether to enable Bing stuff],
+   [ac_cv_enable_bing], [ac_cv_enable_bing=yes])
+case $ac_cv_enable_bing in
+  yes)
+AC_DEFINE(VIK_CONFIG_BING, [], [BING STUFF])
+;;
+esac
+AM_CONDITIONAL([BING], [test x$ac_cv_enable_bing = xyes])
+
 AC_ARG_ENABLE(google, AC_HELP_STRING([--enable-google],
   [enable Google stuff (default is enable)]),
   [ac_cv_enable_google=$enableval],
@@ -340,6 +353,7 @@ echo "==="
 echo "$PACKAGE $VERSION"
 echo "---"
 echo "Alphabetized track & waypoints   : $ac_cv_enable_alpha_trw"
+echo "Bing Maps: $ac_cv_enable_bing"
 echo "Google Maps  : $ac_cv_enable_google"
 echo "Terraserver Maps : $ac_cv_enable_terraserver"
 echo "Expedia Maps : $ac_cv_enable_expedia"
diff --git a/src/Makefile.am b/src/Makefile.am
index d9094af..d3d40b4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -122,6 +122,12 @@ libviking_a_SOURCES = \
print.c print.h \
preferences.c preferences.h
 
+if BING
+libviking_a_SOURCES += \
+   bingmapsource.c bingmapsource.h \
+   bing.c bing.h
+endif
+
 if GOOGLE
 libviking_a_SOURCES += \
google.c google.h
diff --git a/src/bing.c b/src/bing.c
new file mode 100644
index 000..41fae5e
--- /dev/null
+++ b/src/bing.c
@@ -0,0 +1,42 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2011, Guilhem Bonnefille 
+ *
+ * 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
+ *
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include 
+
+#include "bing.h"
+#include "vikmapslayer.h"
+#include "bingmapsource.h"
+
+/** API key registered by Guilhem Bonnefille */
+#define API_KEY 
"AqsTAipaBBpKLXhcaGgP8kceYukatmtDLS1x0CXEhRZnpl1RELF9hlI8j4mNIkrE"
+
+/* initialisation */
+void bing_init () {
+  VikMapSource *bing_aerial = VIK_MAP_SOURCE
+ (bing_map_source_new_with_id (212, "Bing Bird's Eye Maps", API_KEY));
+
+  maps_layer_register_map_source (bing_aerial);
+}
+
diff --git a/src/bing.h b/src/bing.h
new file mode 100644
index 000..07f99be
--- /dev/null
+++ b/src/bing.h
@@ -0,0 +1,28 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2011, Guilhem Bonnefille 
+ *
+ * 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 

[Viking-devel] [PATCH 2/3] Add support for dynamic copyright

2011-02-13 Thread Guilhem Bonnefille
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 
---
 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 000..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 
+ *
+ * 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/

[Viking-devel] [PATCH 1/3] Add logo support

2011-02-13 Thread Guilhem Bonnefille
Add support for logo, displayed in viewport.

Signed-off-by: Guilhem Bonnefille 
---
 src/vikmapslayer.c|4 
 src/vikmapsource.c|   14 ++
 src/vikmapsource.h|2 ++
 src/vikmapsourcedefault.c |   18 +-
 src/vikviewport.c |   44 
 src/vikviewport.h |4 
 src/vikwindow.c   |1 +
 7 files changed, 86 insertions(+), 1 deletions(-)

diff --git a/src/vikmapslayer.c b/src/vikmapslayer.c
index bf926f8..2fda822 100644
--- a/src/vikmapslayer.c
+++ b/src/vikmapslayer.c
@@ -848,6 +848,10 @@ static void maps_layer_draw ( VikMapsLayer *vml, 
VikViewport *vvp )
 const gchar *copyright = vik_map_source_get_copyright ( 
MAPS_LAYER_NTH_TYPE(vml->maptype) );
 vik_viewport_add_copyright ( vvp, copyright );
 
+/* Logo */
+GdkPixbuf *logo = vik_map_source_get_logo ( 
MAPS_LAYER_NTH_TYPE(vml->maptype) );
+vik_viewport_add_logo ( vvp, logo );
+
 /* get corner coords */
 if ( vik_viewport_get_coord_mode ( vvp ) == VIK_COORD_UTM && ! 
vik_viewport_is_one_zone ( vvp ) ) {
   /* UTM multi-zone stuff by Kit Transue */
diff --git a/src/vikmapsource.c b/src/vikmapsource.c
index 5378447..26e55ec 100644
--- a/src/vikmapsource.c
+++ b/src/vikmapsource.c
@@ -56,6 +56,7 @@ vik_map_source_class_init (VikMapSourceClass *klass)
klass->get_copyright = NULL;
klass->get_license = NULL;
klass->get_license_url = NULL;
+   klass->get_logo = NULL;
klass->get_uniq_id = NULL;
klass->get_label = NULL;
klass->get_tilesize_x = NULL;
@@ -117,6 +118,19 @@ vik_map_source_get_license_url (VikMapSource *self)
return (*klass->get_license_url)(self);
 }
 
+const GdkPixbuf *
+vik_map_source_get_logo (VikMapSource *self)
+{
+   VikMapSourceClass *klass;
+   g_return_val_if_fail (self != NULL, NULL);
+   g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
+   klass = VIK_MAP_SOURCE_GET_CLASS(self);
+
+   g_return_val_if_fail (klass->get_logo != NULL, NULL);
+
+   return (*klass->get_logo)(self);
+}
+
 guint8
 vik_map_source_get_uniq_id (VikMapSource *self)
 {
diff --git a/src/vikmapsource.h b/src/vikmapsource.h
index c0b80f3..2400fec 100644
--- a/src/vikmapsource.h
+++ b/src/vikmapsource.h
@@ -46,6 +46,7 @@ struct _VikMapSourceClass
const gchar *(* get_copyright) (VikMapSource * self);
const gchar *(* get_license) (VikMapSource * self);
const gchar *(* get_license_url) (VikMapSource * self);
+   const GdkPixbuf *(* get_logo) (VikMapSource * self);
 
guint8 (* get_uniq_id) (VikMapSource * self);
const gchar * (* get_label) (VikMapSource * self);
@@ -70,6 +71,7 @@ GType vik_map_source_get_type (void) G_GNUC_CONST;
 const gchar *vik_map_source_get_copyright (VikMapSource * self);
 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);
 
 guint8 vik_map_source_get_uniq_id (VikMapSource * self);
 const gchar *vik_map_source_get_label (VikMapSource * self);
diff --git a/src/vikmapsourcedefault.c b/src/vikmapsourcedefault.c
index aa2357a..a85bba9 100644
--- a/src/vikmapsourcedefault.c
+++ b/src/vikmapsourcedefault.c
@@ -24,6 +24,7 @@
 static const gchar *map_source_get_copyright (VikMapSource *self);
 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);
 
 static guint8 map_source_get_uniq_id (VikMapSource *self);
 static const gchar *map_source_get_label (VikMapSource *self);
@@ -42,7 +43,8 @@ struct _VikMapSourceDefaultPrivate
gchar *copyright;
gchar *license;
gchar *license_url;
-   
+   GdkPixbuf *logo;
+
guint8 uniq_id;
gchar *label;
guint16 tilesize_x;
@@ -79,6 +81,7 @@ vik_map_source_default_init (VikMapSourceDefault *object)
   priv->copyright = NULL;
   priv->license = NULL;
   priv->license_url = NULL;
+  priv->logo = NULL;
 }
 
 static void
@@ -95,6 +98,8 @@ vik_map_source_default_finalize (GObject *object)
   priv->license = NULL;
   g_free (priv->license_url);
   priv->license_url = NULL;
+  g_free (priv->logo);
+  priv->license_url = NULL;

   G_OBJECT_CLASS (vik_map_source_default_parent_class)->finalize (object);
 }
@@ -217,6 +222,7 @@ vik_map_source_default_class_init (VikMapSourceDefaultClass 
*klass)
parent_class->get_copyright =   map_source_get_copyright;
parent_class->get_license = map_source_get_license;
parent_class->get_license_url = map_source_get_license_url;
+   parent_class->get_logo =map_source_get_logo;
parent_class->get_uniq_id =map_source_get_uniq_id;
parent_class->get_label =  map_source_get_label;
parent_class->get_tilesize_