OpenLayers OpenLayers

Changeset 7712

Show
Ignore:
Timestamp:
08/08/08 08:23:59 (4 months ago)
Author:
elemoine
Message:

maxZIndex becomes NULL when the last feature is removed, p=pvalsecc, r=me (closes #1670)

Files:

Legend:

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

    r7711 r7712  
    129129            // Reset the maxium z-index based on the last item in the  
    130130            // order array. 
    131             var lastId = this.order[this.order.length - 1]; 
    132             this.maxZIndex = this.indices[lastId]; 
    133         } 
     131            if (this.order.length > 0) { 
     132                var lastId = this.order[this.order.length - 1]; 
     133                this.maxZIndex = this.indices[lastId]; 
     134            } else { 
     135                this.maxZIndex = 0; 
     136            } 
     137        } 
     138    }, 
     139     
     140    /** 
     141     * APIMethod: clear 
     142     */ 
     143    clear: function() { 
     144        this.order = []; 
     145        this.indices = {}; 
     146        this.maxZIndex = 0; 
    134147    }, 
    135148     
    136149    /** 
    137150     * APIMethod: exists 
    138      *  
     151     * 
    139152     * Parameters: 
    140153     * node- {DOMElement} The node to test for existence. 
    141      *  
     154     * 
    142155     * Returns: 
    143156     * {Boolean} Whether or not the node exists in the indexer? 
     
    146159        return (this.indices[node.id] != null); 
    147160    }, 
    148      
     161 
    149162    /** 
    150163     * APIMethod: getZIndex 
     
    396409            } 
    397410        } 
     411        this.indexer.clear(); 
    398412    }, 
    399413 
  • trunk/openlayers/tests/Renderer/Elements.html

    r7652 r7712  
    453453    } 
    454454 
     455    function test_Elements_drawAndErase(t) { 
     456        t.plan(20); 
     457 
     458        setUp(); 
     459 
     460        var r = create_renderer(); 
     461        var element = document.createElement("div"); 
     462        r.root = element; 
     463        document.body.appendChild(element); 
     464 
     465        r.createNode = function(type, id) { 
     466            var element = document.createElement("div"); 
     467            element.id = id; 
     468            return element; 
     469        }; 
     470        r.setStyle = function(node, style, options, geometry) { 
     471            return node; 
     472        }; 
     473         
     474        var geometry = { 
     475            id: 'foo', 
     476            CLASS_NAME: 'bar' 
     477        }; 
     478        var style = { 
     479            graphicZIndex: 10 
     480        }; 
     481        var featureId = 'foo'; 
     482        r.drawGeometry(geometry, style, featureId); 
     483 
     484        function count(obj) { 
     485            var result = 0; 
     486            for (var i in obj) { 
     487                result++; 
     488            } 
     489            return result; 
     490        } 
     491 
     492        t.ok(r.root.childNodes.length == 1, "root is correctly filled"); 
     493        t.ok(r.indexer.maxZIndex == 10, "indexer.maxZIndex is correctly filled"); 
     494        t.ok(r.indexer.order.length == 1, "indexer.order is correctly filled"); 
     495        t.ok(count(r.indexer.indices) == 1, "indexer.indices is correctly filled"); 
     496 
     497        r.eraseGeometry(geometry); 
     498 
     499        t.ok(r.root.childNodes.length == 0, "root is correctly cleared"); 
     500        t.ok(r.indexer.maxZIndex == 0, "indexer.maxZIndex is correctly reset"); 
     501        t.ok(r.indexer.order.length == 0, "indexer.order is correctly reset"); 
     502        t.ok(count(r.indexer.indices) == 0, "indexer.indices is correctly reset"); 
     503 
     504        delete(style.graphicZIndex); 
     505        r.drawGeometry(geometry, style, featureId); 
     506 
     507        t.ok(r.root.childNodes.length == 1, "root is correctly filled"); 
     508        t.ok(r.indexer.maxZIndex == 0, "indexer.maxZIndex is correctly filled"); 
     509        t.ok(r.indexer.order.length == 1, "indexer.order is correctly filled"); 
     510        t.ok(count(r.indexer.indices) == 1, "indexer.indices is correctly filled"); 
     511 
     512        r.clear(); 
     513 
     514        t.ok(r.root.childNodes.length == 0, "root is correctly cleared"); 
     515        t.ok(r.indexer.maxZIndex == 0, "indexer.maxZIndex is correctly reset"); 
     516        t.ok(r.indexer.order.length == 0, "indexer.order is correctly reset"); 
     517        t.ok(count(r.indexer.indices) == 0, "indexer.indices is correctly reset"); 
     518 
     519        style.graphicZIndex = 12; 
     520        r.drawGeometry(geometry, style, featureId); 
     521 
     522        t.ok(r.root.childNodes.length == 1, "root is correctly filled"); 
     523        t.ok(r.indexer.maxZIndex == 12, "indexer.maxZIndex is correctly filled"); 
     524        t.ok(r.indexer.order.length == 1, "indexer.order is correctly filled"); 
     525        t.ok(count(r.indexer.indices) == 1, "indexer.indices is correctly filled"); 
     526 
     527        tearDown(); 
     528    } 
     529 
     530 
    455531  </script> 
    456532</head>