]> git.street.me.uk Git - andy/viking.git/commitdiff
New module for OpenStreetMap sources.
authorGuilhem Bonnefille <guilhem.bonnefille@gmail.com>
Mon, 23 Apr 2007 20:25:05 +0000 (20:25 +0000)
committerGuilhem Bonnefille <guilhem.bonnefille@gmail.com>
Mon, 23 Apr 2007 20:25:05 +0000 (20:25 +0000)
Extract slippy maps code from google.c and create a new module.
This one inserts two map sources: Osmarender and Mapnik.

ChangeLog
src/Makefile.am
src/google.c
src/google.h
src/modules.c
src/osm.c [new file with mode: 0644]
src/osm.h [new file with mode: 0644]
src/vikmapslayer.c

index 28d705222242095c2fa149d7c8b512a5a00bec9e..d30cc69c5cb73d18f554f17e24cd09395e80dcd3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2007-04-23
+Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+       * OpenSourceMap slippy maps (in osm.c) -- Osmarender and Mapnik
+
 2007-04-21
 Evan Battaglia <gtoevan@gmx.net>
        * OpenSourceMap slippy maps (in google.c) -- identical to google maps except zoom numbering
 2007-04-21
 Evan Battaglia <gtoevan@gmx.net>
        * OpenSourceMap slippy maps (in google.c) -- identical to google maps except zoom numbering
index 46a26fb4680e594326bd543802123018d7493961..fc652c6e5e90346efa09af6c275136b7192ffcdc 100644 (file)
@@ -83,6 +83,10 @@ viking_SOURCES += \
        expedia.c expedia.h
 endif
 
        expedia.c expedia.h
 endif
 
+viking_SOURCES += \
+       osm.c osm.h
+
+
 INCLUDES        = @GTK_CFLAGS@ @EXPAT_CFLAGS@ @LIBCURL_CPPFLAGS@
 LDADD           = @GTK_LIBS@ @EXPAT_LIBS@ @LIBCURL@
 AM_CFLAGS              = -Wall -g
 INCLUDES        = @GTK_CFLAGS@ @EXPAT_CFLAGS@ @LIBCURL_CPPFLAGS@
 LDADD           = @GTK_LIBS@ @EXPAT_LIBS@ @LIBCURL@
 AM_CFLAGS              = -Wall -g
index d2f828480edff1479ebf6c41b15ae1b3e2c57621..4bc5ce5e4bd03e1b7fa199f0ced5ca302a891b6d 100644 (file)
@@ -38,12 +38,10 @@ void google_init () {
   VikMapsLayer_MapType google_1 = { 7, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_download };
   VikMapsLayer_MapType google_2 = { 10, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_trans_download };
   VikMapsLayer_MapType google_3 = { 11, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_kh_download };
   VikMapsLayer_MapType google_1 = { 7, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_download };
   VikMapsLayer_MapType google_2 = { 10, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_trans_download };
   VikMapsLayer_MapType google_3 = { 11, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_kh_download };
-  VikMapsLayer_MapType slippy = { 12, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_slippy_download };
 
   maps_layer_register_type("Google Maps", 7, &google_1);
   maps_layer_register_type("Transparent Google Maps", 10, &google_2);
   maps_layer_register_type("Google Satellite Images", 11, &google_3);
 
   maps_layer_register_type("Google Maps", 7, &google_1);
   maps_layer_register_type("Transparent Google Maps", 10, &google_2);
   maps_layer_register_type("Google Satellite Images", 11, &google_3);
-  maps_layer_register_type("OpenStreetMap Slippy Maps", 12, &slippy);
 }
 
 /* 1 << (x) is like a 2**(x) */
 }
 
 /* 1 << (x) is like a 2**(x) */
@@ -156,10 +154,3 @@ void google_kh_download ( MapCoord *src, const gchar *dest_fn )
    a_http_download_get_url ( "kh.google.com", uri, dest_fn );
    g_free ( uri );
 }
    a_http_download_get_url ( "kh.google.com", uri, dest_fn );
    g_free ( uri );
 }
-
-void google_slippy_download ( MapCoord *src, const gchar *dest_fn )
-{
-   gchar *uri = g_strdup_printf ( "/%d/%d/%d.png", 17-src->scale, src->x, src->y );
-   a_http_download_get_url ( "tile.openstreetmap.org", uri, dest_fn );
-   g_free ( uri );
-}
index 7997865e8f622b40be94f0fadfd670adf2d76829..adde53888323e2ea048c82eaa5ab02a92ef15cea 100644 (file)
@@ -41,6 +41,5 @@ void google_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest );
 void google_download ( MapCoord *src, const gchar *dest_fn );
 void google_trans_download ( MapCoord *src, const gchar *dest_fn );
 void google_kh_download ( MapCoord *src, const gchar *dest_fn );
 void google_download ( MapCoord *src, const gchar *dest_fn );
 void google_trans_download ( MapCoord *src, const gchar *dest_fn );
 void google_kh_download ( MapCoord *src, const gchar *dest_fn );
-void google_slippy_download ( MapCoord *src, const gchar *dest_fn );
 
 #endif
 
 #endif
index 2b56aeffe500d5c51b979a6fc27a1b99db80ece5..da528b089986b464677ad4cd3cfb514102b117f3 100644 (file)
@@ -30,6 +30,7 @@
 #include "terraserver.h"
 #include "khmaps.h"
 #include "expedia.h"
 #include "terraserver.h"
 #include "khmaps.h"
 #include "expedia.h"
+#include "osm.h"
 
 void modules_init()
 {
 
 void modules_init()
 {
@@ -44,5 +45,6 @@ void modules_init()
 #ifdef VIK_CONFIG_TERRASERVER
   terraserver_init();
 #endif
 #ifdef VIK_CONFIG_TERRASERVER
   terraserver_init();
 #endif
+  osm_init();
 }
 
 }
 
diff --git a/src/osm.c b/src/osm.c
new file mode 100644 (file)
index 0000000..0c5eed7
--- /dev/null
+++ b/src/osm.c
@@ -0,0 +1,96 @@
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
+ *
+ * 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
+ *
+ */
+
+#include <gtk/gtk.h>
+#include <math.h>
+#include "viking.h"
+#include "coords.h"
+#include "vikcoord.h"
+#include "mapcoord.h"
+#include "http.h"
+#include "vikmapslayer.h"
+
+#include "osm.h"
+
+/* initialisation */
+void osm_init () {
+  VikMapsLayer_MapType osmarender_type = { 12, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, osm_coord_to_mapcoord, osm_mapcoord_to_center_coord, osm_osmarender_download };
+  VikMapsLayer_MapType mapnik_type = { 13, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, osm_coord_to_mapcoord, osm_mapcoord_to_center_coord, osm_mapnik_download };
+  maps_layer_register_type("OpenStreetMap (Osmarender)", 12, &osmarender_type);
+  maps_layer_register_type("OpenStreetMap (Mapnik)", 13, &mapnik_type);
+}
+
+/* 1 << (x) is like a 2**(x) */
+#define GZ(x) (1<<(x))
+
+static const gdouble scale_mpps[] = { GZ(0), GZ(1), GZ(2), GZ(3), GZ(4), GZ(5), GZ(6), GZ(7), GZ(8), GZ(9),
+                                      GZ(10), GZ(11), GZ(12), GZ(13), GZ(14), GZ(15), GZ(16), GZ(17) };
+
+static const gint num_scales = (sizeof(scale_mpps) / sizeof(scale_mpps[0]));
+
+#define ERROR_MARGIN 0.01
+guint8 osm_zoom ( gdouble mpp ) {
+  gint i;
+  for ( i = 0; i < num_scales; i++ ) {
+    if ( ABS(scale_mpps[i] - mpp) < ERROR_MARGIN )
+      return i;
+  }
+  return 255;
+}
+
+gboolean osm_coord_to_mapcoord ( const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
+{
+  g_assert ( src->mode == VIK_COORD_LATLON );
+
+  if ( xzoom != yzoom )
+    return FALSE;
+
+  dest->scale = osm_zoom ( xzoom );
+  if ( dest->scale == 255 )
+    return FALSE;
+
+  dest->x = (src->east_west + 180) / 360 * GZ(17) / xzoom;
+  dest->y = (180 - MERCLAT(src->north_south)) / 360 * GZ(17) / xzoom;
+  dest->z = 0;
+  return TRUE;
+}
+
+void osm_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest )
+{
+  gdouble socalled_mpp = GZ(src->scale);
+  dest->mode = VIK_COORD_LATLON;
+  dest->east_west = ((src->x+0.5) / GZ(17) * socalled_mpp * 360) - 180;
+  dest->north_south = DEMERCLAT(180 - ((src->y+0.5) / GZ(17) * socalled_mpp * 360));
+}
+
+void osm_mapnik_download ( MapCoord *src, const gchar *dest_fn )
+{
+   gchar *uri = g_strdup_printf ( "/osamrender/%d/%d/%d.png", 17-src->scale, src->x, src->y );
+   a_http_download_get_url ( "tile.openstreetmap.org", uri, dest_fn );
+   g_free ( uri );
+}
+
+void osm_osmarender_download ( MapCoord *src, const gchar *dest_fn )
+{
+   gchar *uri = g_strdup_printf ( "/~ojw/Tiles/tile.php/%d/%d/%d.png", 17-src->scale, src->x, src->y );
+   a_http_download_get_url ( "dev.openstreetmap.org", uri, dest_fn );
+   g_free ( uri );
+}
diff --git a/src/osm.h b/src/osm.h
new file mode 100644 (file)
index 0000000..8e16bb4
--- /dev/null
+++ b/src/osm.h
@@ -0,0 +1,39 @@
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
+ *
+ * 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 __VIKING_OSMARENDER_H
+#define __VIKING_OSMARENDER_H
+
+#include <glib.h>
+
+#include "vikcoord.h"
+#include "mapcoord.h"
+
+void osm_init ();
+
+guint8 osm_zoom ( gdouble mpp );
+
+gboolean osm_coord_to_mapcoord ( const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest );
+void osm_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest );
+void osm_mapnik_download ( MapCoord *src, const gchar *dest_fn );
+void osm_osmarender_download ( MapCoord *src, const gchar *dest_fn );
+
+#endif
index 5b0eb9402eee340e76ce49210fbbb4f139a044d0..861af8edd13587961b7bcb9a41692915e7316c8a 100644 (file)
 
 #include "mapcoord.h"
 #include "terraserver.h"
 
 #include "mapcoord.h"
 #include "terraserver.h"
-#include "googlemaps.h"
-#include "google.h"
-#include "khmaps.h"
-#include "expedia.h"
-
 
 /****** MAP TYPES ******/
 
 
 /****** MAP TYPES ******/