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)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@5467 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -69,12 +69,25 @@
|
||||
}
|
||||
|
||||
function update() {
|
||||
// reset modification mode
|
||||
controls.modify.mode = OpenLayers.Control.ModifyFeature.RESHAPE;
|
||||
var rotate = document.getElementById("rotate").checked;
|
||||
controls.modify.rotate = rotate;
|
||||
if(rotate) {
|
||||
controls.modify.mode |= OpenLayers.Control.ModifyFeature.ROTATE;
|
||||
}
|
||||
var resize = document.getElementById("resize").checked;
|
||||
controls.modify.resize = resize;
|
||||
if(resize) {
|
||||
controls.modify.mode |= OpenLayers.Control.ModifyFeature.RESIZE;
|
||||
}
|
||||
var drag = document.getElementById("drag").checked;
|
||||
controls.modify.drag = drag;
|
||||
if(drag) {
|
||||
controls.modify.mode |= OpenLayers.Control.ModifyFeature.DRAG;
|
||||
}
|
||||
// disable reshape mode if at least one of modes rotate, resize,
|
||||
// drag is enabled
|
||||
if (rotate || resize || drag) {
|
||||
controls.modify.mode &= ~OpenLayers.Control.ModifyFeature.RESHAPE;
|
||||
}
|
||||
var sides = parseInt(document.getElementById("sides").value);
|
||||
sides = Math.max(3, isNaN(sides) ? 0 : sides);
|
||||
controls.regular.handler.sides = sides;
|
||||
|
||||
@@ -88,16 +88,18 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
virtualStyle: null,
|
||||
|
||||
/**
|
||||
* APIProperty: rotate
|
||||
* {Boolean} Allow rotation of feature instead of vertex modification.
|
||||
* APIProperty: mode
|
||||
* {Integer} Bitfields specifying the modification mode. Defaults to
|
||||
* OpenLayers.Control.ModifyFeature.RESHAPE. To set the mode to a
|
||||
* combination of options, use the | operator. or example, to allow
|
||||
* the control to both resize and rotate features, use the following
|
||||
* syntax
|
||||
* (code)
|
||||
* control.mode = OpenLayers.Control.ModifyFeature.RESIZE |
|
||||
* OpenLayers.Control.ModifyFeature.ROTATE;
|
||||
* (end)
|
||||
*/
|
||||
rotate: false,
|
||||
|
||||
/**
|
||||
* APIProperty: resize
|
||||
* {Boolean} Allow resizing of feature instead of vertex modification.
|
||||
*/
|
||||
resize: false,
|
||||
mode: null,
|
||||
|
||||
/**
|
||||
* Property: radiusHandle
|
||||
@@ -105,12 +107,6 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
radiusHandle: null,
|
||||
|
||||
/**
|
||||
* APIProperty: drag
|
||||
* {Boolean} Allow dragging of feature with a drag handle.
|
||||
*/
|
||||
drag: false,
|
||||
|
||||
/**
|
||||
* Property: dragHandle
|
||||
* {<OpenLayers.Feature.Vector>} A handle for dragging a feature.
|
||||
@@ -159,6 +155,7 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
this.styleVirtual.fillOpacity = 0.3;
|
||||
this.styleVirtual.strokeOpacity = 0.3;
|
||||
this.deleteCodes = [46, 100];
|
||||
this.mode = OpenLayers.Control.ModifyFeature.RESHAPE;
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
if(!(this.deleteCodes instanceof Array)) {
|
||||
this.deleteCodes = [this.deleteCodes];
|
||||
@@ -427,12 +424,14 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
}
|
||||
if(this.feature &&
|
||||
this.feature.geometry.CLASS_NAME != "OpenLayers.Geometry.Point") {
|
||||
if(this.drag) {
|
||||
if((this.mode & OpenLayers.Control.ModifyFeature.DRAG)) {
|
||||
this.collectDragHandle();
|
||||
}
|
||||
if(this.rotate || this.resize) {
|
||||
if((this.mode & (OpenLayers.Control.ModifyFeature.ROTATE |
|
||||
OpenLayers.Control.ModifyFeature.RESIZE))) {
|
||||
this.collectRadiusHandle();
|
||||
} else {
|
||||
}
|
||||
if((this.mode & OpenLayers.Control.ModifyFeature.RESHAPE)) {
|
||||
this.collectVertices();
|
||||
}
|
||||
}
|
||||
@@ -553,8 +552,8 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
bounds.right, bounds.bottom
|
||||
);
|
||||
var radius = new OpenLayers.Feature.Vector(radiusGeometry);
|
||||
var resize = this.resize;
|
||||
var rotate = this.rotate;
|
||||
var resize = (this.mode & OpenLayers.Control.ModifyFeature.RESIZE);
|
||||
var rotate = (this.mode & OpenLayers.Control.ModifyFeature.ROTATE);
|
||||
radiusGeometry.move = function(x, y) {
|
||||
OpenLayers.Geometry.Point.prototype.move.call(this, x, y);
|
||||
var dx1 = this.x - originGeometry.x;
|
||||
@@ -593,3 +592,24 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
|
||||
CLASS_NAME: "OpenLayers.Control.ModifyFeature"
|
||||
});
|
||||
|
||||
/**
|
||||
* Constant: RESHAPE
|
||||
* {Integer} Constant used to make the control work in reshape mode
|
||||
*/
|
||||
OpenLayers.Control.ModifyFeature.RESHAPE = 1;
|
||||
/**
|
||||
* Constant: RESIZE
|
||||
* {Integer} Constant used to make the control work in resize mode
|
||||
*/
|
||||
OpenLayers.Control.ModifyFeature.RESIZE = 2;
|
||||
/**
|
||||
* Constant: ROTATE
|
||||
* {Integer} Constant used to make the control work in rotate mode
|
||||
*/
|
||||
OpenLayers.Control.ModifyFeature.ROTATE = 4;
|
||||
/**
|
||||
* Constant: DRAG
|
||||
* {Integer} Constant used to make the control work in drag mode
|
||||
*/
|
||||
OpenLayers.Control.ModifyFeature.DRAG = 8;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_ModifyFeature_constructor(t) {
|
||||
t.plan(2);
|
||||
t.plan(3);
|
||||
var layer = "foo";
|
||||
var options = {
|
||||
geometryTypes: "bar"
|
||||
@@ -15,6 +15,8 @@
|
||||
"constructor sets layer correctly");
|
||||
t.eq(control.selectControl.geometryTypes, "bar",
|
||||
"constructor sets options correctly on feature handler");
|
||||
t.eq(control.mode, OpenLayers.Control.ModifyFeature.RESHAPE,
|
||||
"constructor initializes modification mode correctly");
|
||||
}
|
||||
|
||||
function test_ModifyFeature_destroy(t) {
|
||||
@@ -247,7 +249,7 @@
|
||||
}
|
||||
|
||||
function test_ModifyFeature_resetVertices(t) {
|
||||
t.plan(15);
|
||||
t.plan(18);
|
||||
var layer = new OpenLayers.Layer.Vector();
|
||||
var control = new OpenLayers.Control.ModifyFeature(layer);
|
||||
var point = new OpenLayers.Geometry.Point(5,6);
|
||||
@@ -278,20 +280,26 @@
|
||||
t.eq(control.vertices[0].geometry.id, control.vertices[3].geometry.id, "First and last vertices are the same");
|
||||
t.eq(control.virtualVertices.length, 3, "Correct virtual vertices length (polygon).");
|
||||
|
||||
control.drag = true;
|
||||
control.mode = OpenLayers.Control.ModifyFeature.DRAG;
|
||||
control.resetVertices();
|
||||
t.ok(control.dragHandle != null, "Drag handle is set");
|
||||
t.eq(control.vertices.length, 4, "Correct vertices length with polygon (drag)");
|
||||
t.eq(control.vertices.length, 0, "Correct vertices length with polygon (DRAG)");
|
||||
|
||||
control.rotate = true;
|
||||
control.mode = OpenLayers.Control.ModifyFeature.ROTATE;
|
||||
control.resetVertices();
|
||||
t.ok(control.radiusHandle != null, "Radius handle is set");
|
||||
t.eq(control.vertices.length, 0, "Correct vertices length with polygon (rotate)");
|
||||
t.eq(control.vertices.length, 0, "Correct vertices length with polygon (ROTATE)");
|
||||
|
||||
control.rotate = false;
|
||||
control.resize = true;
|
||||
control.mode = OpenLayers.Control.ModifyFeature.RESIZE;
|
||||
control.resetVertices();
|
||||
t.ok(control.radiusHandle != null, "Radius handle is set");
|
||||
t.eq(control.vertices.length, 0, "Correct vertices length with polygon (resize)");
|
||||
t.eq(control.vertices.length, 0, "Correct vertices length with polygon (RESIZE)");
|
||||
|
||||
control.mode = OpenLayers.Control.ModifyFeature.RESHAPE | OpenLayers.Control.ModifyFeature.RESIZE;
|
||||
control.resetVertices();
|
||||
t.ok(control.radiusHandle != null, "Radius handle is set");
|
||||
t.eq(control.vertices.length, 4, "Correct vertices length with polygon (RESHAPE | RESIZE)");
|
||||
t.eq(control.virtualVertices.length, 3, "Correct virtual vertices length (RESHAPE | RESIZE)");
|
||||
}
|
||||
|
||||
function test_ModifyFeature_onDrag(t) {
|
||||
|
||||
Reference in New Issue
Block a user