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

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Tue Mar 1 09:03:34 EST 2011


Author: bartvde
Date: 2011-03-01 06:03:31 -0800 (Tue, 01 Mar 2011)
New Revision: 11598

Modified:
   trunk/openlayers/lib/OpenLayers/Strategy/BBOX.js
   trunk/openlayers/tests/Strategy/BBOX.html
Log:
Vector layer with BBOX Strategy isn't loaded/requested automatically, p=vmische, r=me (closes #3142)

Modified: trunk/openlayers/lib/OpenLayers/Strategy/BBOX.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Strategy/BBOX.js	2011-03-01 13:51:07 UTC (rev 11597)
+++ trunk/openlayers/lib/OpenLayers/Strategy/BBOX.js	2011-03-01 14:03:31 UTC (rev 11598)
@@ -90,6 +90,14 @@
                 "refresh": this.update,
                 scope: this
             });
+            if(this.layer.visibility == true) {
+                this.update();
+            } else {
+                this.layer.events.on({
+                    "visibilitychanged": this.update,
+                    scope: this
+                });
+            }
         }
         return activated;
     },
@@ -106,10 +114,8 @@
         if(deactivated) {
             this.layer.events.un({
                 "moveend": this.update,
-                scope: this
-            });
-            this.layer.events.un({
                 "refresh": this.update,
+                "visibilitychanged": this.update,
                 scope: this
             });
         }
@@ -127,7 +133,8 @@
      */
     update: function(options) {
         var mapBounds = this.getMapBounds();
-        if ((options && options.force) || this.invalidBounds(mapBounds)) {
+        if (mapBounds !== null && ((options && options.force) ||
+                                   this.invalidBounds(mapBounds))) {
             this.calculateBounds(mapBounds);
             this.resolution = this.layer.map.getResolution(); 
             this.triggerRead();
@@ -142,6 +149,9 @@
      * {<OpenLayers.Bounds>} Map bounds in the projection of the layer.
      */
     getMapBounds: function() {
+        if (this.layer.map === null) {
+            return null;
+        }
         var bounds = this.layer.map.getExtent();
         if(!this.layer.projection.equals(this.layer.map.getProjectionObject())) {
             bounds = bounds.clone().transform(

Modified: trunk/openlayers/tests/Strategy/BBOX.html
===================================================================
--- trunk/openlayers/tests/Strategy/BBOX.html	2011-03-01 13:51:07 UTC (rev 11597)
+++ trunk/openlayers/tests/Strategy/BBOX.html	2011-03-01 14:03:31 UTC (rev 11598)
@@ -270,6 +270,29 @@
         
     }
 
+    // Test fix for Ticket #3142
+    function test_layerLoadedAfterBeingAdded(t) {
+        t.plan(1);
+
+        var dummy = new OpenLayers.Layer(null, {isBaseLayer: true});
+
+        var strategy = new OpenLayers.Strategy.BBOX({
+            ratio: 1 // makes for easier comparison to map bounds
+        });
+        var layer = new OpenLayers.Layer.Vector(null, {
+            protocol: new OpenLayers.Protocol(),
+            strategies: [strategy]
+        });
+
+        var map = new OpenLayers.Map("map");
+        map.addLayer(dummy);
+        map.setCenter(new OpenLayers.LonLat(0, 0));
+        map.addLayer(layer);
+
+        // test that the strategy bounds were set
+        t.ok(map.getExtent().equals(strategy.bounds), "[set center] bounds set to map extent");
+    }
+
   </script>
 </head>
 <body>



More information about the Commits mailing list