]> git.street.me.uk Git - andy/viking.git/blobdiff - src/google-map-type.gob
Add Google Kh map type
[andy/viking.git] / src / google-map-type.gob
index a5cff3384eccae4a76bdbd19e5c77386984284a1..33f9059e430f12a18b93f3705a055d39b725ee35 100644 (file)
@@ -38,10 +38,14 @@ typedef enum {
        TYPE_GOOGLE_NUM
 } GoogleType;
 
        TYPE_GOOGLE_NUM
 } GoogleType;
 
+const gchar *google_version_number(MapCoord *mapcoord, GoogleType google_type);
+
 %}
 
 %{
 
 %}
 
 %{
 
+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))
 
 /* 1 << (x) is like a 2**(x) */
 #define GZ(x) ((1<<x))
 
@@ -51,7 +55,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
 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 )
   gint i;
   for ( i = 0; i < num_scales; i++ ) {
     if ( ABS(scale_mpps[i] - mpp) < ERROR_MARGIN )
@@ -60,6 +64,13 @@ guint8 google_zoom ( gdouble mpp ) {
   return 255;
 }
 
   return 255;
 }
 
+static 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 gchar *parse_version_number(gchar *text)
 {
 
 static gchar *parse_version_number(gchar *text)
 {
@@ -76,7 +87,7 @@ static gchar *parse_version_number(gchar *text)
   return vers = g_strndup(s, i);
 }
 
   return vers = g_strndup(s, i);
 }
 
-static const gchar *google_version_number(MapCoord *mapcoord, GoogleType google_type)
+const gchar *google_version_number(MapCoord *mapcoord, GoogleType google_type)
 {
   static gboolean first = TRUE;
   static char *vers[] = { "w2.80", "w2t.80", "30", "w2p.81"};
 {
   static gboolean first = TRUE;
   static char *vers[] = { "w2.80", "w2t.80", "30", "w2p.81"};
@@ -188,6 +199,35 @@ failed:
 class Google:Map:Type from Vik:Map:Type {
   private GoogleType type;
 
 class Google:Map:Type from Vik:Map:Type {
   private GoogleType type;
 
+  init (self) {
+          /* initialize the object here */
+          VIK_MAP_TYPE(self)->tilesize_x = 256;
+          VIK_MAP_TYPE(self)->tilesize_y = 256;
+          VIK_MAP_TYPE(self)->drawmode = VIK_VIEWPORT_DRAWMODE_MERCATOR;
+  }
+
+  public GObject *
+  new_with_id (guint8 id, GoogleType type) {
+         GoogleMapType *ret = GET_NEW;
+         VIK_MAP_TYPE(ret)->uniq_id = id;
+         ret->_priv->type = type;
+         return G_OBJECT (ret);
+  }
+
+  virtual gchar *
+  get_uri( self, MapCoord *src )
+  {
+     const gchar *verstr = google_version_number(src, GOOGLE_MAP_TYPE(self)->_priv->type);
+     gchar *uri = g_strdup_printf ( "/mt?n=404&v=%s&x=%d&y=%d&zoom=%d", verstr, src->x, src->y, src->scale );
+     return uri;
+  }
+
+  virtual gchar *
+  get_hostname( self )
+  {
+    return g_strdup("mt.google.com");
+  }
+
   override (Vik:Map:Type) gboolean
   coord_to_mapcoord ( Vik:Map:Type *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
   {
   override (Vik:Map:Type) gboolean
   coord_to_mapcoord ( Vik:Map:Type *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
   {
@@ -219,7 +259,12 @@ class Google:Map:Type from Vik:Map:Type {
   override (Vik:Map:Type) int
    download ( Vik:Map:Type *self, MapCoord *src, const gchar *dest_fn )
   {
   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 ));
+   int res;
+   gchar *uri = google_map_type_get_uri(GOOGLE_MAP_TYPE(self), src);
+   gchar *host = google_map_type_get_hostname(GOOGLE_MAP_TYPE(self));
+   res = a_http_download_get_url ( host, uri, dest_fn, &google_options );
+   g_free ( uri );
+   g_free ( host );
+   return res;
   }
 }
\ No newline at end of file
   }
 }
\ No newline at end of file