X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/b291388aea60f9c8b5501550e8668266ba621ab5..59de083b4da4c6babb5b86e8362cbd490b102c04:/src/google.c diff --git a/src/google.c b/src/google.c index c4375434..062a6e08 100644 --- a/src/google.c +++ b/src/google.c @@ -18,16 +18,44 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#include +#include #include #include #include #include "coords.h" #include "vikcoord.h" #include "mapcoord.h" -#include "http.h" +#include "download.h" +#include "curl_download.h" #include "globals.h" #include "google.h" +#include "google-map-type.h" +#include "vikmapslayer.h" + + +static int google_kh_download ( MapCoord *src, const gchar *dest_fn ); +static void google_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest ); + +static DownloadOptions google_options = { "http://maps.google.com/", 0, a_check_map_file }; + +void google_init () { + 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) */ #define GZ(x) ((1<mode == VIK_COORD_LATLON ); @@ -65,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; @@ -73,23 +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 void real_google_download ( MapCoord *src, const gchar *dest_fn, const char *verstr ) -{ - gchar *uri = g_strdup_printf ( "/mt?v=%s&x=%d&y=%d&zoom=%d", verstr, src->x, src->y, src->scale ); - a_http_download_get_url ( "mt.google.com", uri, dest_fn ); - g_free ( uri ); -} - -void google_download ( MapCoord *src, const gchar *dest_fn ) -{ - real_google_download ( src, dest_fn, "w2.35" ); -} - -void google_trans_download ( MapCoord *src, const gchar *dest_fn ) -{ - real_google_download ( src, dest_fn, "w2t.1" ); -} - static char *kh_encode(guint32 x, guint32 y, guint8 scale) { gchar *buf = g_malloc ( (20-scale)*sizeof(gchar) ); @@ -131,11 +264,14 @@ static char *kh_encode(guint32 x, guint32 y, guint8 scale) return buf; } -void google_kh_download ( MapCoord *src, const gchar *dest_fn ) +static int google_kh_download ( MapCoord *src, const gchar *dest_fn ) { + int res; gchar *khenc = kh_encode( src->x, src->y, src->scale ); - gchar *uri = g_strdup_printf ( "/kh?v=3&t=%s", khenc ); + 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 ); - a_http_download_get_url ( "kh.google.com", uri, dest_fn ); + res = a_http_download_get_url ( "khm.google.com", uri, dest_fn, &google_options ); g_free ( uri ); + return(res); }