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:
+23
-16
@@ -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;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,6 +21,21 @@
|
||||
*/
|
||||
OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
||||
|
||||
/**
|
||||
* Property: serverResolutions
|
||||
* {Array} the resolutions provided by the Bing servers.
|
||||
*/
|
||||
serverResolutions: [
|
||||
156543.03390625, 78271.516953125, 39135.7584765625,
|
||||
19567.87923828125, 9783.939619140625, 4891.9698095703125,
|
||||
2445.9849047851562, 1222.9924523925781, 611.4962261962891,
|
||||
305.74811309814453, 152.87405654907226, 76.43702827453613,
|
||||
38.218514137268066, 19.109257068634033, 9.554628534317017,
|
||||
4.777314267158508, 2.388657133579254, 1.194328566789627,
|
||||
0.5971642833948135, 0.29858214169740677, 0.14929107084870338,
|
||||
0.07464553542435169
|
||||
],
|
||||
|
||||
/**
|
||||
* Property: attributionTemplate
|
||||
* {String}
|
||||
@@ -80,7 +95,6 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
||||
*/
|
||||
initialize: function(options) {
|
||||
options = OpenLayers.Util.applyDefaults({
|
||||
restrictedMinZoom: 1,
|
||||
sphericalMercator: true
|
||||
}, options);
|
||||
var name = options.name || "Bing " + (options.type || this.type);
|
||||
@@ -127,12 +141,14 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
||||
this.url.push(url.replace("{subdomain}", res.imageUrlSubdomains[i]));
|
||||
};
|
||||
this.addOptions({
|
||||
restrictedMinZoom: res.zoomMin,
|
||||
numZoomLevels: res.zoomMax + 1
|
||||
});
|
||||
this.updateAttribution();
|
||||
// redraw to replace "blank.gif" tiles with real tiles
|
||||
this.redraw();
|
||||
maxResolution: Math.min(
|
||||
this.serverResolutions[res.zoomMin], this.maxResolution
|
||||
),
|
||||
zoomOffset: res.zoomMin,
|
||||
numZoomLevels: Math.min(
|
||||
res.zoomMax + 1 - res.zoomMin, this.numZoomLevels
|
||||
)
|
||||
}, true);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,21 @@ OpenLayers.Layer.GoogleNG = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
||||
*/
|
||||
SUPPORTED_TRANSITIONS: [],
|
||||
|
||||
/**
|
||||
* Property: serverResolutions
|
||||
* {Array} the resolutions provided by the Google API.
|
||||
*/
|
||||
serverResolutions: [
|
||||
156543.03390625, 78271.516953125, 39135.7584765625,
|
||||
19567.87923828125, 9783.939619140625, 4891.9698095703125,
|
||||
2445.9849047851562, 1222.9924523925781, 611.4962261962891,
|
||||
305.74811309814453, 152.87405654907226, 76.43702827453613,
|
||||
38.218514137268066, 19.109257068634033, 9.554628534317017,
|
||||
4.777314267158508, 2.388657133579254, 1.194328566789627,
|
||||
0.5971642833948135, 0.29858214169740677, 0.14929107084870338,
|
||||
0.07464553542435169, 0.037322767712175846
|
||||
],
|
||||
|
||||
/**
|
||||
* Property: attributionTemplate
|
||||
* {String}
|
||||
@@ -94,7 +109,6 @@ OpenLayers.Layer.GoogleNG = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
||||
var newArgs = [options.name, null, options];
|
||||
OpenLayers.Layer.XYZ.prototype.initialize.apply(this, newArgs);
|
||||
|
||||
this.options.numZoomLevels = options.numZoomLevels;
|
||||
if (!OpenLayers.Layer.GoogleNG.mapObject) {
|
||||
OpenLayers.Layer.GoogleNG.mapObject =
|
||||
new google.maps.Map(document.createElement("div"));
|
||||
@@ -121,26 +135,16 @@ OpenLayers.Layer.GoogleNG = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
||||
this.setName("Google " + mapType.name);
|
||||
}
|
||||
|
||||
var numZoomLevels = mapType.maxZoom + 1;
|
||||
if (this.options.numZoomLevels != null) {
|
||||
numZoomLevels = Math.min(numZoomLevels, this.options.numZoomLevels);
|
||||
}
|
||||
var restrictedMinZoom;
|
||||
if (this.restrictedMinZoom || mapType.minZoom) {
|
||||
restrictedMinZoom = Math.max(
|
||||
mapType.minZoom || 0, this.restrictedMinZoom || 0
|
||||
);
|
||||
}
|
||||
|
||||
var minZoom = mapType.minZoom || 0;
|
||||
this.addOptions({
|
||||
restrictedMinZoom: restrictedMinZoom,
|
||||
numZoomLevels: numZoomLevels,
|
||||
tileSize: new OpenLayers.Size(
|
||||
mapType.tileSize.width, mapType.tileSize.height
|
||||
maxResolution: Math.min(
|
||||
this.serverResolutions[minZoom], this.maxResolution
|
||||
),
|
||||
zoomOffset: minZoom,
|
||||
numZoomLevels: Math.min(
|
||||
mapType.maxZoom + 1 - minZoom, this.numZoomLevels
|
||||
)
|
||||
});
|
||||
// redraw to populate tiles with content
|
||||
this.redraw();
|
||||
}, true);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
+2
-16
@@ -1927,8 +1927,8 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
*/
|
||||
isValidZoomLevel: function(zoomLevel) {
|
||||
return ( (zoomLevel != null) &&
|
||||
(zoomLevel >= this.getRestrictedMinZoom()) &&
|
||||
(zoomLevel < this.getNumZoomLevels()) );
|
||||
(zoomLevel >= 0) &&
|
||||
(zoomLevel < this.getNumZoomLevels()) );
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -2031,20 +2031,6 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user