removing the restrictedMinZoom property, and allow for restricting zoom levels with maxResolution and numZoomLevels. Thanks tschaub for the doc, test and examples improvements. r=tschaub (see #3338)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@12106 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2011-06-18 19:25:46 +00:00
parent 6248cdc94d
commit a9d3b8b72e
8 changed files with 98 additions and 105 deletions

View File

@@ -275,18 +275,6 @@ OpenLayers.Layer = OpenLayers.Class({
*/
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
* {Float}
@@ -474,8 +462,12 @@ OpenLayers.Layer = OpenLayers.Class({
*
* Parameters:
* newOptions - {Object}
* reinitialize - {Boolean} If set to true, and if resolution options of the
* current baseLayer were changed, the map will be recentered to make
* sure that it is displayed with a valid resolution, and a
* changebaselayer event will be triggered.
*/
addOptions: function (newOptions) {
addOptions: function (newOptions, reinitialize) {
if (this.options == null) {
this.options = {};
@@ -502,6 +494,8 @@ OpenLayers.Layer = OpenLayers.Class({
// properties of the "properties" array defined below is set
// in the new options
if(this.map) {
// store current resolution so we can try to restore it later
var resolution = this.map.getResolution();
var properties = this.RESOLUTION_PROPERTIES.concat(
["projection", "units", "minExtent", "maxExtent"]
);
@@ -510,6 +504,20 @@ OpenLayers.Layer = OpenLayers.Class({
OpenLayers.Util.indexOf(properties, o) >= 0) {
this.initResolutions();
if (reinitialize && this.map.baseLayer === this) {
// update map position, and restore previous resolution
this.map.setCenter(this.map.getCenter(),
this.map.getZoomForResolution(resolution),
false, true
);
// trigger a changebaselayer event to make sure that
// all controls (especially
// OpenLayers.Control.PanZoomBar) get notified of the
// new options
this.map.events.triggerEvent("changebaselayer", {
layer: this
});
}
break;
}
}
@@ -763,8 +771,7 @@ OpenLayers.Layer = OpenLayers.Class({
} else {
if (this.map) {
var resolution = this.map.getResolution();
inRange = ( this.map.getZoom() >= this.restrictedMinZoom &&
(resolution >= this.minResolution) &&
inRange = ( (resolution >= this.minResolution) &&
(resolution <= this.maxResolution) );
}
}
@@ -1197,7 +1204,7 @@ OpenLayers.Layer = OpenLayers.Class({
}
zoom = Math.max(0, i-1);
}
return Math.max(this.restrictedMinZoom, zoom);
return zoom;
},
/**