X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/67209ca83325c1986fd194cd71cb4aca1e5e6a81..9a3cdf12b1272d028726b3186c8db41afc5cbeb4:/src/osm.c diff --git a/src/osm.c b/src/osm.c index 0c5eed74..352da2a8 100644 --- a/src/osm.c +++ b/src/osm.c @@ -30,12 +30,23 @@ #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 ); + + /* 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 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 }; + 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); } /* 1 << (x) is like a 2**(x) */ @@ -56,7 +67,7 @@ guint8 osm_zoom ( gdouble mpp ) { return 255; } -gboolean osm_coord_to_mapcoord ( const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest ) +static gboolean osm_coord_to_mapcoord ( const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest ) { g_assert ( src->mode == VIK_COORD_LATLON ); @@ -73,7 +84,7 @@ gboolean osm_coord_to_mapcoord ( const VikCoord *src, gdouble xzoom, gdouble yzo return TRUE; } -void osm_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest ) +static void osm_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest ) { gdouble socalled_mpp = GZ(src->scale); dest->mode = VIK_COORD_LATLON; @@ -81,16 +92,32 @@ void osm_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest ) dest->north_south = DEMERCLAT(180 - ((src->y+0.5) / GZ(17) * socalled_mpp * 360)); } -void osm_mapnik_download ( MapCoord *src, const gchar *dest_fn ) +/* 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 ( "/~ojw/Tiles/maplint.php/%d/%d/%d.png", 17-src->scale, src->x, src->y ); + res = a_http_download_get_url ( "dev.openstreetmap.org", uri, dest_fn ); + g_free ( uri ); + return res; +} + +static int osm_mapnik_download ( MapCoord *src, const gchar *dest_fn ) { + int res = -1; 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 ); + res = a_http_download_get_url ( "tile.openstreetmap.org", uri, dest_fn ); g_free ( uri ); + return res; } -void osm_osmarender_download ( MapCoord *src, const gchar *dest_fn ) +static int osm_osmarender_download ( MapCoord *src, const gchar *dest_fn ) { + int res = -1; 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 ); + res = a_http_download_get_url ( "dev.openstreetmap.org", uri, dest_fn ); g_free ( uri ); + return res; }