8 #include "vikmapsourcedefault.h"
17 #include "vikviewport.h"
26 static DownloadOptions terraserver_options = { NULL, 0, a_check_map_file };
28 #define TERRASERVER_SITE "terraserver-usa.com"
29 #define MARGIN_OF_ERROR 0.001
31 static int mpp_to_scale ( gdouble mpp, guint8 type )
35 if ( ABS(mpp - t) > MARGIN_OF_ERROR )
39 case 1: return (type == 4) ? 8 : 0;
40 case 2: return (type == 4) ? 9 : 0;
41 case 4: return (type != 2) ? 10 : 0;
55 static gdouble scale_to_mpp ( gint scale )
57 return pow(2,scale - 10);
62 class Terraserver:Map:Type from Vik:Map:Source:Default {
66 /* initialize the object here */
67 // FIXME VIK_MAP_SOURCE_DEFAULT(self)->tilesize_x = 200;
68 // FIXME VIK_MAP_SOURCE_DEFAULT(self)->tilesize_y = 200;
69 // FIXME VIK_MAP_SOURCE_DEFAULT(self)->drawmode = VIK_VIEWPORT_DRAWMODE_UTM;
73 new_with_id (guint8 id, int type) {
74 TerraserverMapType *ret = GET_NEW;
75 // FIXME VIK_MAP_SOURCE_DEFAULT(ret)->uniq_id = id;
76 ret->_priv->type = type;
77 return G_OBJECT (ret);
80 override (Vik:Map:Source) gboolean
81 coord_to_mapcoord ( Vik:Map:Source *self, const VikCoord *src, gdouble xmpp, gdouble ympp, MapCoord *dest )
83 int type = TERRASERVER_MAP_TYPE(self)->_priv->type;
84 g_assert ( src->mode == VIK_COORD_UTM );
89 dest->scale = mpp_to_scale ( xmpp, type );
93 dest->x = (gint)(((gint)(src->east_west))/(200*xmpp));
94 dest->y = (gint)(((gint)(src->north_south))/(200*xmpp));
95 dest->z = src->utm_zone;
99 override (Vik:Map:Source) void
100 mapcoord_to_center_coord ( Vik:Map:Source *self, MapCoord *src, VikCoord *dest )
102 // FIXME: slowdown here!
103 gdouble mpp = scale_to_mpp ( src->scale );
104 dest->mode = VIK_COORD_UTM;
105 dest->utm_zone = src->z;
106 dest->east_west = ((src->x * 200) + 100) * mpp;
107 dest->north_south = ((src->y * 200) + 100) * mpp;
110 override (Vik:Map:Source) int
111 download ( Vik:Map:Source *self, MapCoord *src, const gchar *dest_fn )
114 int type = TERRASERVER_MAP_TYPE(self)->_priv->type;
115 gchar *uri = g_strdup_printf ( "/tile.ashx?T=%d&S=%d&X=%d&Y=%d&Z=%d", type,
116 src->scale, src->x, src->y, src->z );
117 res = a_http_download_get_url ( TERRASERVER_SITE, uri, dest_fn, &terraserver_options );