Changeset 5467
- Timestamp:
- 12/17/07 05:12:56 (1 year ago)
- Files:
-
- trunk/openlayers/examples/modify-feature.html (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Control/ModifyFeature.js (modified) (6 diffs)
- trunk/openlayers/tests/Control/test_ModifyFeature.html (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/examples/modify-feature.html
r5404 r5467 70 70 71 71 function update() { 72 // reset modification mode 73 controls.modify.mode = OpenLayers.Control.ModifyFeature.RESHAPE; 72 74 var rotate = document.getElementById("rotate").checked; 73 controls.modify.rotate = rotate; 75 if(rotate) { 76 controls.modify.mode |= OpenLayers.Control.ModifyFeature.ROTATE; 77 } 74 78 var resize = document.getElementById("resize").checked; 75 controls.modify.resize = resize; 79 if(resize) { 80 controls.modify.mode |= OpenLayers.Control.ModifyFeature.RESIZE; 81 } 76 82 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 } 78 91 var sides = parseInt(document.getElementById("sides").value); 79 92 sides = Math.max(3, isNaN(sides) ? 0 : sides); trunk/openlayers/lib/OpenLayers/Control/ModifyFeature.js
r5301 r5467 89 89 90 90 /** 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, 101 103 102 104 /** … … 106 108 radiusHandle: null, 107 109 108 /**109 * APIProperty: drag110 * {Boolean} Allow dragging of feature with a drag handle.111 */112 drag: false,113 114 110 /** 115 111 * Property: dragHandle … … 160 156 this.styleVirtual.strokeOpacity = 0.3; 161 157 this.deleteCodes = [46, 100]; 158 this.mode = OpenLayers.Control.ModifyFeature.RESHAPE; 162 159 OpenLayers.Control.prototype.initialize.apply(this, [options]); 163 160 if(!(this.deleteCodes instanceof Array)) { … … 428 425 if(this.feature && 429 426 this.feature.geometry.CLASS_NAME != "OpenLayers.Geometry.Point") { 430 if( this.drag) {427 if((this.mode & OpenLayers.Control.ModifyFeature.DRAG)) { 431 428 this.collectDragHandle(); 432 429 } 433 if(this.rotate || this.resize) { 430 if((this.mode & (OpenLayers.Control.ModifyFeature.ROTATE | 431 OpenLayers.Control.ModifyFeature.RESIZE))) { 434 432 this.collectRadiusHandle(); 435 } else { 433 } 434 if((this.mode & OpenLayers.Control.ModifyFeature.RESHAPE)) { 436 435 this.collectVertices(); 437 436 } … … 554 553 ); 555 554 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); 558 557 radiusGeometry.move = function(x, y) { 559 558 OpenLayers.Geometry.Point.prototype.move.call(this, x, y); … … 594 593 CLASS_NAME: "OpenLayers.Control.ModifyFeature" 595 594 }); 595 596 /** 597 * Constant: RESHAPE 598 * {Integer} Constant used to make the control work in reshape mode 599 */ 600 OpenLayers.Control.ModifyFeature.RESHAPE = 1; 601 /** 602 * Constant: RESIZE 603 * {Integer} Constant used to make the control work in resize mode 604 */ 605 OpenLayers.Control.ModifyFeature.RESIZE = 2; 606 /** 607 * Constant: ROTATE 608 * {Integer} Constant used to make the control work in rotate mode 609 */ 610 OpenLayers.Control.ModifyFeature.ROTATE = 4; 611 /** 612 * Constant: DRAG 613 * {Integer} Constant used to make the control work in drag mode 614 */ 615 OpenLayers.Control.ModifyFeature.DRAG = 8; trunk/openlayers/tests/Control/test_ModifyFeature.html
r5301 r5467 5 5 6 6 function test_ModifyFeature_constructor(t) { 7 t.plan( 2);7 t.plan(3); 8 8 var layer = "foo"; 9 9 var options = { … … 16 16 t.eq(control.selectControl.geometryTypes, "bar", 17 17 "constructor sets options correctly on feature handler"); 18 t.eq(control.mode, OpenLayers.Control.ModifyFeature.RESHAPE, 19 "constructor initializes modification mode correctly"); 18 20 } 19 21 … … 248 250 249 251 function test_ModifyFeature_resetVertices(t) { 250 t.plan(1 5);252 t.plan(18); 251 253 var layer = new OpenLayers.Layer.Vector(); 252 254 var control = new OpenLayers.Control.ModifyFeature(layer); … … 279 281 t.eq(control.virtualVertices.length, 3, "Correct virtual vertices length (polygon)."); 280 282 281 control. drag = true;283 control.mode = OpenLayers.Control.ModifyFeature.DRAG; 282 284 control.resetVertices(); 283 285 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; 287 289 control.resetVertices(); 288 290 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.res ize = 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(); 293 295 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)"); 295 303 } 296 304
