8 #include "vik-map-type.h"
18 #include "googlemaps.h"
20 /* 1 << (x-1) is like a 2**(x-1) */
21 #define GZ(x) ((1<<(x-1))*GOOGLEMAPS_ZOOM_ONE_MPP)
23 static const gdouble scale_mpps[] = { GZ(1)/2, GZ(1), GZ(2), GZ(3), GZ(4), GZ(5), GZ(6), GZ(7), GZ(8), GZ(9),
24 GZ(10), GZ(11), GZ(12), GZ(13), GZ(14), GZ(15) };
26 static const gint num_scales = (sizeof(scale_mpps) / sizeof(scale_mpps[0]));
28 #define ERROR_MARGIN 0.01
29 static guint8 googlemaps_zoom ( gdouble mpp ) {
31 for ( i = 0; i < num_scales; i++ ) {
32 if ( ABS(scale_mpps[i] - mpp) < ERROR_MARGIN )
39 class Google:Maps from Vik:Map:Type {
40 override (Vik:Map:Type) void
41 mapcoord_to_center_coord ( Vik:Map:Type *self, MapCoord *src, VikCoord *dest )
43 dest->mode = VIK_COORD_LATLON;
44 dest->north_south = 39.5 - (1.0/(131072 >> src->scale) * (src->y+0.5) * 128);
45 dest->east_west = 1.0 / (131072 >> src->scale) * (src->x+0.5) / 0.77162458338772 * 128 - 98.35;
48 override (Vik:Map:Type) gboolean
49 coord_to_mapcoord ( self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
51 g_assert ( src->mode == VIK_COORD_LATLON );
56 dest->scale = googlemaps_zoom ( xzoom );
57 if ( dest->scale == 255 )
60 dest->x = (gint) floor ( floor ((src->east_west + 98.35) * (131072 >> dest->scale) * 0.77162458338772) / 128);
61 dest->y = (gint) floor ( floor ((39.5 - src->north_south) * (131072 >> dest->scale)) / 128);