From 149e85c92386158154e6df1716b6b977a538ff1c Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 30 Sep 2007 18:11:27 +0000 Subject: [PATCH] In changing base layers, we now rely on the old map resolution instead of the old map zoom. This means that for layers with different resolutions arrays, we try to keep the map resolution as consistent as possible (instead of keeping an arbitrary zoom level consistent). This change also fixes a bug that comes up in changing base layers for layers with different length resolution arrays (closes #1032). git-svn-id: http://svn.openlayers.org/trunk/openlayers@4682 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Map.js | 13 ++++++++++++- tests/test_Map.html | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index a06e4948fa..21c6707077 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -109,6 +109,12 @@ OpenLayers.Map = OpenLayers.Class({ */ center: null, + /** + * Property: resolution + * {Float} The resolution of the map. + */ + resolution: null, + /** * Property: zoom * {Integer} The current zoom level of the map @@ -703,7 +709,11 @@ OpenLayers.Map = OpenLayers.Class({ if (center != null) { if (oldExtent == null) { // simply set center but force zoom change - this.setCenter(center, this.getZoom(), false, true); + this.setCenter( + center, + this.getZoomForResolution(this.resolution), + false, true + ); } else { // zoom to oldExtent *and* force zoom change this.setCenter(oldExtent.getCenterLonLat(), @@ -1121,6 +1131,7 @@ OpenLayers.Map = OpenLayers.Class({ if (zoomChanged) { this.zoom = zoom; + this.resolution = this.baseLayer.getResolution(); // zoom level has changed, increment viewRequestID. this.viewRequestID++; } diff --git a/tests/test_Map.html b/tests/test_Map.html index bdb75455f2..ff0f333c07 100644 --- a/tests/test_Map.html +++ b/tests/test_Map.html @@ -277,6 +277,35 @@ t.ok(map.baseLayer == wmslayer2, "setbaselayer correctly sets 'baseLayer' property"); } + function test_Map_removeLayer_res(t) { + t.plan(2); + + map = new OpenLayers.Map('map'); + + var layer0 = new OpenLayers.Layer.WMS( + 'Test Layer 0', + "http://octo.metacarta.com/cgi-bin/mapserv", + {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}, + {resolutions: [4, 2, 1]} + ); + + var layer1 = new OpenLayers.Layer.WMS( + 'Test Layer 1', + "http://octo.metacarta.com/cgi-bin/mapserv", + {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}, + {resolutions: [4, 2]} + ); + + map.addLayers([layer0, layer1]); + map.zoomToMaxExtent(); + map.zoomTo(2); + t.eq(map.getResolution(), layer0.resolutions[2], + "correct resolution before removal"); + map.removeLayer(layer0); + t.eq(map.getResolution(), layer0.resolutions[1], + "correct resolution after removal"); + } + function test_13_Map_setBaseLayer_after_pan (t) { t.plan(1);