From f7fcb86ee989d014530dee33cc2db6354d616d5a Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 25 Feb 2011 11:47:41 +0000 Subject: [PATCH] Making it so moveTo is only called once when creating a map with center and layers options. r=crschmidt (closes #3114) git-svn-id: http://svn.openlayers.org/trunk/openlayers@11480 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Map.js | 8 ++++++++ tests/Map.html | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index ad64e54b02..c45cbb1e1d 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -600,6 +600,14 @@ OpenLayers.Map = OpenLayers.Class({ // add any initial layers if (options && options.layers) { + /** + * If you have set options.center, the map center property will be + * set at this point. However, since setCenter has not been caleld, + * addLayers gets confused. So we delete the map center in this + * case. Because the check below uses options.center, it will + * be properly set below. + */ + delete this.center; this.addLayers(options.layers); // set center (and optionally zoom) if (options.center) { diff --git a/tests/Map.html b/tests/Map.html index 12841e7cfd..568b7e4c87 100644 --- a/tests/Map.html +++ b/tests/Map.html @@ -1602,7 +1602,7 @@ } function test_center_option(t) { - t.plan(6); + t.plan(7); var map, msg; @@ -1625,6 +1625,12 @@ map.destroy(); } + var log = []; + var meth = OpenLayers.Layer.prototype.moveTo; + OpenLayers.Layer.prototype.moveTo = function() { + log.push(arguments); + meth.apply(this, arguments); + }; // set center without zoom var center = new OpenLayers.LonLat(1, 2); @@ -1635,8 +1641,10 @@ }); t.ok(center.equals(map.getCenter()), "map center set without zoom"); + t.eq(log.length, 1, "moveTo called once"); map.destroy(); + OpenLayers.Layer.prototype.moveTo = meth; // set center and zoom var zoom = 3;