OpenLayers OpenLayers

Changeset 4270

Show
Ignore:
Timestamp:
09/13/07 19:09:42 (1 year ago)
Author:
tschaub
Message:

disallowing point deletion at this time since we don't support feature deletion for other geometry types

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/tschaub/feature/lib/OpenLayers/Control/ModifyFeature.js

    r4269 r4270  
    111111     */ 
    112112    onModificationEnd: function() {}, 
    113      
    114     /** 
    115      * APIProperty: onDelete 
    116      * {Function} Optional function to be called when a feature is finished  
    117      *     deleted.  The function should expect to be called with a 
    118      *     feature. 
    119      */ 
    120     onDelete: function() {}, 
    121113 
    122114    /** 
     
    389381    handleKeypress: function(code) { 
    390382        // check for delete key 
    391         if(OpenLayers.Util.indexOf(this.deleteCodes, code) != -1) { 
    392             var vertex; 
    393             // points can be deleted before the dragging has begun 
    394             if(this.dragControl.feature) { 
    395                 // we've got a draggable vertex or a dragged point 
    396                 vertex = this.dragControl.feature; 
    397             } else if(this.feature && 
    398                       this.feature.geometry.CLASS_NAME == 
    399                       "OpenLayers.Geometry.Point") { 
    400                 // we've not begun dragging, delete the point (confirmed below) 
    401                 vertex = this.feature; 
    402             } 
    403             if(vertex) { 
    404                 if(this.feature.geometry.CLASS_NAME == 
    405                    "OpenLayers.Geometry.Point") { 
    406                     if(this.feature == vertex) { 
    407                         // delete the point only if it is modifiable 
    408                         this.unselectFeature(vertex); 
    409                         this.layer.removeFeatures([vertex]); 
    410                         this.onDelete(vertex); 
    411                     } 
    412                 } else { 
    413                     if(OpenLayers.Util.indexOf(this.vertices, vertex) != -1) { 
    414                         // remove the vertex 
    415                         vertex.geometry.parent.removeComponent(vertex.geometry); 
    416                         this.layer.drawFeature(this.feature, 
    417                                                this.selectControl.selectStyle); 
    418                         this.resetVertices(); 
    419                         this.onModification(this.feature); 
    420                     } 
    421                 } 
     383        if(this.feature && 
     384           OpenLayers.Util.indexOf(this.deleteCodes, code) != -1) { 
     385            var vertex = this.dragControl.feature; 
     386            if(vertex && 
     387               OpenLayers.Util.indexOf(this.vertices, vertex) != -1) { 
     388                // remove the vertex 
     389                vertex.geometry.parent.removeComponent(vertex.geometry); 
     390                this.layer.drawFeature(this.feature, 
     391                                       this.selectControl.selectStyle); 
     392                this.resetVertices(); 
     393                this.onModification(this.feature); 
    422394            } 
    423395        } 
  • sandbox/tschaub/feature/tests/Control/test_ModifyFeature.html

    r4269 r4270  
    6161     
    6262    function test_ModifyFeature_handleKeypress(t) { 
    63         t.plan(24); 
     63        t.plan(8); 
    6464 
    6565        /** 
    66          * There are three things that we want to test here 
     66         * There are two things that we want to test here 
    6767         * 1) test that control.deleteCodes are respected 
    68          * 2) test that a point is properly deleted 
    6968         * 3) test that a vertex is properly deleted 
     69         * 
     70         * In the future, feature deletion may be added to the control. 
    7071         */ 
    7172         
     
    7576        control.deleteCodes = [delKey, dKey]; 
    7677 
    77         // test that point is deleted for all delete codes 
     78        //// test that point is deleted for all delete codes 
     79        //var point = new OpenLayers.Feature.Vector( 
     80        //    new OpenLayers.Geometry.Point() 
     81        //); 
     82        //// mock up deletion before dragging (but after selection) 
     83        //control.dragControl.feature = null; 
     84        //control.feature = point; 
     85        //var oldUnselect = control.unselectFeature; 
     86        //control.unselectFeature = function(feature) { 
     87        //    t.eq(feature.id, point.id, 
     88        //         "point deletion before drag: unselectFeature called with the correct feature"); 
     89        //}; 
     90        //control.layer = { 
     91        //    removeFeatures: function(features) { 
     92        //        t.ok(features.length == 1, 
     93        //             "point deletion before drag: removeFeatures called with a single feature"); 
     94        //        t.eq(features[0].id, point.id, 
     95        //             "point deletion before drag: removeFeatures called with the correct feature"); 
     96        //    } 
     97        //}; 
     98        //control.onDelete = function(feature) { 
     99        //    t.eq(feature.id, point.id, 
     100        //         "point deletion before drag: onDelete called with the correct feature"); 
     101        //}; 
     102        //// run the above four tests twice 
     103        //control.handleKeypress(delKey); 
     104        //control.handleKeypress(dKey); 
     105        //// reset modified methods 
     106        //control.unselectFeatures = oldUnselect; 
     107        //control.onDelete = function() {}; 
     108        // 
     109        //// mock up deletion during dragging - these repeat the above tests 
     110        //control.dragControl.feature = point; 
     111        //control.feature = point; 
     112        //var oldUnselect = control.unselectFeature; 
     113        //control.unselectFeature = function(feature) { 
     114        //    t.eq(feature.id, point.id, 
     115        //         "point deletion during drag: unselectFeature called with the correct feature"); 
     116        //}; 
     117        //control.layer = { 
     118        //    removeFeatures: function(features) { 
     119        //        t.ok(features.length == 1, 
     120        //             "point deletion during drag: removeFeatures called with a single feature"); 
     121        //        t.eq(features[0].id, point.id, 
     122        //             "point deletion during drag: removeFeatures called with the correct feature"); 
     123        //    } 
     124        //}; 
     125        //control.onDelete = function(feature) { 
     126        //    t.eq(feature.id, point.id, 
     127        //         "point deletion during drag: onDelete called with the correct feature"); 
     128        //}; 
     129        //// run the above four tests twice 
     130        //control.handleKeypress(delKey); 
     131        //control.handleKeypress(dKey); 
     132        //// reset modified methods 
     133        //control.unselectFeatures = oldUnselect; 
     134        //control.onDelete = function() {}; 
     135         
     136        // test that a polygon vertex is deleted for all delete codes 
    78137        var point = new OpenLayers.Feature.Vector( 
    79138            new OpenLayers.Geometry.Point() 
    80139        ); 
    81         // mock up deletion before dragging (but after selection) 
    82         control.dragControl.feature = null; 
    83         control.feature = point; 
    84         var oldUnselect = control.unselectFeature; 
    85         control.unselectFeature = function(feature) { 
    86             t.eq(feature.id, point.id, 
    87                  "point deletion before drag: unselectFeature called with the correct feature"); 
    88         }; 
    89         control.layer = { 
    90             removeFeatures: function(features) { 
    91                 t.ok(features.length == 1, 
    92                      "point deletion before drag: removeFeatures called with a single feature"); 
    93                 t.eq(features[0].id, point.id, 
    94                      "point deletion before drag: removeFeatures called with the correct feature"); 
    95             } 
    96         }; 
    97         control.onDelete = function(feature) { 
    98             t.eq(feature.id, point.id, 
    99                  "point deletion before drag: onDelete called with the correct feature"); 
    100         }; 
    101         // run the above four tests twice 
    102         control.handleKeypress(delKey); 
    103         control.handleKeypress(dKey); 
    104         // reset modified methods 
    105         control.unselectFeatures = oldUnselect; 
    106         control.onDelete = function() {}; 
    107  
    108         // mock up deletion during dragging - these repeat the above tests 
    109         control.dragControl.feature = point; 
    110         control.feature = point; 
    111         var oldUnselect = control.unselectFeature; 
    112         control.unselectFeature = function(feature) { 
    113             t.eq(feature.id, point.id, 
    114                  "point deletion during drag: unselectFeature called with the correct feature"); 
    115         }; 
    116         control.layer = { 
    117             removeFeatures: function(features) { 
    118                 t.ok(features.length == 1, 
    119                      "point deletion during drag: removeFeatures called with a single feature"); 
    120                 t.eq(features[0].id, point.id, 
    121                      "point deletion during drag: removeFeatures called with the correct feature"); 
    122             } 
    123         }; 
    124         control.onDelete = function(feature) { 
    125             t.eq(feature.id, point.id, 
    126                  "point deletion during drag: onDelete called with the correct feature"); 
    127         }; 
    128         // run the above four tests twice 
    129         control.handleKeypress(delKey); 
    130         control.handleKeypress(dKey); 
    131         // reset modified methods 
    132         control.unselectFeatures = oldUnselect; 
    133         control.onDelete = function() {}; 
    134          
    135         // test that a polygon vertex is deleted for all delete codes 
    136140        var poly = new OpenLayers.Feature.Vector( 
    137141            new OpenLayers.Geometry.Polygon() 
     
    402406    } 
    403407 
    404     function test_ModifyFeature_onDelete(t) { 
    405         t.plan(2); 
    406         var map = new OpenLayers.Map("map"); 
    407         var layer = new OpenLayers.Layer.Vector(); 
    408         map.addLayer(layer); 
    409         var control = new OpenLayers.Control.ModifyFeature(layer); 
    410         map.addControl(control); 
    411         control.activate(); 
    412          
    413         // make sure onDelete is called on point deletion (before dragging) 
    414         var point = new OpenLayers.Feature.Vector( 
    415             new OpenLayers.Geometry.Point(Math.random(), Math.random()) 
    416         ); 
    417         control.feature = point; 
    418         control.onDelete = function(feature) { 
    419             t.eq(feature.id, point.id, 
    420                 "onDelete called with the right feature before drag"); 
    421         }; 
    422         control.handleKeypress(46); 
    423  
    424         // make sure onDelete is called on point deletion (during dragging) 
    425         var point = new OpenLayers.Feature.Vector( 
    426             new OpenLayers.Geometry.Point(Math.random(), Math.random()) 
    427         ); 
    428         control.dragControl.feature = point; 
    429         control.feature = point; 
    430         control.onDelete = function(feature) { 
    431             t.eq(feature.id, point.id, 
    432                 "onDelete called with the right feature during drag"); 
    433         }; 
    434         control.handleKeypress(46); 
    435          
    436     } 
     408 
     409    //function t//est_ModifyFeature_onDelete(t) { 
     410    //    t.plan(2); 
     411    //    var map = new OpenLayers.Map("map"); 
     412    //    var layer = new OpenLayers.Layer.Vector(); 
     413    //    map.addLayer(layer); 
     414    //    var control = new OpenLayers.Control.ModifyFeature(layer); 
     415    //    map.addControl(control); 
     416    //    control.activate(); 
     417    //     
     418    //    // make sure onDelete is called on point deletion (before dragging) 
     419    //    var point = new OpenLayers.Feature.Vector( 
     420    //        new OpenLayers.Geometry.Point(Math.random(), Math.random()) 
     421    //    ); 
     422    //    control.feature = point; 
     423    //    control.onDelete = function(feature) { 
     424    //        t.eq(feature.id, point.id, 
     425    //            "onDelete called with the right feature before drag"); 
     426    //    }; 
     427    //    control.handleKeypress(46); 
     428    // 
     429    //    // make sure onDelete is called on point deletion (during dragging) 
     430    //    var point = new OpenLayers.Feature.Vector( 
     431    //        new OpenLayers.Geometry.Point(Math.random(), Math.random()) 
     432    //    ); 
     433    //    control.dragControl.feature = point; 
     434    //    control.feature = point; 
     435    //    control.onDelete = function(feature) { 
     436    //        t.eq(feature.id, point.id, 
     437    //            "onDelete called with the right feature during drag"); 
     438    //    }; 
     439    //    control.handleKeypress(46); 
     440    // 
     441    //} 
    437442 
    438443    </script>