Allow array for min/maxExtent in layers.

This commit is contained in:
tschaub
2011-10-26 16:02:51 -06:00
parent 98ee7167c4
commit fb790424a5
3 changed files with 79 additions and 0 deletions

View File

@@ -471,6 +471,16 @@ OpenLayers.Layer = OpenLayers.Class({
if (this.options == null) {
this.options = {};
}
// allow array for extents
if (newOptions) {
if (newOptions.maxExtent && !(newOptions.maxExtent instanceof OpenLayers.Bounds)) {
newOptions.maxExtent = new OpenLayers.Bounds(newOptions.maxExtent);
}
if (newOptions.minExtent && !(newOptions.minExtent instanceof OpenLayers.Bounds)) {
newOptions.minExtent = new OpenLayers.Bounds(newOptions.minExtent);
}
}
// update our copy for clone
OpenLayers.Util.extend(this.options, newOptions);

View File

@@ -197,6 +197,39 @@
t.eq(layer.numZoomLevels, numZoomLevels, "numZoomLevels set correctly");
}
function test_maxExtent(t) {
t.plan(5);
var layer = new OpenLayers.Layer(
null, {maxExtent: [-180, 0, 0, 90]}
);
t.ok(layer.maxExtent instanceof OpenLayers.Bounds, "(array) bounds instance");
t.eq(layer.maxExtent.left, -180, "(array) bounds left");
t.eq(layer.maxExtent.bottom, 0, "(array) bounds left");
t.eq(layer.maxExtent.right, 0, "(array) bounds right");
t.eq(layer.maxExtent.top, 90, "(array) bounds top");
layer.destroy();
}
function test_minExtent(t) {
t.plan(5);
var layer = new OpenLayers.Layer(
null, {minExtent: [-180, 0, 0, 90]}
);
t.ok(layer.minExtent instanceof OpenLayers.Bounds, "(array) bounds instance");
t.eq(layer.minExtent.left, -180, "(array) bounds left");
t.eq(layer.minExtent.bottom, 0, "(array) bounds left");
t.eq(layer.minExtent.right, 0, "(array) bounds right");
t.eq(layer.minExtent.top, 90, "(array) bounds top");
layer.destroy();
}
function test_eventListeners(t) {
t.plan(1);

View File

@@ -378,6 +378,42 @@
}
function test_maxExtent(t) {
t.plan(5);
var layer = new OpenLayers.Layer.WMS(
null, "http://example.com/wms",
{layers: "foo"},
{maxExtent: [-180, 0, 0, 90]}
);
t.ok(layer.maxExtent instanceof OpenLayers.Bounds, "(array) bounds instance");
t.eq(layer.maxExtent.left, -180, "(array) bounds left");
t.eq(layer.maxExtent.bottom, 0, "(array) bounds left");
t.eq(layer.maxExtent.right, 0, "(array) bounds right");
t.eq(layer.maxExtent.top, 90, "(array) bounds top");
layer.destroy();
}
function test_minExtent(t) {
t.plan(5);
var layer = new OpenLayers.Layer.WMS(
null, "http://example.com/wms",
{layers: "foo"},
{minExtent: [-180, 0, 0, 90]}
);
t.ok(layer.minExtent instanceof OpenLayers.Bounds, "(array) bounds instance");
t.eq(layer.minExtent.left, -180, "(array) bounds left");
t.eq(layer.minExtent.bottom, 0, "(array) bounds left");
t.eq(layer.minExtent.right, 0, "(array) bounds right");
t.eq(layer.minExtent.top, 90, "(array) bounds top");
layer.destroy();
}
function test_tileOrigin(t) {
t.plan(4);