* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
-#include <gtk/gtk.h>
+ #ifdef HAVE_CONFIG_H
+ #include "config.h"
+ #endif
+
-#ifdef HAVE_MATH_H
-#include <math.h>
-#endif
-#include "viking.h"
-#include "coords.h"
-#include "vikcoord.h"
-#include "mapcoord.h"
+ #include <glib/gi18n.h>
+
+#include "osm.h"
#include "vikmapslayer.h"
+#include "vikslippymapsource.h"
+ #include "vikwebtoolcenter.h"
+ #include "vikexttools.h"
-#include "osm.h"
-
-static guint8 osm_zoom ( gdouble mpp );
-
-static gboolean osm_coord_to_mapcoord ( const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest );
-static void osm_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest );
-static int osm_maplint_download ( MapCoord *src, const gchar *dest_fn );
-static int osm_mapnik_download ( MapCoord *src, const gchar *dest_fn );
-static int osm_osmarender_download ( MapCoord *src, const gchar *dest_fn );
-static int osm_cycle_download ( MapCoord *src, const gchar *dest_fn );
-#ifdef VIK_CONFIG_BLUEMARBLE
-static int bluemarble_download ( MapCoord *src, const gchar *dest_fn );
-#endif
-#ifdef VIK_CONFIG_OPENAERIAL
-static int openaerialmap_download ( MapCoord *src, const gchar *dest_fn );
-#endif
-
-static DownloadOptions osm_options = { NULL, 0, a_check_map_file };
-
/* 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 }; VikMapsLayer_MapType maplint_type = { 14, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, osm_coord_to_mapcoord, osm_mapcoord_to_center_coord, osm_maplint_download };
- VikMapsLayer_MapType cycle_type = { 17, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, osm_coord_to_mapcoord, osm_mapcoord_to_center_coord, osm_cycle_download };
+ VikMapSource *osmarender_type = VIK_MAP_SOURCE(vik_slippy_map_source_new_with_id(12, "tah.openstreetmap.org", "/Tiles/tile/%d/%d/%d.png"));
+ VikMapSource *mapnik_type = VIK_MAP_SOURCE(vik_slippy_map_source_new_with_id( 13, "tile.openstreetmap.org", "/%d/%d/%d.png"));
+ VikMapSource *maplint_type = VIK_MAP_SOURCE(vik_slippy_map_source_new_with_id( 14, "tah.openstreetmap.org", "/Tiles/maplint.php/%d/%d/%d.png"));
+ VikMapSource *cycle_type = VIK_MAP_SOURCE(vik_slippy_map_source_new_with_id( 17, "thunderflames.org/tiles/cycle/", "%d/%d/%d.png" ));
-#ifdef VIK_CONFIG_BLUEMARBLE
- VikMapsLayer_MapType bluemarble_type = { 15, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, osm_coord_to_mapcoord, osm_mapcoord_to_center_coord, bluemarble_download };
-#endif
-
-#ifdef VIK_CONFIG_OPENAERIAL
- VikMapsLayer_MapType openaerialmap_type = { 20, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, osm_coord_to_mapcoord, osm_mapcoord_to_center_coord, openaerialmap_download };
-#endif
-
- maps_layer_register_type("OpenStreetMap (Osmarender)", 12, &osmarender_type);
- maps_layer_register_type("OpenStreetMap (Mapnik)", 13, &mapnik_type);
- maps_layer_register_type("OpenStreetMap (Maplint)", 14, &maplint_type);
- maps_layer_register_type("OpenStreetMap (Cycle)", 17, &cycle_type);
-
-#ifdef VIK_CONFIG_BLUEMARBLE
- maps_layer_register_type("BlueMarble", 15, &bluemarble_type);
-#endif
-#ifdef VIK_CONFIG_OPENAERIAL
- maps_layer_register_type("OpenAerialMap", 20, &openaerialmap_type);
-#endif
+ maps_layer_register_map_source ("OpenStreetMap (Osmarender)", osmarender_type);
+ maps_layer_register_map_source ("OpenStreetMap (Mapnik)", mapnik_type);
+ maps_layer_register_map_source ("OpenStreetMap (Maplint)", maplint_type);
+ maps_layer_register_map_source ("OpenStreetMap (Cycle)", cycle_type);
+
+ // Webtools
+ VikWebtoolCenter *webtool = NULL;
+ webtool = vik_webtool_center_new_with_members ( _("OSM (view)"), "http://openstreetmap.org/?lat=%s&lon=%s&zoom=%d&layers=B000FTF" );
+ vik_ext_tools_register ( VIK_EXT_TOOL ( webtool ) );
+ g_object_unref ( webtool );
+
+ webtool = vik_webtool_center_new_with_members ( _("OSM (edit)"), "http://www.openstreetmap.org/edit?lat=%s&lon=%s&zoom=%d" );
+ vik_ext_tools_register ( VIK_EXT_TOOL ( webtool ) );
+ g_object_unref ( webtool );
+
+ webtool = vik_webtool_center_new_with_members ( _("OSM (render)"), "http://www.informationfreeway.org/?lat=%s&lon=%s&zoom=%d&layers=B0000F000F" );
+ vik_ext_tools_register ( VIK_EXT_TOOL ( webtool ) );
+ g_object_unref ( webtool );
}
-/* 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;
-}
-
-static 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;
-}
-
-static 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));
-}
-
-/* Maplint tiles
- * Ex: http://dev.openstreetmap.org/~ojw/Tiles/maplint.php/10/517/375.png
- */
-static int osm_maplint_download ( MapCoord *src, const gchar *dest_fn )
-{
- int res = -1;
- gchar *uri = g_strdup_printf ( "/Tiles/maplint.php/%d/%d/%d.png", 17-src->scale, src->x, src->y );
- res = a_http_download_get_url ( "tah.openstreetmap.org", uri, dest_fn, &osm_options );
- g_free ( uri );
- return res;
-}
-
-static int osm_mapnik_download ( MapCoord *src, const gchar *dest_fn )
-{
- int res = -1;
- gchar *uri = g_strdup_printf ( "/%d/%d/%d.png", 17-src->scale, src->x, src->y );
- res = a_http_download_get_url ( "tile.openstreetmap.org", uri, dest_fn, &osm_options );
- g_free ( uri );
- return res;
-}
-
-static int osm_osmarender_download ( MapCoord *src, const gchar *dest_fn )
-{
- int res = -1;
- gchar *uri = g_strdup_printf ( "/Tiles/tile/%d/%d/%d.png", 17-src->scale, src->x, src->y );
- res = a_http_download_get_url ( "tah.openstreetmap.org", uri, dest_fn, &osm_options );
- g_free ( uri );
- return res;
-}
-
-#ifdef VIK_CONFIG_BLUEMARBLE
-static int bluemarble_download ( MapCoord *src, const gchar *dest_fn )
-{
- int res = -1;
- gchar *uri = g_strdup_printf ( "/com.modestmaps.bluemarble/%d-r%d-c%d.jpg", 17-src->scale, src->y, src->x );
- res = a_http_download_get_url ( "s3.amazonaws.com", uri, dest_fn, &osm_options );
-
- g_free ( uri );
- return res;
-
-}
-#endif
-
-#ifdef VIK_CONFIG_OPENAERIAL
-static int openaerialmap_download ( MapCoord *src, const gchar *dest_fn )
-{
- int res = -1;
- gchar *uri = g_strdup_printf ( "/tiles/1.0.0/openaerialmap-900913/%d/%d/%d.jpg", 17-src->scale, src->x, src->y );
- res = a_http_download_get_url ( "tile.openaerialmap.org", uri, dest_fn, &osm_options );
-
- g_free ( uri );
- return res;
-}
-#endif
-
-static int osm_cycle_download ( MapCoord *src, const gchar *dest_fn )
-{
- int res = -1;
- gchar *uri = g_strdup_printf ( "/tiles/cycle/%d/%d/%d.png", 17-src->scale, src->x, src->y );
- res = a_http_download_get_url ( "andy.sandbox.cloudmade.com", uri, dest_fn, &osm_options );
- g_free ( uri );
- return res;
-}
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
+ #ifdef HAVE_CONFIG_H
+ #include "config.h"
+ #endif
-#include <gtk/gtk.h>
-#ifdef HAVE_MATH_H
-#include <math.h>
-#endif
-
-#include "viking.h"
-#include "coords.h"
-#include "vikcoord.h"
-#include "mapcoord.h"
-#include "download.h"
-#include "vikmapslayer.h"
-
#include "terraserver.h"
-
-static gboolean terraserver_topo_coord_to_mapcoord ( const VikCoord *src, gdouble xmpp, gdouble ympp, MapCoord *dest );
-static int terraserver_topo_download ( MapCoord *src, const gchar *dest_fn );
-
-static gboolean terraserver_aerial_coord_to_mapcoord ( const VikCoord *src, gdouble xmpp, gdouble ympp, MapCoord *dest );
-static int terraserver_aerial_download ( MapCoord *src, const gchar *dest_fn );
-
-static gboolean terraserver_urban_coord_to_mapcoord ( const VikCoord *src, gdouble xmpp, gdouble ympp, MapCoord *dest );
-static int terraserver_urban_download ( MapCoord *src, const gchar *dest_fn );
-
-static void terraserver_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest );
-
-static DownloadOptions terraserver_options = { NULL, 0, a_check_map_file };
+#include "terraservermapsource.h"
+#include "vikmapslayer.h"
void terraserver_init () {
- VikMapsLayer_MapType map_type_1 = { 2, 200, 200, VIK_VIEWPORT_DRAWMODE_UTM, terraserver_topo_coord_to_mapcoord, terraserver_mapcoord_to_center_coord, terraserver_topo_download };
- VikMapsLayer_MapType map_type_2 = { 1, 200, 200, VIK_VIEWPORT_DRAWMODE_UTM, terraserver_aerial_coord_to_mapcoord, terraserver_mapcoord_to_center_coord, terraserver_aerial_download };
- VikMapsLayer_MapType map_type_3 = { 4, 200, 200, VIK_VIEWPORT_DRAWMODE_UTM, terraserver_urban_coord_to_mapcoord, terraserver_mapcoord_to_center_coord, terraserver_urban_download };
-
- maps_layer_register_type("Terraserver Topos", 2, &map_type_1);
- maps_layer_register_type("Terraserver Aerials", 1, &map_type_2);
- maps_layer_register_type("Terraserver Urban Areas", 4, &map_type_3);
-}
-
-#define TERRASERVER_SITE "terraserver-usa.com"
-#define MARGIN_OF_ERROR 0.001
-
-static int mpp_to_scale ( gdouble mpp, guint8 type )
-{
- mpp *= 4;
- gint t = (gint) mpp;
- if ( ABS(mpp - t) > MARGIN_OF_ERROR )
- return FALSE;
+ VikMapSource *map_type_1 = VIK_MAP_SOURCE(terraserver_map_source_new_with_id( 2, 2 ));
+ VikMapSource *map_type_2 = VIK_MAP_SOURCE(terraserver_map_source_new_with_id( 1, 1 ));
+ VikMapSource *map_type_3 = VIK_MAP_SOURCE(terraserver_map_source_new_with_id( 4, 4 ));
- switch ( t ) {
- case 1: return (type == 4) ? 8 : 0;
- case 2: return (type == 4) ? 9 : 0;
- case 4: return (type != 2) ? 10 : 0;
- case 8: return 11;
- case 16: return 12;
- case 32: return 13;
- case 64: return 14;
- case 128: return 15;
- case 256: return 16;
- case 512: return 17;
- case 1024: return 18;
- case 2048: return 19;
- default: return 0;
- }
+ maps_layer_register_map_source ("Terraserver Topos", map_type_1);
+ maps_layer_register_map_source ("Terraserver Aerials", map_type_2);
+ maps_layer_register_map_source ("Terraserver Urban Areas", map_type_3);
}
-
-static gdouble scale_to_mpp ( gint scale )
-{
- return pow(2,scale - 10);
-}
-
-static gboolean terraserver_coord_to_mapcoord ( const VikCoord *src, gdouble xmpp, gdouble ympp, MapCoord *dest, guint8 type )
-{
- g_assert ( src->mode == VIK_COORD_UTM );
-
- if ( xmpp != ympp )
- return FALSE;
-
- dest->scale = mpp_to_scale ( xmpp, type );
- if ( ! dest->scale )
- return FALSE;
-
- dest->x = (gint)(((gint)(src->east_west))/(200*xmpp));
- dest->y = (gint)(((gint)(src->north_south))/(200*xmpp));
- dest->z = src->utm_zone;
- return TRUE;
-}
-
-static gboolean terraserver_topo_coord_to_mapcoord ( const VikCoord *src, gdouble xmpp, gdouble ympp, MapCoord *dest )
-{ return terraserver_coord_to_mapcoord ( src, xmpp, ympp, dest, 2 ); }
-static gboolean terraserver_aerial_coord_to_mapcoord ( const VikCoord *src, gdouble xmpp, gdouble ympp, MapCoord *dest )
-{ return terraserver_coord_to_mapcoord ( src, xmpp, ympp, dest, 1 ); }
-static gboolean terraserver_urban_coord_to_mapcoord ( const VikCoord *src, gdouble xmpp, gdouble ympp, MapCoord *dest )
-{ return terraserver_coord_to_mapcoord ( src, xmpp, ympp, dest, 4 ); }
-
-static void terraserver_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest )
-{
- // FIXME: slowdown here!
- gdouble mpp = scale_to_mpp ( src->scale );
- dest->mode = VIK_COORD_UTM;
- dest->utm_zone = src->z;
- dest->east_west = ((src->x * 200) + 100) * mpp;
- dest->north_south = ((src->y * 200) + 100) * mpp;
-}
-
-static int terraserver_download ( MapCoord *src, const gchar *dest_fn, guint8 type )
-{
- int res = -1;
- gchar *uri = g_strdup_printf ( "/tile.ashx?T=%d&S=%d&X=%d&Y=%d&Z=%d", type,
- src->scale, src->x, src->y, src->z );
- res = a_http_download_get_url ( TERRASERVER_SITE, uri, dest_fn, &terraserver_options );
- g_free ( uri );
- return(res);
-}
-
-static int terraserver_topo_download ( MapCoord *src, const gchar *dest_fn )
-{ return terraserver_download ( src, dest_fn, 2 ); }
-static int terraserver_aerial_download ( MapCoord *src, const gchar *dest_fn )
-{ return terraserver_download ( src, dest_fn, 1 ); }
-static int terraserver_urban_download ( MapCoord *src, const gchar *dest_fn )
-{ return terraserver_download ( src, dest_fn, 4 ); }