]> 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 bf3d84d7ca93024ee5a22a94c2ac4b365be3354c..33f9059e430f12a18b93f3705a055d39b725ee35 100644 (file)
@@ -38,6 +38,8 @@ typedef enum {
        TYPE_GOOGLE_NUM
 } GoogleType;
 
+const gchar *google_version_number(MapCoord *mapcoord, GoogleType google_type);
+
 %}
 
 %{
@@ -53,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
-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 )
@@ -62,6 +64,13 @@ guint8 google_zoom ( gdouble mpp ) {
   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)
 {
@@ -78,7 +87,7 @@ static gchar *parse_version_number(gchar *text)
   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"};
@@ -185,15 +194,6 @@ failed:
   return (vers[google_type]);
 }
 
-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;
-}
-
 %}
 
 class Google:Map:Type from Vik:Map:Type {
@@ -201,22 +201,31 @@ class Google:Map:Type from Vik:Map:Type {
 
   init (self) {
           /* initialize the object here */
-          self->tilesize_x = 256;
-          self->tilesize_y = 256;
-          self->drawmode = VIK_VIEWPORT_DRAWMODE_MERCATOR;
+          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) {
-         GObject *ret = GET_NEW;
+  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);
   }
 
-  public GObject *
-  new (void) {
-         GObject *ret = GET_NEW;
-         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
@@ -250,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 )
   {
-     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