8 #include "vik-map-type.h"
25 static DownloadOptions terraserver_options = { NULL, 0, a_check_map_file };
27 #define TERRASERVER_SITE "terraserver-usa.com"
28 #define MARGIN_OF_ERROR 0.001
30 static int mpp_to_scale ( gdouble mpp, guint8 type )
34 if ( ABS(mpp - t) > MARGIN_OF_ERROR )
38 case 1: return (type == 4) ? 8 : 0;
39 case 2: return (type == 4) ? 9 : 0;
40 case 4: return (type != 2) ? 10 : 0;
54 static gdouble scale_to_mpp ( gint scale )
56 return pow(2,scale - 10);
61 class Terraserver:Map:Type from Vik:Map:Type {
64 override (Vik:Map:Type) gboolean
65 coord_to_mapcoord ( Vik:Map:Type *self, const VikCoord *src, gdouble xmpp, gdouble ympp, MapCoord *dest )
67 int type = TERRASERVER_MAP_TYPE(self)->_priv->type;
68 g_assert ( src->mode == VIK_COORD_UTM );
73 dest->scale = mpp_to_scale ( xmpp, type );
77 dest->x = (gint)(((gint)(src->east_west))/(200*xmpp));
78 dest->y = (gint)(((gint)(src->north_south))/(200*xmpp));
79 dest->z = src->utm_zone;
83 override (Vik:Map:Type) void
84 mapcoord_to_center_coord ( Vik:Map:Type *self, MapCoord *src, VikCoord *dest )
86 // FIXME: slowdown here!
87 gdouble mpp = scale_to_mpp ( src->scale );
88 dest->mode = VIK_COORD_UTM;
89 dest->utm_zone = src->z;
90 dest->east_west = ((src->x * 200) + 100) * mpp;
91 dest->north_south = ((src->y * 200) + 100) * mpp;
94 override (Vik:Map:Type) int
95 download ( Vik:Map:Type *self, MapCoord *src, const gchar *dest_fn )
98 int type = TERRASERVER_MAP_TYPE(self)->_priv->type;
99 gchar *uri = g_strdup_printf ( "/tile.ashx?T=%d&S=%d&X=%d&Y=%d&Z=%d", type,
100 src->scale, src->x, src->y, src->z );
101 res = a_http_download_get_url ( TERRASERVER_SITE, uri, dest_fn, &terraserver_options );