OpenLayers OpenLayers

Changeset 7919

Show
Ignore:
Timestamp:
09/01/08 17:46:26 (3 months ago)
Author:
ahocevar
Message:

Let's take care that background graphic nodes of features with backgroundGraphic style get removed properly when the style is changed to display: "none".

This solves the backgroundGraphic issue of #1709, the remaining issue with externalGraphic will be fixed by #1675.

Thanks jstern81 for the patch, and I am truly impressed by jstern81 finding the right spot in the codebase that needs to be fixed -- as an OpenLayers newcomer.

Tests added by myself. r=me. (references #1709)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Renderer/Elements.js

    r7781 r7919  
    464464        }; 
    465465 
    466         // 
    467         if (style.backgroundGraphic) { 
    468             this.redrawBackgroundNode(geometry.id, geometry, style, featureId); 
    469         } 
    470          
    471466        if (style.display != "none") { 
    472             this.redrawNode(geometry.id, geometry, style, featureId);  
     467            if (style.backgroundGraphic) { 
     468                this.redrawBackgroundNode(geometry.id, geometry, style, featureId); 
     469            } 
     470            this.redrawNode(geometry.id, geometry, style, featureId); 
    473471        } else { 
    474472            var node = OpenLayers.Util.getElement(geometry.id); 
    475473            if (node) { 
     474                if (node._style.backgroundGraphic) { 
     475                    node.parentNode.removeChild(document.getElementById( 
     476                        geometry.id + this.BACKGROUND_ID_SUFFIX)); 
     477                } 
    476478                node.parentNode.removeChild(node); 
    477479            } 
  • trunk/openlayers/tests/Renderer/Elements.html

    r7783 r7919  
    128128     
    129129    function test_Elements_drawGeometry(t) { 
    130         t.plan(5); 
     130        t.plan(7); 
    131131 
    132132        setUp(); 
     
    135135         
    136136        var element = document.createElement("div"); 
     137        document.body.appendChild(element); 
    137138        r.root = element; 
    138139 
     
    146147            return node; 
    147148        }; 
     149        r.redrawBackgroundNode = function(id, geometry, style, featureId) { 
     150            var el = r.nodeFactory(); 
     151            el.id = "foo_background"; 
     152            r.root.appendChild(el); 
     153        }; 
     154 
    148155        r.getNodeType = function(geometry, style) { 
    149156            return "div"; 
     
    153160            CLASS_NAME: 'bar' 
    154161        }; 
    155         var style = true
     162        var style = {'backgroundGraphic': 'foo'}
    156163        var featureId = 'dude'; 
    157164        r.drawGeometry(geometry, style, featureId); 
    158165        t.ok(g_Node.parentNode == r.root, "node is correctly appended to root"); 
     166        t.eq(r.root.childNodes.length, 2, "redrawBackgroundNode appended background node"); 
    159167        t.eq(g_Node._featureId, 'dude', "_featureId is correct"); 
    160         t.ok(g_Node._style, "_style is correct"); 
     168        t.eq(g_Node._style.backgroundGraphic, "foo", "_style is correct"); 
    161169        t.eq(g_Node._geometryClass, 'bar', "_geometryClass is correct"); 
    162170 
     
    165173            return g_Node; 
    166174        } 
    167  
    168         var style = {'display':'none'}; 
     175         
     176        style = {'display':'none'}; 
    169177        r.drawGeometry(geometry, style, featureId); 
    170178        t.ok(g_Node.parentNode != r.root, "node is correctly removed"); 
     179        t.ok(!document.getElementById("foo_background"), "background node correctly removed") 
    171180             
    172181        tearDown();