new restrictedMinZoom property. r=bartvde (closes #3024)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11058 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2011-01-24 21:43:35 +00:00
parent 2f7a3e818a
commit a1c80ffb7e
4 changed files with 84 additions and 5 deletions

View File

@@ -275,6 +275,18 @@ OpenLayers.Layer = OpenLayers.Class({
*/ */
numZoomLevels: null, 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 * APIProperty: minScale
* {Float} * {Float}
@@ -740,7 +752,8 @@ OpenLayers.Layer = OpenLayers.Class({
} else { } else {
if (this.map) { if (this.map) {
var resolution = this.map.getResolution(); var resolution = this.map.getResolution();
inRange = ( (resolution >= this.minResolution) && inRange = ( this.map.getZoom() >= this.restrictedMinZoom &&
(resolution >= this.minResolution) &&
(resolution <= this.maxResolution) ); (resolution <= this.maxResolution) );
} }
} }
@@ -1171,7 +1184,7 @@ OpenLayers.Layer = OpenLayers.Class({
} }
zoom = Math.max(0, i-1); zoom = Math.max(0, i-1);
} }
return zoom; return Math.max(this.restrictedMinZoom, zoom);
}, },
/** /**

View File

@@ -1801,7 +1801,7 @@ OpenLayers.Map = OpenLayers.Class({
*/ */
isValidZoomLevel: function(zoomLevel) { isValidZoomLevel: function(zoomLevel) {
return ( (zoomLevel != null) && return ( (zoomLevel != null) &&
(zoomLevel >= 0) && (zoomLevel >= this.getRestrictedMinZoom()) &&
(zoomLevel < this.getNumZoomLevels()) ); (zoomLevel < this.getNumZoomLevels()) );
}, },
@@ -1905,6 +1905,20 @@ OpenLayers.Map = OpenLayers.Class({
return maxExtent; return maxExtent;
}, },
/**
* 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 * APIMethod: getNumZoomLevels
* *

View File

@@ -556,7 +556,7 @@
function test_Layer_getZoomForResolution(t) { function test_Layer_getZoomForResolution(t) {
t.plan(12); t.plan(13);
var layer = new OpenLayers.Layer('Test Layer'); var layer = new OpenLayers.Layer('Test Layer');
layer.map = {}; layer.map = {};
@@ -585,6 +585,9 @@
t.eq(layer.getZoomForResolution(1).toPrecision(6), (layer.resolutions.length - 1).toPrecision(6), t.eq(layer.getZoomForResolution(1).toPrecision(6), (layer.resolutions.length - 1).toPrecision(6),
"(fractionalZoom) doesn't return zoom above highest index"); "(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");
} }
function test_Layer_redraw(t) { function test_Layer_redraw(t) {

View File

@@ -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) { function test_Map_isValidLonLat(t) {
t.plan( 3 ); t.plan( 3 );
@@ -1234,6 +1262,27 @@
t.ok(maxExtent == map.baseLayer.maxExtent, "null options, valid baseLayer returns map.baseLayer.maxExtent"); 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){ function test_Map_zoomToMaxExtent(t){
t.plan(4) t.plan(4)