OpenLayers OpenLayers

Changeset 5467

Show
Ignore:
Timestamp:
12/17/07 05:12:56 (1 year ago)
Author:
elemoine
Message:

ModifyFeature: enable dragging without enabling vertex modifications. Special thanks to tschaub for the collaboration on all the changes to the modify feature control. And thanks to crschmidt for the review. (closes #1188)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/examples/modify-feature.html

    r5404 r5467  
    7070         
    7171        function update() { 
     72            // reset modification mode 
     73            controls.modify.mode = OpenLayers.Control.ModifyFeature.RESHAPE; 
    7274            var rotate = document.getElementById("rotate").checked; 
    73             controls.modify.rotate = rotate; 
     75            if(rotate) { 
     76                controls.modify.mode |= OpenLayers.Control.ModifyFeature.ROTATE; 
     77            } 
    7478            var resize = document.getElementById("resize").checked; 
    75             controls.modify.resize = resize; 
     79            if(resize) { 
     80                controls.modify.mode |= OpenLayers.Control.ModifyFeature.RESIZE; 
     81            } 
    7682            var drag = document.getElementById("drag").checked; 
    77             controls.modify.drag = drag; 
     83            if(drag) { 
     84                controls.modify.mode |= OpenLayers.Control.ModifyFeature.DRAG; 
     85            } 
     86            // disable reshape mode if at least one of modes rotate, resize, 
     87            // drag is enabled 
     88            if (rotate || resize || drag) { 
     89                controls.modify.mode &= ~OpenLayers.Control.ModifyFeature.RESHAPE; 
     90            } 
    7891            var sides = parseInt(document.getElementById("sides").value); 
    7992            sides = Math.max(3, isNaN(sides) ? 0 : sides); 
  • trunk/openlayers/lib/OpenLayers/Control/ModifyFeature.js

    r5301 r5467  
    8989 
    9090    /** 
    91      * APIProperty: rotate 
    92      * {Boolean} Allow rotation of feature instead of vertex modification. 
    93      */ 
    94     rotate: false, 
    95  
    96     /** 
    97      * APIProperty: resize 
    98      * {Boolean} Allow resizing of feature instead of vertex modification. 
    99      */ 
    100     resize: false, 
     91     * APIProperty: mode 
     92     * {Integer} Bitfields specifying the modification mode. Defaults to 
     93     *      OpenLayers.Control.ModifyFeature.RESHAPE. To set the mode to a 
     94     *      combination of options, use the | operator. or example, to allow 
     95     *      the control to both resize and rotate features, use the following 
     96     *      syntax 
     97     * (code) 
     98     * control.mode = OpenLayers.Control.ModifyFeature.RESIZE | 
     99     *                OpenLayers.Control.ModifyFeature.ROTATE; 
     100     *  (end) 
     101     */ 
     102    mode: null, 
    101103 
    102104    /** 
     
    106108    radiusHandle: null, 
    107109 
    108     /** 
    109      * APIProperty: drag 
    110      * {Boolean} Allow dragging of feature with a drag handle. 
    111      */ 
    112     drag: false, 
    113      
    114110    /** 
    115111     * Property: dragHandle 
     
    160156        this.styleVirtual.strokeOpacity = 0.3; 
    161157        this.deleteCodes = [46, 100]; 
     158        this.mode = OpenLayers.Control.ModifyFeature.RESHAPE; 
    162159        OpenLayers.Control.prototype.initialize.apply(this, [options]); 
    163160        if(!(this.deleteCodes instanceof Array)) { 
     
    428425        if(this.feature && 
    429426           this.feature.geometry.CLASS_NAME != "OpenLayers.Geometry.Point") { 
    430             if(this.drag) { 
     427            if((this.mode & OpenLayers.Control.ModifyFeature.DRAG)) { 
    431428                this.collectDragHandle(); 
    432429            } 
    433             if(this.rotate || this.resize) { 
     430            if((this.mode & (OpenLayers.Control.ModifyFeature.ROTATE | 
     431                             OpenLayers.Control.ModifyFeature.RESIZE))) { 
    434432                this.collectRadiusHandle(); 
    435             } else { 
     433            } 
     434            if((this.mode & OpenLayers.Control.ModifyFeature.RESHAPE)) { 
    436435                this.collectVertices(); 
    437436            } 
     
    554553        ); 
    555554        var radius = new OpenLayers.Feature.Vector(radiusGeometry); 
    556         var resize = this.resize
    557         var rotate = this.rotate
     555        var resize = (this.mode & OpenLayers.Control.ModifyFeature.RESIZE)
     556        var rotate = (this.mode & OpenLayers.Control.ModifyFeature.ROTATE)
    558557        radiusGeometry.move = function(x, y) { 
    559558            OpenLayers.Geometry.Point.prototype.move.call(this, x, y); 
     
    594593    CLASS_NAME: "OpenLayers.Control.ModifyFeature" 
    595594}); 
     595 
     596/** 
     597 * Constant: RESHAPE 
     598 * {Integer} Constant used to make the control work in reshape mode 
     599 */ 
     600OpenLayers.Control.ModifyFeature.RESHAPE = 1; 
     601/** 
     602 * Constant: RESIZE 
     603 * {Integer} Constant used to make the control work in resize mode 
     604 */ 
     605OpenLayers.Control.ModifyFeature.RESIZE = 2; 
     606/** 
     607 * Constant: ROTATE 
     608 * {Integer} Constant used to make the control work in rotate mode 
     609 */ 
     610OpenLayers.Control.ModifyFeature.ROTATE = 4; 
     611/** 
     612 * Constant: DRAG 
     613 * {Integer} Constant used to make the control work in drag mode 
     614 */ 
     615OpenLayers.Control.ModifyFeature.DRAG = 8; 
  • trunk/openlayers/tests/Control/test_ModifyFeature.html

    r5301 r5467  
    55     
    66    function test_ModifyFeature_constructor(t) { 
    7         t.plan(2); 
     7        t.plan(3); 
    88        var layer = "foo";         
    99        var options = { 
     
    1616        t.eq(control.selectControl.geometryTypes, "bar", 
    1717             "constructor sets options correctly on feature handler"); 
     18        t.eq(control.mode, OpenLayers.Control.ModifyFeature.RESHAPE, 
     19             "constructor initializes modification mode correctly"); 
    1820    } 
    1921 
     
    248250 
    249251    function test_ModifyFeature_resetVertices(t) { 
    250         t.plan(15); 
     252        t.plan(18); 
    251253        var layer = new OpenLayers.Layer.Vector(); 
    252254        var control = new OpenLayers.Control.ModifyFeature(layer); 
     
    279281        t.eq(control.virtualVertices.length, 3, "Correct virtual vertices length (polygon)."); 
    280282 
    281         control.drag = true
     283        control.mode = OpenLayers.Control.ModifyFeature.DRAG
    282284        control.resetVertices(); 
    283285        t.ok(control.dragHandle != null, "Drag handle is set"); 
    284         t.eq(control.vertices.length, 4, "Correct vertices length with polygon (drag)"); 
    285  
    286         control.rotate = true
     286        t.eq(control.vertices.length, 0, "Correct vertices length with polygon (DRAG)"); 
     287 
     288        control.mode = OpenLayers.Control.ModifyFeature.ROTATE
    287289        control.resetVertices(); 
    288290        t.ok(control.radiusHandle != null, "Radius handle is set"); 
    289         t.eq(control.vertices.length, 0, "Correct vertices length with polygon (rotate)"); 
    290  
    291         control.rotate = false
    292         control.resize = true
     291        t.eq(control.vertices.length, 0, "Correct vertices length with polygon (ROTATE)"); 
     292 
     293        control.mode = OpenLayers.Control.ModifyFeature.RESIZE
     294        control.resetVertices()
    293295        t.ok(control.radiusHandle != null, "Radius handle is set"); 
    294         t.eq(control.vertices.length, 0, "Correct vertices length with polygon (resize)"); 
     296        t.eq(control.vertices.length, 0, "Correct vertices length with polygon (RESIZE)"); 
     297 
     298        control.mode = OpenLayers.Control.ModifyFeature.RESHAPE | OpenLayers.Control.ModifyFeature.RESIZE; 
     299        control.resetVertices(); 
     300        t.ok(control.radiusHandle != null, "Radius handle is set"); 
     301        t.eq(control.vertices.length, 4, "Correct vertices length with polygon (RESHAPE | RESIZE)"); 
     302        t.eq(control.virtualVertices.length, 3, "Correct virtual vertices length (RESHAPE | RESIZE)"); 
    295303    }     
    296304