Changeset 7484
- Timestamp:
- 07/09/08 11:29:15 (1 month ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/vector-behavior/lib/OpenLayers/Layer/Vector.js
r7465 r7484 113 113 */ 114 114 features: null, 115 116 /** 117 * APIProperty: featureMap 118 * {Object} A feature fid to <OpenLayers.Feature.Vector> feature map. 119 */ 120 featureMap: null, 115 121 116 122 /** … … 206 212 207 213 this.features = []; 214 this.featureMap = {}; 208 215 this.selectedFeatures = []; 209 216 … … 230 237 this.destroyFeatures(); 231 238 this.features = null; 239 this.featureMap = null; 232 240 this.selectedFeatures = null; 233 241 if (this.renderer) { … … 414 422 415 423 this.features.push(feature); 424 this.featureMap[feature.fid] = feature; 416 425 417 426 //give feature reference to its layer … … 475 484 476 485 this.features = OpenLayers.Util.removeItem(this.features, feature); 486 delete this.featureMap[feature.fid]; 477 487 478 488 if (feature.geometry) { sandbox/vector-behavior/lib/OpenLayers/Strategy/Grid.js
r7483 r7484 32 32 33 33 /** 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 /** 34 46 * Class: tileClass 35 47 * Inner class to represent tiles … … 73 85 destroyFeatures: function() { 74 86 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 } 76 103 } 77 104 this.features = []; … … 101 128 var features = resp.features; 102 129 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 } 103 146 this.features = features; 104 this.strategy.layer.addFeatures(features); 147 if (toAdd && toAdd.length > 0) { 148 this.strategy.layer.addFeatures(toAdd); 149 } 105 150 } 106 151 } else {
