[OpenLayers-Commits] r11058 - in trunk/openlayers: lib/OpenLayers tests

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Mon Jan 24 16:43:35 EST 2011


Author: ahocevar
Date: 2011-01-24 13:43:35 -0800 (Mon, 24 Jan 2011)
New Revision: 11058

Modified:
   trunk/openlayers/lib/OpenLayers/Layer.js
   trunk/openlayers/lib/OpenLayers/Map.js
   trunk/openlayers/tests/Layer.html
   trunk/openlayers/tests/Map.html
Log:
new restrictedMinZoom property. r=bartvde (closes #3024)

Modified: trunk/openlayers/lib/OpenLayers/Layer.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer.js	2011-01-24 12:43:53 UTC (rev 11057)
+++ trunk/openlayers/lib/OpenLayers/Layer.js	2011-01-24 21:43:35 UTC (rev 11058)
@@ -274,6 +274,18 @@
      * {Integer}
      */
     numZoomLevels: null,
+    
+    /**
+     * Property: restrictedMinZoom
+     * {Integer} Restriction of the minimum zoom level. This is used for layers
+     *     that only use a subset of the resolutions in the <resolutions>
+     *     array. This is independent of <numResolutions>, which always starts
+     *     counting at zoom level 0. If restrictedMinZoom is e.g. set to 2,
+     *     the first two zoom levels (0 and 1) will not be used by this layer.
+     *     If the layer is a base layer, zooming to the map's maxExtent means
+     *     setting the map's zoom to 2.
+     */
+    restrictedMinZoom: 0,
    
     /**
      * APIProperty: minScale
@@ -740,7 +752,8 @@
         } else {
             if (this.map) {
                 var resolution = this.map.getResolution();
-                inRange = ( (resolution >= this.minResolution) &&
+                inRange = ( this.map.getZoom() >= this.restrictedMinZoom &&
+                            (resolution >= this.minResolution) &&
                             (resolution <= this.maxResolution) );
             }
         }
@@ -1171,7 +1184,7 @@
             }
             zoom = Math.max(0, i-1);
         }
-        return zoom;
+        return Math.max(this.restrictedMinZoom, zoom);
     },
     
     /**

Modified: trunk/openlayers/lib/OpenLayers/Map.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Map.js	2011-01-24 12:43:53 UTC (rev 11057)
+++ trunk/openlayers/lib/OpenLayers/Map.js	2011-01-24 21:43:35 UTC (rev 11058)
@@ -1800,8 +1800,8 @@
      *           within the min/max range of zoom levels.
      */
     isValidZoomLevel: function(zoomLevel) {
-       return ( (zoomLevel != null) &&
-                (zoomLevel >= 0) && 
+        return ( (zoomLevel != null) &&
+                (zoomLevel >= this.getRestrictedMinZoom()) && 
                 (zoomLevel < this.getNumZoomLevels()) );
     },
     
@@ -1906,6 +1906,20 @@
     },
     
     /**
+     * Method: getRestricteMinZoom
+     *
+     * Returns:
+     * {Integer} the minimum zoom level allowed for the current baseLayer.
+     */
+    getRestrictedMinZoom: function() {
+        var minZoom = null;
+        if (this.baseLayer != null) {
+            minZoom = this.baseLayer.restrictedMinZoom;
+        }
+        return minZoom;
+    },
+    
+    /**
      * APIMethod: getNumZoomLevels
      * 
      * Returns:

Modified: trunk/openlayers/tests/Layer.html
===================================================================
--- trunk/openlayers/tests/Layer.html	2011-01-24 12:43:53 UTC (rev 11057)
+++ trunk/openlayers/tests/Layer.html	2011-01-24 21:43:35 UTC (rev 11058)
@@ -556,7 +556,7 @@
 
     function test_Layer_getZoomForResolution(t) {
 
-        t.plan(12);
+        t.plan(13);
 
         var layer = new OpenLayers.Layer('Test Layer');
         layer.map = {};
@@ -584,6 +584,9 @@
              "(fractionalZoom) doesn't return zoom below zero");
         t.eq(layer.getZoomForResolution(1).toPrecision(6), (layer.resolutions.length - 1).toPrecision(6),
              "(fractionalZoom) doesn't return zoom above highest index");
+        
+        layer.restrictedMinZoom = 1;
+        t.eq(layer.getZoomForResolution(200), 1, "zoom all the way out, but we have a restrictedMinZoom of 1");
 
     }
     

Modified: trunk/openlayers/tests/Map.html
===================================================================
--- trunk/openlayers/tests/Map.html	2011-01-24 12:43:53 UTC (rev 11057)
+++ trunk/openlayers/tests/Map.html	2011-01-24 21:43:35 UTC (rev 11058)
@@ -326,6 +326,34 @@
     }
  */
 
+    function test_Map_isValidZoomLevel(t) {
+        t.plan(6);
+        var map = new OpenLayers.Map("map");
+        map.addLayer(new OpenLayers.Layer(null, {
+            isBaseLayer: true, numZoomLevels: 19
+        }))
+        var valid;
+
+        valid = OpenLayers.Map.prototype.isValidZoomLevel.apply(map, [0]);
+        t.eq(valid, true, "0 is a valid zoomLevel when baseLayer has no restrictedMinZoom");
+
+        valid = OpenLayers.Map.prototype.isValidZoomLevel.apply(map, [18]);
+        t.eq(valid, true, "18 is a valid zoomLevel");
+
+        valid = OpenLayers.Map.prototype.isValidZoomLevel.apply(map, [19]);
+        t.eq(valid, false, "19 is not a valid zoomLevel");
+        
+        map.baseLayer.restrictedMinZoom = 1;
+        valid = OpenLayers.Map.prototype.isValidZoomLevel.apply(map, [0]);
+        t.eq(valid, false, "0 is not a valid zoomLevel when baseLayer has restrictedMinZoom of 1");
+
+        valid = OpenLayers.Map.prototype.isValidZoomLevel.apply(map, [1]);
+        t.eq(valid, true, "1 is a valid zoomLevel");
+
+        valid = OpenLayers.Map.prototype.isValidZoomLevel.apply(map, [19]);
+        t.eq(valid, false, "19 is not a valid zoomLevel when baseLayer has restrictedMinZoom of 1");
+    }
+    
     function test_Map_isValidLonLat(t) {
         t.plan( 3 );    
 
@@ -1234,6 +1262,27 @@
         t.ok(maxExtent == map.baseLayer.maxExtent, "null options, valid baseLayer returns map.baseLayer.maxExtent");     
     }
 
+    function test_Map_getRestrictedMinZoom(t){
+        t.plan(3);
+
+        var map = {};
+
+      //no baseLayer
+        var minZoom = OpenLayers.Map.prototype.getRestrictedMinZoom.apply(map);
+        t.eq(minZoom, null, "no baseLayer returns null");
+        
+        map.baseLayer = new OpenLayers.Layer(null, {isBaseLayer: true});
+
+      //baseLayer
+        minZoom = OpenLayers.Map.prototype.getRestrictedMinZoom.apply(map);
+        t.eq(minZoom, 0, "default baseLayer.restrictedMinZoom returns 0");     
+
+      //custom minZoomLevel on baseLayer
+        map.baseLayer.restrictedMinZoom = 1;
+        minZoom = OpenLayers.Map.prototype.getRestrictedMinZoom.apply(map);
+        t.eq(minZoom, map.baseLayer.restrictedMinZoom, "custom baseLayer.restrictedMinZoom returns map.baseLayer.restrictedMinZoom");     
+    }
+    
     function test_Map_zoomToMaxExtent(t){
         t.plan(4)
 



More information about the Commits mailing list