From f7a2efe2bf46873d0acfe2c037434483b6d582e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Fri, 24 Jul 2009 12:49:13 +0000 Subject: [PATCH] make updateSize not call setCenter if map has no center, and remove unused code, r=tschaub (closes #2105) (closes #2114) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9587 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Map.js | 8 ++++---- tests/Map.html | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 46d4b9c3c1..f7aef8ad81 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -1343,12 +1343,12 @@ OpenLayers.Map = OpenLayers.Class({ this.layers[i].onMapResize(); } - if (this.baseLayer != null) { - var center = new OpenLayers.Pixel(newSize.w /2, newSize.h / 2); - var centerLL = this.getLonLatFromViewPortPx(center); + var center = this.getCenter(); + + if (this.baseLayer != null && center != null) { var zoom = this.getZoom(); this.zoom = null; - this.setCenter(this.getCenter(), zoom); + this.setCenter(center, zoom); } } diff --git a/tests/Map.html b/tests/Map.html index c778a3c828..28afb022c6 100644 --- a/tests/Map.html +++ b/tests/Map.html @@ -1313,7 +1313,39 @@ map.destroy(); t.ok(!map.panTween || !map.panTween.playing, "the map pan tween is not playing after destroy"); - + } + + function test_updateSize(t) { + t.plan(2); + + var map, moveToCnt, size; + + map = new OpenLayers.Map({div: "map"}); + map.addLayer(new OpenLayers.Layer("layer", {isBaseLayer: true})); + + map.moveTo = function() { + moveToCnt++; + OpenLayers.Map.prototype.moveTo.apply(this, arguments); + }; + + map.getCurrentSize = function() { + return size; + }; + + // map has no center + // 1 test + moveToCnt = 0; + size = new OpenLayers.Size(650, 350); + map.updateSize(); + t.eq(moveToCnt, 0, "updateSize doesn't move the map if it doesn't have a center"); + + // map has a center + // 1 test + map.zoomToMaxExtent(); + moveToCnt = 0; + size = new OpenLayers.Size(600, 300); + map.updateSize(); + t.eq(moveToCnt, 1, "updateSize move the map if it has a center"); }