From 7b7c174cc7237e8f3c2a652410dea0bb913a708d Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Tue, 6 Apr 2010 19:20:57 +0000 Subject: [PATCH] Allow center to be provided to map constructor without layers. r=bartvde (closes #2561) git-svn-id: http://svn.openlayers.org/trunk/openlayers@10169 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Map.js | 13 ++++++------- tests/Map.html | 8 ++++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index abd47d1dd8..1d1646affb 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -594,13 +594,12 @@ OpenLayers.Map = OpenLayers.Class({ // add any initial layers if (options && options.layers) { - this.addLayers(options.layers); - } - - // set center (and optionally zoom) - if (options && options.center) { - // zoom can be undefined here - this.setCenter(options.center, options.zoom); + this.addLayers(options.layers); + // set center (and optionally zoom) + if (options.center) { + // zoom can be undefined here + this.setCenter(options.center, options.zoom); + } } }, diff --git a/tests/Map.html b/tests/Map.html index 3b0f435339..e2a2dddc8a 100644 --- a/tests/Map.html +++ b/tests/Map.html @@ -1557,19 +1557,19 @@ var map, msg; - // try setting center without layers, this is not supported + // try setting center without layers, this has no effect var failed = false; try { map = new OpenLayers.Map({ div: "map", center: new OpenLayers.LonLat(1, 2) }); - msg = "center set with no layers"; + msg = "center option without layers has no effect"; } catch (err) { failed = true; - msg = "center cannot be set without layers"; + msg = "center option without layers throws error"; } - t.ok(failed, msg); + t.ok(!failed, msg); if (map) { map.destroy();