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

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Sun Apr 3 01:04:20 EDT 2011


Author: tschaub
Date: 2011-04-02 22:04:17 -0700 (Sat, 02 Apr 2011)
New Revision: 11860

Modified:
   trunk/openlayers/lib/OpenLayers/Renderer/Canvas.js
   trunk/openlayers/tests/Renderer/Canvas.html
Log:
Making the canvas renderer keep track of a pending redraw.  With this change we properly redraw even if the last feature in a batch has no geometry.  p=me,ahocevar r=ahocevar (closes #3225)

Modified: trunk/openlayers/lib/OpenLayers/Renderer/Canvas.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Renderer/Canvas.js	2011-04-03 04:58:49 UTC (rev 11859)
+++ trunk/openlayers/lib/OpenLayers/Renderer/Canvas.js	2011-04-03 05:04:17 UTC (rev 11860)
@@ -42,7 +42,14 @@
      * Property: features
      * {Object} Internal object of feature/style pairs for use in redrawing the layer.
      */
-    features: null, 
+    features: null,
+    
+    /**
+     * Property: pendingRedraw
+     * {Boolean} The renderer needs a redraw call to render features added while
+     *     the renderer was locked.
+     */
+    pendingRedraw: false,
    
     /**
      * Constructor: OpenLayers.Renderer.Canvas
@@ -134,10 +141,14 @@
             style = style || feature.style;
             style = this.applyDefaultSymbolizer(style);  
 
-            this.features[feature.id] = [feature, style]; 
-            this.redraw();
+            this.features[feature.id] = [feature, style];
             rendered = true;
+            this.pendingRedraw = true;
         }
+        if (this.pendingRedraw && !this.locked) {
+            this.redraw();
+            this.pendingRedraw = false;
+        }
         return rendered;
     },
 
@@ -659,7 +670,6 @@
                 if (!this.features.hasOwnProperty(id)) { continue; }
                 feature = this.features[id][0];
                 style = this.features[id][1];
-                if (!feature.geometry) { continue; }
                 this.drawGeometry(feature.geometry, style, feature.id);
                 if(style.label) {
                     labelMap.push([feature, style]);

Modified: trunk/openlayers/tests/Renderer/Canvas.html
===================================================================
--- trunk/openlayers/tests/Renderer/Canvas.html	2011-04-03 04:58:49 UTC (rev 11859)
+++ trunk/openlayers/tests/Renderer/Canvas.html	2011-04-03 05:04:17 UTC (rev 11860)
@@ -150,6 +150,68 @@
         t.eq(r.resolution, null, "resolution nullified");
         t.eq(r.map, null, "map nullified");
     }
+
+    function test_pendingRedraw(t) {
+        if (!supported) {
+            t.plan(0); 
+            return; 
+        }
+        
+        t.plan(4);
+        var layer = new OpenLayers.Layer.Vector(null, {
+            isBaseLayer: true,
+            renderers: ["Canvas"]
+        });
+        
+        var map = new OpenLayers.Map({
+            div: "map",
+            controls: [],
+            layers: [layer],
+            center: new OpenLayers.LonLat(0, 0),
+            zoom: 0
+        });
+        
+        var count = 0;
+        var redraw = layer.renderer.redraw;
+        layer.renderer.redraw = function() {
+            ++count;
+            redraw.apply(this, arguments);
+        }
+        
+        // add one point feature and confirm redraw is called once
+        count = 0;
+        layer.addFeatures([
+            new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(0, 0))
+        ]);
+        t.eq(count, 1, "redraw called once after adding one point feature");
+        
+        // add one feature with no geometry and confirm redraw is not called
+        count = 0;
+        layer.addFeatures([
+            new OpenLayers.Feature.Vector()
+        ]);
+        t.eq(count, 0, "redraw is not called when adding a feature with no geometry");
+        
+        // add one point feature, one feature with no geom, and one point feature and confirm redraw is called once
+        count = 0;
+        layer.addFeatures([
+            new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1, 0)),
+            new OpenLayers.Feature.Vector(),
+            new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(0, 1))
+        ]);
+        t.eq(count, 1, "redraw called once after adding three features where middle one has no geometry");
+
+        // add two point features and one feature with no geom, and confirm redraw is called once
+        count = 0;
+        layer.addFeatures([
+            new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1, 0)),
+            new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(0, 1)),
+            new OpenLayers.Feature.Vector()
+        ]);
+        t.eq(count, 1, "redraw called once after adding three features where last one has no geometry");
+        
+        map.destroy();
+    }
     
     function test_hitDetection(t) {
         if (!supported) {



More information about the Commits mailing list