OpenLayers OpenLayers

Changeset 5470

Show
Ignore:
Timestamp:
12/17/07 09:36:39 (1 year ago)
Author:
elemoine
Message:

Do not call preFeatureInsert() and onFeatureInsert() callbacks when the modify feature control and the regular polygon handler internally adds point geometries to the layer. This is accomplished by adding an 'options' argument to the addFeatures() method in Layer.Vector. If that options argument has the silent property set to true, then the preFeatureInsert() and onFeatureInsert() callbacks aren't called. Thanks tschaub and fredj for your input. Thanks crschmidt for the final review. (closes #1148)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Control/ModifyFeature.js

    r5467 r5470  
    515515        } 
    516516        collectComponentVertices.call(this, this.feature.geometry); 
    517         this.layer.addFeatures(this.vertices); 
    518         this.layer.addFeatures(this.virtualVertices); 
     517        this.layer.addFeatures(this.vertices, {silent: true}); 
     518        this.layer.addFeatures(this.virtualVertices, {silent: true}); 
    519519    }, 
    520520 
     
    535535        } 
    536536        this.dragHandle = origin; 
    537         this.layer.addFeatures([this.dragHandle]); 
     537        this.layer.addFeatures([this.dragHandle], {silent: true}); 
    538538    }, 
    539539 
     
    575575        } 
    576576        this.radiusHandle = radius; 
    577         this.layer.addFeatures([this.radiusHandle]); 
     577        this.layer.addFeatures([this.radiusHandle], {silent: true}); 
    578578    }, 
    579579 
  • trunk/openlayers/lib/OpenLayers/Handler/RegularPolygon.js

    r5200 r5470  
    217217        this.feature = new OpenLayers.Feature.Vector(); 
    218218        this.createGeometry(); 
    219         this.layer.addFeatures([this.feature]); 
     219        this.layer.addFeatures([this.feature], {silent: true}); 
    220220        this.layer.drawFeature(this.feature, this.style); 
    221221    }, 
  • trunk/openlayers/lib/OpenLayers/Layer/Vector.js

    r5429 r5470  
    243243     * Parameters: 
    244244     * features - {Array(<OpenLayers.Feature.Vector>)}  
    245      */ 
    246     addFeatures: function(features) { 
     245     * options - {Object} 
     246     */ 
     247    addFeatures: function(features, options) { 
    247248        if (!(features instanceof Array)) { 
    248249            features = [features]; 
    249250        } 
     251         
     252        var notify = !options || !options.silent; 
    250253 
    251254        for (var i = 0; i < features.length; i++) { 
     
    268271            } 
    269272 
    270             this.preFeatureInsert(feature); 
     273            if (notify) { 
     274                this.preFeatureInsert(feature); 
     275            } 
    271276 
    272277            if (this.drawn) { 
     
    274279            } 
    275280             
    276             this.onFeatureInsert(feature); 
     281            if (notify) { 
     282                this.onFeatureInsert(feature); 
     283            } 
    277284        } 
    278285    }, 
  • trunk/openlayers/tests/Layer/test_Vector.html

    r5454 r5470  
    1717     
    1818    function test_02_Layer_Vector_addFeatures(t) { 
    19         t.plan(2); 
     19        t.plan(4); 
    2020     
    2121        var layer = new OpenLayers.Layer.Vector(name); 
     
    2323        var point = new OpenLayers.Geometry.Point(-111.04, 45.68); 
    2424        var pointFeature = new OpenLayers.Feature.Vector(point); 
     25 
     26        layer.preFeatureInsert = function(feature) { 
     27            t.ok(feature == pointFeature, "OpenLayers.Layer.Vector.addFeatures calls preFeatureInsert with the right arg"); 
     28        } 
     29        layer.onFeatureInsert = function(feature) { 
     30            t.ok(feature == pointFeature, "OpenLayers.Layer.Vector.addFeatures calls onFeatureInsert with the right arg"); 
     31        } 
     32 
    2533        layer.addFeatures([pointFeature]); 
    2634         
    2735        t.eq(layer.features.length, 1, "OpenLayers.Layer.Vector.addFeatures adds something to the array"); 
    2836        t.ok(layer.features[0] == pointFeature, "OpenLayers.Layer.Vector.addFeatures returns an array of features"); 
     37 
     38        layer.preFeatureInsert = function(feature) { 
     39            t.fail("OpenLayers.Layer.Vector.addFeatures calls preFeatureInsert while it must not"); 
     40        } 
     41        layer.onFeatureInsert = function(feature) { 
     42            t.fail("OpenLayers.Layer.Vector.addFeatures calls onFeatureInsert while it must not"); 
     43        } 
     44 
     45        layer.addFeatures([pointFeature], {silent: true}); 
    2946    } 
    3047