diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index 46ec873be7..06940d117a 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -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); diff --git a/tests/Layer.html b/tests/Layer.html index 92976c6f21..eabd233aee 100644 --- a/tests/Layer.html +++ b/tests/Layer.html @@ -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); diff --git a/tests/Layer/WMS.html b/tests/Layer/WMS.html index 51228b0afb..27d69a57bc 100644 --- a/tests/Layer/WMS.html +++ b/tests/Layer/WMS.html @@ -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);