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:
@@ -26,4 +26,4 @@ map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||
map.setCenter(new OpenLayers.LonLat(-71.147, 42.472).transform(
|
||||
new OpenLayers.Projection("EPSG:4326"),
|
||||
map.getProjectionObject()
|
||||
), 12);
|
||||
), 11);
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -82,9 +82,9 @@
|
||||
|
||||
function test_Layer_addOptions (t) {
|
||||
|
||||
t.plan( 19 );
|
||||
t.plan( 20 );
|
||||
|
||||
var map = new OpenLayers.Map("map");
|
||||
var map = new OpenLayers.Map("map", {allOverlays: true});
|
||||
var options = { chicken: 151, foo: "bar" };
|
||||
var layer = new OpenLayers.Layer('Test Layer', options);
|
||||
map.addLayer(layer);
|
||||
@@ -156,6 +156,17 @@
|
||||
layer.addOptions({projection: "EPSG:900913"});
|
||||
t.ok(layer.projection instanceof OpenLayers.Projection,
|
||||
"addOptions creates a Projection object when given a projection string");
|
||||
|
||||
log = null;
|
||||
// adding a 2nd layer to see if it gets reinitialized properly
|
||||
var layer2 = new OpenLayers.Layer(null, {
|
||||
moveTo: function(bounds) {
|
||||
log = bounds;
|
||||
}
|
||||
});
|
||||
map.addLayer(layer2);
|
||||
layer.addOptions({maxResolution: 0.00034332275390625}, true);
|
||||
t.eq(log.toBBOX(), map.getExtent().toBBOX(), "when reinitialize is set to true, changing base layer's resolution property reinitializes all layers.");
|
||||
|
||||
map.removeLayer(layer);
|
||||
log = 0;
|
||||
@@ -556,7 +567,7 @@
|
||||
|
||||
function test_Layer_getZoomForResolution(t) {
|
||||
|
||||
t.plan(13);
|
||||
t.plan(12);
|
||||
|
||||
var layer = new OpenLayers.Layer('Test Layer');
|
||||
layer.map = {};
|
||||
@@ -584,10 +595,6 @@
|
||||
"(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");
|
||||
|
||||
}
|
||||
|
||||
function test_Layer_redraw(t) {
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
var log = {};
|
||||
layer = new OpenLayers.Layer.GoogleNG({
|
||||
numZoomLevels: 10,
|
||||
restrictedMinZoom: 2,
|
||||
maxResolution: 39135.7584765625,
|
||||
initLayer: function() {
|
||||
log[layer.id] = true;
|
||||
OpenLayers.Layer.GoogleNG.prototype.initLayer.apply(this, arguments);
|
||||
@@ -30,13 +30,14 @@
|
||||
map.zoomToMaxExtent();
|
||||
|
||||
var map2 = new OpenLayers.Map("map2");
|
||||
var minZoom = 1;
|
||||
var layer2 = new OpenLayers.Layer.GoogleNG({
|
||||
numZoomLevels: 24,
|
||||
initLayer: function() {
|
||||
log[layer2.id] = true;
|
||||
var origMinZoom = OpenLayers.Layer.GoogleNG.mapObject.mapTypes[layer2.type].minZoom;
|
||||
// pretend the API reports a minZoom of 1
|
||||
OpenLayers.Layer.GoogleNG.mapObject.mapTypes[layer2.type].minZoom = 1;
|
||||
// pretend the API reports a different minZoom
|
||||
OpenLayers.Layer.GoogleNG.mapObject.mapTypes[layer2.type].minZoom = minZoom;
|
||||
OpenLayers.Layer.GoogleNG.prototype.initLayer.apply(this, arguments);
|
||||
OpenLayers.Layer.GoogleNG.mapObject.mapTypes[layer2.type].minZoom = origMinZoom;
|
||||
}
|
||||
@@ -49,10 +50,10 @@
|
||||
t.eq(log[layer2.id], true, "initLayer called for 2nd layer");
|
||||
|
||||
t.eq(layer.numZoomLevels, 10, "numZoomLevels from configuration takes precedence if lower");
|
||||
t.eq(layer2.numZoomLevels, OpenLayers.Layer.GoogleNG.mapObject.mapTypes[layer2.type].maxZoom+1, "numZoomLevels from API takes precedence if lower");
|
||||
t.eq(layer2.numZoomLevels, OpenLayers.Layer.GoogleNG.mapObject.mapTypes[layer2.type].maxZoom + 1 - minZoom, "numZoomLevels from API takes precedence if lower");
|
||||
|
||||
t.eq(layer.restrictedMinZoom, 2, "restrictedMinZoom from configuration takes precedence if higher");
|
||||
t.eq(layer2.restrictedMinZoom, 1, "restrictedMinZoom from API takes precedence if higher");
|
||||
t.eq(layer.maxResolution, 39135.7584765625, "maxResolution from configuration takes precedence if higher");
|
||||
t.eq(layer2.maxResolution, 78271.516953125, "maxResolution from API takes precedence if higher");
|
||||
|
||||
map.destroy();
|
||||
map2.destroy();
|
||||
|
||||
@@ -338,31 +338,24 @@
|
||||
*/
|
||||
|
||||
function test_Map_isValidZoomLevel(t) {
|
||||
t.plan(6);
|
||||
t.plan(4);
|
||||
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, [-1]);
|
||||
t.eq(valid, false, "-1 is not a valid zoomLevel");
|
||||
|
||||
valid = OpenLayers.Map.prototype.isValidZoomLevel.apply(map, [0]);
|
||||
t.eq(valid, true, "0 is a valid zoomLevel when baseLayer has no restrictedMinZoom");
|
||||
t.eq(valid, true, "0 is a valid zoomLevel");
|
||||
|
||||
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");
|
||||
|
||||
map.destroy();
|
||||
}
|
||||
@@ -1296,27 +1289,6 @@
|
||||
var maxExtent = OpenLayers.Map.prototype.getMaxExtent.apply(map, [options]);
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user