From ca30d3df626a23af14ac8206df3a4c6411fd0ca0 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Sun, 23 Nov 2008 22:31:12 +0000 Subject: [PATCH] map.getCenter() should return a cloned center, so that (for example) transforming the center doesn't break the map. patch by edgemaster, r=me, (Closes #1853) git-svn-id: http://svn.openlayers.org/trunk/openlayers@8410 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Map.js | 6 +++++- tests/Map.html | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index c640895dd6..1d059fee6c 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -1330,7 +1330,11 @@ OpenLayers.Map = OpenLayers.Class({ * {} */ getCenter: function () { - return this.center; + var center = null; + if (this.center) { + center = this.center.clone(); + } + return center; }, diff --git a/tests/Map.html b/tests/Map.html index 5e864f6f2b..fc53af7530 100644 --- a/tests/Map.html +++ b/tests/Map.html @@ -100,7 +100,7 @@ } function test_Map_center(t) { - t.plan(7); + t.plan(8); map = new OpenLayers.Map('map'); var baseLayer = new OpenLayers.Layer.WMS("Test Layer", "http://octo.metacarta.com/cgi-bin/mapserv?", @@ -128,6 +128,8 @@ t.ok( lonlat.equals(zero), "map center is correct after calling zoomToFullExtent" ); */ + map.getCenter().lon = 10; + t.ok( map.getCenter().equals(ll), "map.getCenter returns a clone of map.center"); } function test_Map_zoomend_event (t) {