X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/f40fb47d1dfb8e75b1a679ab2cc06980bbc8e647..ccab0e9e7869f120d20bd41bac6043b37c88b2ec:/src/google.c diff --git a/src/google.c b/src/google.c index d1c4e41f..c7e7ecc2 100644 --- a/src/google.c +++ b/src/google.c @@ -22,290 +22,64 @@ #include "config.h" #endif -#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 "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, a_check_map_file }; +#include "vikexttools.h" +#include "vikwebtoolcenter.h" +#include "vikgoto.h" +#include "googlesearch.h" +#include "vikrouting.h" +#include "vikroutingwebengine.h" +#include "babel.h" void google_init () { - VikMapType *google_1 = VIK_MAP_TYPE(google_map_type_new_with_id(7)); - VikMapType *google_2 = VIK_MAP_TYPE(google_map_type_new_with_id(10)); - //{ 10, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_trans_download }; - VikMapType *google_3 = VIK_MAP_TYPE(google_map_type_new_with_id(11)); - //{ 11, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_kh_download }; - VikMapType *google_4 = VIK_MAP_TYPE(google_map_type_new_with_id(16)); - //{ 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); -} - -/* 1 << (x) is like a 2**(x) */ -#define GZ(x) ((1<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; -} - -void google_mapcoord_to_center_coord ( 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)); -} - -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 )); + // Webtools + VikWebtoolCenter *webtool = vik_webtool_center_new_with_members ( _("Google"), "http://maps.google.com/maps/@%s,%s,%dz" ); + vik_ext_tools_register ( VIK_EXT_TOOL ( webtool ) ); + g_object_unref ( webtool ); + + // Goto + /* + * Google no longer supports the API we used + * + GoogleGotoTool *gototool = google_goto_tool_new ( ); + vik_goto_register ( VIK_GOTO_TOOL ( gototool ) ); + g_object_unref ( gototool ); + */ } -static char *kh_encode(guint32 x, guint32 y, guint8 scale) +/** + * Delayed initialization part as the check for gpsbabel availability needs to have been performed + */ +void google_post_init () { - gchar *buf = g_malloc ( (20-scale)*sizeof(gchar) ); - guint32 ya = 1 << (17 - scale); - gint8 i, j; - - if (y < 0 || (ya-1 < y)) { - strcpy(buf,"tqq"); /* BAD */ - return buf; - } - if (x < 0 || ya-1 < x) { - x %= ya; - if (x < 0) - x += ya; - } - - buf[0] = 't'; - for (j = 1, i = 16; i >= scale; i--, j++) { - ya /= 2; - if (y < ya) { - if (x < ya) - buf[j]='q'; - else { - buf[j]='r'; - x -= ya; - } - } else { - if (x < ya) { - buf[j] = 't'; - y -= ya; - } else { - buf[j] = 's'; - x -= ya; - y -= ya; - } - } + // Routing + /* Google Directions service as routing engine. + * + * Technical details are available here: + * https://developers.google.com/maps/documentation/directions/#DirectionsResponses + * + * gpsbabel supports this format. + */ + /* + * Google no longer supports the API we used + * + if ( a_babel_available() ) { + VikRoutingEngine *routing = g_object_new ( VIK_ROUTING_WEB_ENGINE_TYPE, + "id", "google", + "label", "Google", + "format", "google", + "url-base", "http://maps.google.com/maps?output=js&q=", + "url-start-ll", "from:%s,%s", + "url-stop-ll", "+to:%s,%s", + "url-start-dir", "from:%s", + "url-stop-dir", "+to:%s", + "referer", "http://maps.google.com/", + NULL); + vik_routing_register ( VIK_ROUTING_ENGINE ( routing ) ); + g_object_unref ( routing ); } - buf[j] = '\0'; - return buf; -} - -static int google_kh_download ( MapCoord *src, const gchar *dest_fn ) -{ - int res; - gchar *khenc = kh_encode( src->x, src->y, src->scale ); - 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 ( "khm.google.com", uri, dest_fn, &google_options ); - g_free ( uri ); - return(res); + */ }