OpenLayers OpenLayers

Ticket #1427: patch-1427-r7546-A1.diff

File patch-1427-r7546-A1.diff, 3.2 kB (added by elemoine, 5 months ago)
  • tests/Control/ModifyFeature.html

    old new  
    164164    }     
    165165 
    166166    function test_selectFeature(t) { 
    167         t.plan(15); 
     167        t.plan(16); 
    168168        var layer = new OpenLayers.Layer.Vector(); 
    169169        var control = new OpenLayers.Control.ModifyFeature(layer); 
    170170        control.vertices = []; 
    171171        control.virtualVertices = []; 
    172         layer.events.on({"beforefeaturemodified": function(event) { 
    173             t.eq(event.feature, fakeFeature, "beforefeaturemodified triggered"); 
    174         }}); 
     172        var callback = function(obj) { 
     173            t.eq(obj.feature, fakeFeature, "beforefeaturemodified triggered"); 
     174        }; 
     175        layer.events.on({"beforefeaturemodified": callback}); 
    175176        control.dragControl.activate = function() { t.ok(true, "drag Control activated"); } 
    176177        control.onModificationStart = function(feature)  { t.eq(feature.id, fakeFeature.id, "On Modification Start called with correct feature."); }  
    177178         
     
    211212 
    212213        // Features are removed whenever they exist 
    213214        control.selectFeature({feature: fakeFeature}); 
     215        layer.events.un({"beforefeaturemodified": callback}); 
     216 
     217        // Check that selectFeature does nothing if a beforefeaturemodified 
     218        // listener returns false 
     219        var callback = function(obj) { 
     220            t.eq(obj.feature, fakeFeature, "beforefeaturemodified triggered"); 
     221            return false; 
     222        }; 
     223        layer.events.on({"beforefeaturemodified": callback}); 
     224        var getTestFunction = function(funcName) { 
     225            return function() { 
     226                t.fail(funcName + " called with a beforefeaturemodified listener returned false"); 
     227            }; 
     228        }; 
     229        control.resetVertices = getTestFunction("resetVertices"); 
     230        control.dragControl.activate = getTestFunction("dragControl.activate"); 
     231        control.onModificationStart = getTestFunction("onModificationStart"); 
     232        control.selectFeature({feature: fakeFeature}); 
     233        layer.events.un({"beforefeaturemodified": callback}); 
    214234         
    215235        control.destroy(); 
    216236        layer.destroy(); 
  • lib/OpenLayers/Control/ModifyFeature.js

    old new  
    297297     *     selected feature. 
    298298     */ 
    299299    selectFeature: function(object) { 
    300         this.feature = object.feature; 
    301         this.resetVertices(); 
    302         this.dragControl.activate(); 
    303         this.onModificationStart(this.feature); 
    304         this.layer.events.triggerEvent("beforefeaturemodified",  
    305                                        {feature: this.feature}); 
     300        var cont = this.layer.events.triggerEvent( 
     301            "beforefeaturemodified", {feature: object.feature} 
     302        ); 
     303        if(cont !== false) { 
     304            this.feature = object.feature; 
     305            this.resetVertices(); 
     306            this.dragControl.activate(); 
     307            this.onModificationStart(this.feature); 
     308        } 
    306309    }, 
    307310 
    308311    /**