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

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Oct 20 10:01:36 EDT 2010


Author: ahocevar
Date: 2010-10-20 07:01:36 -0700 (Wed, 20 Oct 2010)
New Revision: 10851

Modified:
   trunk/openlayers/lib/OpenLayers/Renderer/Elements.js
   trunk/openlayers/tests/Renderer/Elements.html
Log:
Make sure that the background node is removed when redrawing with a different symbolizer. Thanks ahtih for this excellent debut patch. p=ahtih, r=me (closes #2891)


Modified: trunk/openlayers/lib/OpenLayers/Renderer/Elements.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Renderer/Elements.js	2010-10-20 10:51:51 UTC (rev 10850)
+++ trunk/openlayers/lib/OpenLayers/Renderer/Elements.js	2010-10-20 14:01:36 UTC (rev 10851)
@@ -509,10 +509,13 @@
         };
 
         rendered = false;
+        var removeBackground = false;
         if (style.display != "none") {
             if (style.backgroundGraphic) {
                 this.redrawBackgroundNode(geometry.id, geometry, style,
                     featureId);
+            } else {
+                removeBackground = true;
             }
             rendered = this.redrawNode(geometry.id, geometry, style,
                 featureId);
@@ -521,12 +524,18 @@
             var node = document.getElementById(geometry.id);
             if (node) {
                 if (node._style.backgroundGraphic) {
-                    node.parentNode.removeChild(document.getElementById(
-                        geometry.id + this.BACKGROUND_ID_SUFFIX));
+                    removeBackground = true;
                 }
                 node.parentNode.removeChild(node);
             }
         }
+        if (removeBackground) {
+            var node = document.getElementById(
+                geometry.id + this.BACKGROUND_ID_SUFFIX);
+            if (node) {
+                node.parentNode.removeChild(node);
+            }
+        }
         return rendered;
     },
     

Modified: trunk/openlayers/tests/Renderer/Elements.html
===================================================================
--- trunk/openlayers/tests/Renderer/Elements.html	2010-10-20 10:51:51 UTC (rev 10850)
+++ trunk/openlayers/tests/Renderer/Elements.html	2010-10-20 14:01:36 UTC (rev 10851)
@@ -561,8 +561,63 @@
         tearDown();        
     }
 
+    function test_Elements_drawGeometry_3(t) {
+        t.plan(2);
 
+        setUp();
 
+        var r = create_renderer();
+        
+        var element = document.createElement("div");
+        r.vectorRoot = element;
+
+        r.nodeFactory = function(id, type) {
+            return document.createElement("div");
+        };
+        var g_Node = null;
+        var b_Node = null;
+        r.drawGeometryNode = function(node, geometry, style) {
+            g_Node = node;
+            return {node: node, complete: true};
+        };
+        r.redrawBackgroundNode = function(id, geometry, style, featureId) {
+            b_Node = r.nodeFactory();
+            b_Node.id = "foo_background";
+            element.appendChild(b_Node);
+        };
+
+        r.getNodeType = function(geometry, style) {
+            return "div";
+        };
+        var geometry = {
+            id: 'foo',
+            CLASS_NAME: 'bar',
+            getBounds: function() {return {bottom: 0}}
+        };
+        var style = {'backgroundGraphic': 'foo'};
+        var featureId = 'dude';
+        r.drawGeometry(geometry, style, featureId);
+        t.ok(b_Node.parentNode == element, "redrawBackgroundNode appended background node");
+
+        var returnNode = function(id) {
+        	return id == "foo_background" ? b_Node : g_Node;
+        }
+       	
+        var _getElement = document.getElementById;
+        document.getElementById = returnNode;
+        OpenLayers.Util.getElement = returnNode;
+
+        style = {};
+        r.drawGeometry(geometry, style, featureId);
+        t.ok(b_Node.parentNode != element, "background node correctly removed")
+            
+        document.getElementById = _getElement;
+
+        tearDown();
+    }
+
+
+
   </script>
 </head>
 <body>



More information about the Commits mailing list