OpenLayers OpenLayers

Changeset 7484

Show
Ignore:
Timestamp:
07/09/08 11:29:15 (1 month ago)
Author:
elemoine
Message:

deal with features spanning multiple tiles

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/vector-behavior/lib/OpenLayers/Layer/Vector.js

    r7465 r7484  
    113113     */ 
    114114    features: null, 
     115 
     116    /** 
     117     * APIProperty: featureMap 
     118     * {Object} A feature fid to <OpenLayers.Feature.Vector> feature map. 
     119     */ 
     120    featureMap: null, 
    115121     
    116122    /**  
     
    206212 
    207213        this.features = []; 
     214        this.featureMap = {}; 
    208215        this.selectedFeatures = []; 
    209216 
     
    230237        this.destroyFeatures(); 
    231238        this.features = null; 
     239        this.featureMap = null; 
    232240        this.selectedFeatures = null; 
    233241        if (this.renderer) { 
     
    414422 
    415423            this.features.push(feature); 
     424            this.featureMap[feature.fid] = feature; 
    416425             
    417426            //give feature reference to its layer 
     
    475484 
    476485            this.features = OpenLayers.Util.removeItem(this.features, feature); 
     486            delete this.featureMap[feature.fid]; 
    477487 
    478488            if (feature.geometry) { 
  • sandbox/vector-behavior/lib/OpenLayers/Strategy/Grid.js

    r7483 r7484  
    3232 
    3333    /** 
     34     * Property: safe 
     35     * {Boolean} If true the strategy makes sure it does not add multiple 
     36     * features with the same fid to the layer, this can occur if features 
     37     * span multiple grid cells. If true the strategy also makes sure it 
     38     * does not remove a feature that should still be visible because it 
     39     * spans multiple grid cells. If false, no such care is taken. For 
     40     * point features you may want to set it to false and get better 
     41     * performance. Defaults to true. 
     42     */ 
     43    safe: true, 
     44 
     45    /** 
    3446     * Class: tileClass 
    3547     * Inner class to represent tiles 
     
    7385        destroyFeatures: function() { 
    7486            if (this.features.length > 0) { 
    75                 this.strategy.layer.destroyFeatures(this.features); 
     87                var toDestroy = null; 
     88                if (this.strategy.safe) { 
     89                    var tileFeature; 
     90                    for (var i = 0; i < this.features.length; i++) { 
     91                        tileFeature = this.features[i]; 
     92                        if (--tileFeature.refCnt == 0) { 
     93                            toDestroy = toDestroy || []; 
     94                            toDestroy.push(tileFeature); 
     95                        } 
     96                    } 
     97                } else { 
     98                    toDestroy = this.features; 
     99                } 
     100                if (toDestroy && toDestroy.length > 0) { 
     101                    this.strategy.layer.destroyFeatures(this.features); 
     102                } 
    76103            } 
    77104            this.features = []; 
     
    101128                        var features = resp.features; 
    102129                        if (features && features.length > 0) { 
     130                            var toAdd = null; 
     131                            if (this.strategy.safe) { 
     132                                var fid, inFeature; 
     133                                for (var i = 0; i < features.length; i++) { 
     134                                    inFeature = this.strategy.layer.featureMap[features[i].fid]; 
     135                                    if (!inFeature) { 
     136                                        toAdd = toAdd || []; 
     137                                        inFeature = features[i]; 
     138                                        toAdd.push(inFeature); 
     139                                        inFeature.refCnt = 0; 
     140                                    } 
     141                                    inFeature.refCnt++; 
     142                                } 
     143                            } else { 
     144                                toAdd = features; 
     145                            } 
    103146                            this.features = features; 
    104                             this.strategy.layer.addFeatures(features); 
     147                            if (toAdd && toAdd.length > 0) { 
     148                                this.strategy.layer.addFeatures(toAdd); 
     149                            } 
    105150                        } 
    106151                    } else {