%headertop{ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "vikcoord.h" #include "mapcoord.h" #include "vik-map-type.h" %} %{ #include #include #include #include #include #include #include #include "coords.h" #include "vikcoord.h" #include "mapcoord.h" #include "download.h" #include "curl_download.h" #include "globals.h" #include "google.h" #include "vikmapslayer.h" %} %h{ typedef enum { TYPE_GOOGLE_MAPS = 0, TYPE_GOOGLE_TRANS, TYPE_GOOGLE_SAT, TYPE_GOOGLE_TERRAIN, TYPE_GOOGLE_NUM } GoogleType; %} %{ static DownloadOptions google_options = { "http://maps.google.com/", 0, a_check_map_file }; /* 1 << (x) is like a 2**(x) */ #define GZ(x) ((1<x, src->y, src->scale ); res = a_http_download_get_url ( "mt.google.com", uri, dest_fn, &google_options ); g_free ( uri ); return res; } %} class Google:Map:Type from Vik:Map:Type { private GoogleType type; init (self) { /* initialize the object here */ self->tilesize_x = 256; self->tilesize_y = 256; self->drawmode = VIK_VIEWPORT_DRAWMODE_MERCATOR; } public GObject * new_with_id (guint8 id) { GObject *ret = GET_NEW; VIK_MAP_TYPE(ret)->uniq_id = id; return G_OBJECT (ret); } public GObject * new (void) { GObject *ret = GET_NEW; return G_OBJECT (ret); } override (Vik:Map:Type) gboolean coord_to_mapcoord ( Vik:Map:Type *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest ) { g_assert ( src->mode == VIK_COORD_LATLON ); if ( xzoom != yzoom ) return FALSE; dest->scale = google_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; } override (Vik:Map:Type) void mapcoord_to_center_coord ( Vik:Map:Type *self, 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)); } override (Vik:Map:Type) int download ( Vik:Map:Type *self, MapCoord *src, const gchar *dest_fn ) { const gchar *vers_str = google_version_number(src, GOOGLE_MAP_TYPE(self)->_priv->type); return(real_google_download ( src, dest_fn, vers_str )); } }