X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/8c0604067586d37324e75ee2939038ecde370fa1..59de083b4da4c6babb5b86e8362cbd490b102c04:/src/google.c diff --git a/src/google.c b/src/google.c index ec61c8ba..062a6e08 100644 --- a/src/google.c +++ b/src/google.c @@ -36,28 +36,25 @@ #include "curl_download.h" #include "globals.h" #include "google.h" +#include "google-map-type.h" #include "vikmapslayer.h" -static int google_download ( MapCoord *src, const gchar *dest_fn ); -static int google_trans_download ( MapCoord *src, const gchar *dest_fn ); -static int google_terrain_download ( MapCoord *src, const gchar *dest_fn ); static int google_kh_download ( MapCoord *src, const gchar *dest_fn ); static void google_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest ); -static gboolean google_coord_to_mapcoord ( const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest ); -static DownloadOptions google_options = { "http://maps.google.com/", 0 }; +static DownloadOptions google_options = { "http://maps.google.com/", 0, a_check_map_file }; void google_init () { - VikMapsLayer_MapType google_1 = { 7, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_download }; - VikMapsLayer_MapType google_2 = { 10, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_trans_download }; - VikMapsLayer_MapType google_3 = { 11, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_kh_download }; - VikMapsLayer_MapType google_4 = { 16, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_terrain_download }; - - maps_layer_register_type(_("Google Maps"), 7, &google_1); - maps_layer_register_type(_("Transparent Google Maps"), 10, &google_2); - maps_layer_register_type(_("Google Satellite Images"), 11, &google_3); - maps_layer_register_type(_("Google Terrain Maps"), 16, &google_4); + VikMapType *google_1 = VIK_MAP_TYPE(google_map_type_new_with_id(7, TYPE_GOOGLE_MAPS)); + VikMapType *google_2 = VIK_MAP_TYPE(google_map_type_new_with_id(10, TYPE_GOOGLE_TRANS)); + VikMapType *google_3 = VIK_MAP_TYPE(google_map_type_new_with_id(11, TYPE_GOOGLE_SAT)); + VikMapType *google_4 = VIK_MAP_TYPE(google_map_type_new_with_id(16, TYPE_GOOGLE_TERRAIN)); + + maps_layer_register_type(_("Google Maps"), 7, google_1); + maps_layer_register_type(_("Transparent Google Maps"), 10, google_2); + maps_layer_register_type(_("Google Satellite Images"), 11, google_3); + maps_layer_register_type(_("Google Terrain Maps"), 16, google_4); } /* 1 << (x) is like a 2**(x) */ @@ -69,7 +66,7 @@ static const gdouble scale_mpps[] = { GZ(0), GZ(1), GZ(2), GZ(3), GZ(4), GZ(5), static const gint num_scales = (sizeof(scale_mpps) / sizeof(scale_mpps[0])); #define ERROR_MARGIN 0.01 -guint8 google_zoom ( gdouble mpp ) { +static guint8 google_zoom ( gdouble mpp ) { gint i; for ( i = 0; i < num_scales; i++ ) { if ( ABS(scale_mpps[i] - mpp) < ERROR_MARGIN ) @@ -78,15 +75,6 @@ guint8 google_zoom ( gdouble mpp ) { return 255; } -typedef enum { - TYPE_GOOGLE_MAPS = 0, - TYPE_GOOGLE_TRANS, - TYPE_GOOGLE_SAT, - TYPE_GOOGLE_TERRAIN, - - TYPE_GOOGLE_NUM -} GoogleType; - static gchar *parse_version_number(gchar *text) { int i; @@ -105,19 +93,21 @@ static gchar *parse_version_number(gchar *text) static const gchar *google_version_number(MapCoord *mapcoord, GoogleType google_type) { static gboolean first = TRUE; - static char *vers[] = { "w2.60", "w2t.60", "20", "w2p.60" }; + static char *vers[] = { "w2.80", "w2t.80", "30", "w2p.81"}; FILE *tmp_file; int tmp_fd; gchar *tmpname; gchar *uri; VikCoord coord; + gchar coord_north_south[G_ASCII_DTOSTR_BUF_SIZE], coord_east_west[G_ASCII_DTOSTR_BUF_SIZE]; gchar *text, *pat, *beg; GMappedFile *mf; gsize len; gchar *gvers, *tvers, *kvers, *terrvers, *tmpvers; - static DownloadOptions dl_options = { "http://maps.google.com/", 0 }; - static const char *gvers_pat = "http://mt0.google.com/mt?n\\x3d404\\x26v\\x3d"; - static const char *kvers_pat = "http://kh0.google.com/kh?n\\x3d404\\x26v\\x3d"; + static DownloadOptions dl_options = { "http://maps.google.com/", 0, a_check_map_file }; + /* static const char *gvers_pat = "http://mt0.google.com/mt?v\\x3d"; */ + static const char *gvers_pat = "http://mt0.google.com/mt"; + static const char *kvers_pat = "http://khm0.google.com/kh?v\\x3d"; g_assert(google_type < TYPE_GOOGLE_NUM); @@ -133,7 +123,9 @@ static const gchar *google_version_number(MapCoord *mapcoord, GoogleType google_ } google_mapcoord_to_center_coord(mapcoord, &coord); - uri = g_strdup_printf("http://maps.google.com/maps?f=q&hl=en&q=%f,%f", coord.north_south, coord.east_west); + uri = g_strdup_printf("http://maps.google.com/maps?f=q&hl=en&q=%s,%s", + g_ascii_dtostr (coord_north_south, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) coord.north_south), + g_ascii_dtostr (coord_east_west, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) coord.east_west)); tmp_file = fdopen(tmp_fd, "r+"); if (curl_download_uri(uri, tmp_file, &dl_options)) { /* error */ @@ -155,6 +147,11 @@ static const gchar *google_version_number(MapCoord *mapcoord, GoogleType google_ while (!gvers || !tvers ||!terrvers) { if ((pat = g_strstr_len(pat, &text[len] - pat, gvers_pat)) != NULL) { pat += strlen(gvers_pat); + if ((pat[0] != '/' && pat[0] != '?') || + pat[1] != 'v' || pat[2] != '\\' || + pat[3] != 'x' || pat[4] != '3' || pat[5] != 'd') + continue; + pat += 6; if ((tmpvers = parse_version_number(pat)) != NULL) { if (strstr(tmpvers, "t.")) tvers = tmpvers; @@ -218,7 +215,7 @@ gboolean google_coord_to_mapcoord ( const VikCoord *src, gdouble xzoom, gdouble return TRUE; } -void google_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest ) +static void google_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest ) { gdouble socalled_mpp = GZ(src->scale); dest->mode = VIK_COORD_LATLON; @@ -226,33 +223,6 @@ void google_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest ) dest->north_south = DEMERCLAT(180 - ((src->y+0.5) / GZ(17) * socalled_mpp * 360)); } -static int real_google_download ( MapCoord *src, const gchar *dest_fn, const char *verstr ) -{ - int res; - gchar *uri = g_strdup_printf ( "/mt?n=404&v=%s&x=%d&y=%d&zoom=%d", verstr, src->x, src->y, src->scale ); - res = a_http_download_get_url ( "mt.google.com", uri, dest_fn, &google_options ); - g_free ( uri ); - return res; -} - -static int google_download ( MapCoord *src, const gchar *dest_fn ) -{ - const gchar *vers_str = google_version_number(src, TYPE_GOOGLE_MAPS); - return(real_google_download ( src, dest_fn, vers_str )); -} - -static int google_trans_download ( MapCoord *src, const gchar *dest_fn ) -{ - const gchar *vers_str = google_version_number(src, TYPE_GOOGLE_TRANS); - return(real_google_download ( src, dest_fn, vers_str )); -} - -static int google_terrain_download ( MapCoord *src, const gchar *dest_fn ) -{ - const gchar *vers_str = google_version_number(src, TYPE_GOOGLE_TERRAIN); - return(real_google_download ( src, dest_fn, vers_str )); -} - static char *kh_encode(guint32 x, guint32 y, guint8 scale) { gchar *buf = g_malloc ( (20-scale)*sizeof(gchar) ); @@ -301,7 +271,7 @@ static int google_kh_download ( MapCoord *src, const gchar *dest_fn ) const gchar *vers_str = google_version_number(src, TYPE_GOOGLE_SAT); gchar *uri = g_strdup_printf ( "/kh?n=404&v=%s&t=%s", vers_str, khenc ); g_free ( khenc ); - res = a_http_download_get_url ( "kh.google.com", uri, dest_fn, &google_options ); + res = a_http_download_get_url ( "khm.google.com", uri, dest_fn, &google_options ); g_free ( uri ); return(res); }