]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikwmscmapsource.c
[QA] Improve create zoom menu to use G_N_ELEMENTS to know array bounds.
[andy/viking.git] / src / vikwmscmapsource.c
index 8dd74fe5a64f6a6510795ba043c7db245d056da0..5b760312b0ba873913af4b7a66f98a40be4c717b 100644 (file)
  */
  
  /**
+  * SECTION:vikwmscmapsource
+  * @short_description: the class for WMS/WMS-C oriented map sources
+  * 
+  * The #VikWmscMapSource class handles WMS/WMS-C oriented map sources.
+  * 
   * http://wiki.osgeo.org/wiki/WMS_Tile_Caching
   */
  
 
 #include "globals.h"
 #include "vikwmscmapsource.h"
+#include "maputils.h"
 
 static gboolean _coord_to_mapcoord ( VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest );
 static void _mapcoord_to_center_coord ( VikMapSource *self, MapCoord *src, VikCoord *dest );
-static gboolean _supports_download_only_new (VikMapSource *self );
+static gboolean _supports_download_only_new ( VikMapSource *self );
+static gboolean _is_direct_file_access ( VikMapSource *self );
 
 static gchar *_get_uri( VikMapSourceDefault *self, MapCoord *src );
 static gchar *_get_hostname( VikMapSourceDefault *self );
@@ -194,6 +201,7 @@ vik_wmsc_map_source_class_init (VikWmscMapSourceClass *klass)
        grandparent_class->coord_to_mapcoord =        _coord_to_mapcoord;
        grandparent_class->mapcoord_to_center_coord = _mapcoord_to_center_coord;
        grandparent_class->supports_download_only_new = _supports_download_only_new;
+       grandparent_class->is_direct_file_access = _is_direct_file_access;
        
        parent_class->get_uri = _get_uri;
        parent_class->get_hostname = _get_hostname;
@@ -241,36 +249,8 @@ vik_wmsc_map_source_class_init (VikWmscMapSourceClass *klass)
        object_class->finalize = vik_wmsc_map_source_finalize;
 }
 
-/* 1 << (x) is like a 2**(x) */
-#define GZ(x) ((1<<x))
-
-static const gdouble scale_mpps[] = { GZ(0), GZ(1), GZ(2), GZ(3), GZ(4), GZ(5), GZ(6), GZ(7), GZ(8), GZ(9),
-                                           GZ(10), GZ(11), GZ(12), GZ(13), GZ(14), GZ(15), GZ(16), GZ(17) };
-
-static const gint num_scales = (sizeof(scale_mpps) / sizeof(scale_mpps[0]));
-
-static const gdouble scale_neg_mpps[] = { 1.0/GZ(0), 1.0/GZ(1), 1.0/GZ(2), 1.0/GZ(3) };
-static const gint num_scales_neg = (sizeof(scale_neg_mpps) / sizeof(scale_neg_mpps[0]));
-
-#define ERROR_MARGIN 0.01
-static gint wmsc_zoom ( gdouble mpp ) {
-  gint i;
-  for ( i = 0; i < num_scales; i++ ) {
-    if ( ABS(scale_mpps[i] - mpp) < ERROR_MARGIN ) {
-      return i;
-    }
-  }
-  for ( i = 0; i < num_scales_neg; i++ ) {
-    if ( ABS(scale_neg_mpps[i] - mpp) < 0.000001 ) {
-      return -i;
-    }
-  }
-
-  return 255;
-}
-
-gboolean
-_supports_download_only_new (VikMapSource *self)
+static gboolean
+_supports_download_only_new ( VikMapSource *self )
 {
        g_return_val_if_fail (VIK_IS_WMSC_MAP_SOURCE(self), FALSE);
        
@@ -279,6 +259,12 @@ _supports_download_only_new (VikMapSource *self)
        return priv->options.check_file_server_time;
 }
 
+static gboolean
+_is_direct_file_access ( VikMapSource *self )
+{
+       return FALSE;
+}
+
 static gboolean
 _coord_to_mapcoord ( VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
 {
@@ -287,18 +273,18 @@ _coord_to_mapcoord ( VikMapSource *self, const VikCoord *src, gdouble xzoom, gdo
   if ( xzoom != yzoom )
     return FALSE;
 
-  dest->scale = wmsc_zoom ( xzoom );
+  dest->scale = map_utils_mpp_to_scale ( xzoom );
   if ( dest->scale == 255 )
     return FALSE;
 
-  /* Note : GZ(17) / xzoom / 2 = number of tile on Y axis */
+  /* Note : VIK_GZ(17) / xzoom / 2 = number of tile on Y axis */
   g_debug("%s: xzoom=%f yzoom=%f -> %f", __FUNCTION__,
-          xzoom, yzoom, GZ(17) / xzoom / 2);
-  dest->x = floor((src->east_west + 180) / 180 * GZ(17) / xzoom / 2);
+          xzoom, yzoom, VIK_GZ(17) / xzoom / 2);
+  dest->x = floor((src->east_west + 180) / 180 * VIK_GZ(17) / xzoom / 2);
   /* We should restore logic of viking:
    * tile index on Y axis follow a screen logic (top -> down)
    */
-  dest->y = floor((180 - (src->north_south + 90)) / 180 * GZ(17) / xzoom / 2);
+  dest->y = floor((180 - (src->north_south + 90)) / 180 * VIK_GZ(17) / xzoom / 2);
   dest->z = 0;
   g_debug("%s: %f,%f -> %d,%d", __FUNCTION__,
           src->east_west, src->north_south, dest->x, dest->y);
@@ -310,15 +296,15 @@ _mapcoord_to_center_coord ( VikMapSource *self, MapCoord *src, VikCoord *dest )
 {
   gdouble socalled_mpp;
   if (src->scale >= 0)
-    socalled_mpp = GZ(src->scale);
+    socalled_mpp = VIK_GZ(src->scale);
   else
-    socalled_mpp = 1.0/GZ(-src->scale);
+    socalled_mpp = 1.0/VIK_GZ(-src->scale);
   dest->mode = VIK_COORD_LATLON;
-  dest->east_west = (src->x+0.5) * 180 / GZ(17) * socalled_mpp * 2 - 180;
+  dest->east_west = (src->x+0.5) * 180 / VIK_GZ(17) * socalled_mpp * 2 - 180;
   /* We should restore logic of viking:
    * tile index on Y axis follow a screen logic (top -> down)
    */
-  dest->north_south = -((src->y+0.5) * 180 / GZ(17) * socalled_mpp * 2 - 90);
+  dest->north_south = -((src->y+0.5) * 180 / VIK_GZ(17) * socalled_mpp * 2 - 90);
   g_debug("%s: %d,%d -> %f,%f", __FUNCTION__,
           src->x, src->y, dest->east_west, dest->north_south);
 }
@@ -331,16 +317,16 @@ _get_uri( VikMapSourceDefault *self, MapCoord *src )
     VikWmscMapSourcePrivate *priv = VIK_WMSC_MAP_SOURCE_PRIVATE(self);
        gdouble socalled_mpp;
        if (src->scale >= 0)
-               socalled_mpp = GZ(src->scale);
+               socalled_mpp = VIK_GZ(src->scale);
        else
-               socalled_mpp = 1.0/GZ(-src->scale);
-       gdouble minx = (gdouble)src->x * 180 / GZ(17) * socalled_mpp * 2 - 180;
-       gdouble maxx = (gdouble)(src->x + 1) * 180 / GZ(17) * socalled_mpp * 2 - 180;
+               socalled_mpp = 1.0/VIK_GZ(-src->scale);
+       gdouble minx = (gdouble)src->x * 180 / VIK_GZ(17) * socalled_mpp * 2 - 180;
+       gdouble maxx = (gdouble)(src->x + 1) * 180 / VIK_GZ(17) * socalled_mpp * 2 - 180;
        /* We should restore logic of viking:
      * tile index on Y axis follow a screen logic (top -> down)
      */
-       gdouble miny = -((gdouble)(src->y + 1) * 180 / GZ(17) * socalled_mpp * 2 - 90);
-       gdouble maxy = -((gdouble)(src->y) * 180 / GZ(17) * socalled_mpp * 2 - 90);
+       gdouble miny = -((gdouble)(src->y + 1) * 180 / VIK_GZ(17) * socalled_mpp * 2 - 90);
+       gdouble maxy = -((gdouble)(src->y) * 180 / VIK_GZ(17) * socalled_mpp * 2 - 90);
        
        gchar sminx[G_ASCII_DTOSTR_BUF_SIZE];
        gchar smaxx[G_ASCII_DTOSTR_BUF_SIZE];