From 2a1217691512d86d9ce7f8b2b05a21c36a52a2cf Mon Sep 17 00:00:00 2001 From: ahocevar Date: Wed, 2 Mar 2011 11:09:24 +0000 Subject: [PATCH] make setOptions work for restrictedExtent change, like it was before #3062. r=bartvde (closes #3144) git-svn-id: http://svn.openlayers.org/trunk/openlayers@11608 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Map.js | 6 ++++++ tests/Map.html | 24 ++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 36e3cdb794..7f6096974f 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -739,7 +739,13 @@ OpenLayers.Map = OpenLayers.Class({ * options - {Object} Hashtable of options to tag to the map */ setOptions: function(options) { + var updatePxExtent = this.minPx && + options.restrictedExtent != this.restrictedExtent; OpenLayers.Util.extend(this, options); + // force recalculation of minPx and maxPx + updatePxExtent && this.moveTo(this.getCachedCenter(), this.zoom, { + forceZoomChange: true + }); }, /** diff --git a/tests/Map.html b/tests/Map.html index 351f0545cb..8979543bf5 100644 --- a/tests/Map.html +++ b/tests/Map.html @@ -1052,7 +1052,7 @@ } function test_Map_restrictedExtent(t) { - t.plan(24); + t.plan(25); var extent = new OpenLayers.Bounds(-180, -90, 180, 90); var options = { maxResolution: "auto" @@ -1147,8 +1147,28 @@ "map extent not restricted with null restrictedExtent for se"); map.destroy(); + + extent = new OpenLayers.Bounds(8, 44.5, 19, 50); + var options = { + restrictedExtent: extent + }; + map = new OpenLayers.Map('map', options); + + var wms = new OpenLayers.Layer.WMS( + "OpenLayers WMS", + "http://vmap0.tiles.osgeo.org/wms/vmap0?", + {layers: 'basic'} + ); + + map.addLayers([wms]); + map.zoomToExtent(extent); + map.zoomIn(); + map.setOptions({restrictedExtent: null}); + map.pan(-250, -250); + t.ok((map.getExtent().bottom == 48.3486328125 && map.getExtent().left == 7.45751953125), "Expected extent when toggling restrictedExtent"); + map.destroy(); } - + function test_Map_getResolutionForZoom(t) { t.plan(2); var map = new OpenLayers.Map("map");