[OpenLayers-Commits] r11480 - in trunk/openlayers: lib/OpenLayers tests

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Fri Feb 25 06:47:45 EST 2011


Author: tschaub
Date: 2011-02-25 03:47:41 -0800 (Fri, 25 Feb 2011)
New Revision: 11480

Modified:
   trunk/openlayers/lib/OpenLayers/Map.js
   trunk/openlayers/tests/Map.html
Log:
Making it so moveTo is only called once when creating a map with center and layers options. r=crschmidt (closes #3114)

Modified: trunk/openlayers/lib/OpenLayers/Map.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Map.js	2011-02-25 11:01:37 UTC (rev 11479)
+++ trunk/openlayers/lib/OpenLayers/Map.js	2011-02-25 11:47:41 UTC (rev 11480)
@@ -600,6 +600,14 @@
         
         // 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) {

Modified: trunk/openlayers/tests/Map.html
===================================================================
--- trunk/openlayers/tests/Map.html	2011-02-25 11:01:37 UTC (rev 11479)
+++ trunk/openlayers/tests/Map.html	2011-02-25 11:47:41 UTC (rev 11480)
@@ -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;



More information about the Commits mailing list