In standalone mode, allow only dragging of sketch vertices or the point
selected for modification. Thanks tschaub for the improved patch. r=tschaub (closes #2219) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9613 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -236,6 +236,22 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
},
|
},
|
||||||
onComplete: function(feature) {
|
onComplete: function(feature) {
|
||||||
control.dragComplete.apply(control, [feature]);
|
control.dragComplete.apply(control, [feature]);
|
||||||
|
},
|
||||||
|
featureCallbacks: {
|
||||||
|
over: function(feature) {
|
||||||
|
/**
|
||||||
|
* In normal mode, the feature handler is set up to allow
|
||||||
|
* dragging of all points. In standalone mode, we only
|
||||||
|
* want to allow dragging of sketch vertices and virtual
|
||||||
|
* vertices - or, in the case of a modifiable point, the
|
||||||
|
* point itself.
|
||||||
|
*/
|
||||||
|
if(control.standalone !== true || feature._sketch ||
|
||||||
|
control.feature === feature) {
|
||||||
|
control.dragControl.overFeature.apply(
|
||||||
|
control.dragControl, [feature]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.dragControl = new OpenLayers.Control.DragFeature(
|
this.dragControl = new OpenLayers.Control.DragFeature(
|
||||||
|
|||||||
@@ -612,7 +612,7 @@
|
|||||||
|
|
||||||
function test_standalone(t) {
|
function test_standalone(t) {
|
||||||
|
|
||||||
t.plan(13);
|
t.plan(17);
|
||||||
var map = new OpenLayers.Map("map");
|
var map = new OpenLayers.Map("map");
|
||||||
var layer = new OpenLayers.Layer.Vector();
|
var layer = new OpenLayers.Layer.Vector();
|
||||||
|
|
||||||
@@ -622,7 +622,13 @@
|
|||||||
var f2 = new OpenLayers.Feature.Vector(
|
var f2 = new OpenLayers.Feature.Vector(
|
||||||
OpenLayers.Geometry.fromWKT("POLYGON((1 1,5 1,5 5,1 5,1 1),(2 2, 3 2, 3 3, 2 3,2 2))")
|
OpenLayers.Geometry.fromWKT("POLYGON((1 1,5 1,5 5,1 5,1 1),(2 2, 3 2, 3 3, 2 3,2 2))")
|
||||||
);
|
);
|
||||||
layer.addFeatures([f1, f2]);
|
var f3 = new OpenLayers.Feature.Vector(
|
||||||
|
OpenLayers.Geometry.fromWKT("POINT(10 15)")
|
||||||
|
);
|
||||||
|
var f4 = new OpenLayers.Feature.Vector(
|
||||||
|
OpenLayers.Geometry.fromWKT("POINT(15 10)")
|
||||||
|
);
|
||||||
|
layer.addFeatures([f1, f2, f3, f4]);
|
||||||
|
|
||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
var control = new OpenLayers.Control.ModifyFeature(layer, {standalone: true});
|
var control = new OpenLayers.Control.ModifyFeature(layer, {standalone: true});
|
||||||
@@ -662,7 +668,7 @@
|
|||||||
log = [];
|
log = [];
|
||||||
control.selectFeature(f2);
|
control.selectFeature(f2);
|
||||||
t.ok(control.feature === f2, "[select f2] control.feature set to f2");
|
t.ok(control.feature === f2, "[select f2] control.feature set to f2");
|
||||||
|
|
||||||
// deactivate control and confirm feature is unselected
|
// deactivate control and confirm feature is unselected
|
||||||
control.deactivate();
|
control.deactivate();
|
||||||
t.eq(log.length, 1, "[deactivate] event logged");
|
t.eq(log.length, 1, "[deactivate] event logged");
|
||||||
@@ -670,6 +676,24 @@
|
|||||||
t.ok(log[0].feature === f2, "[deactivate] correct feature");
|
t.ok(log[0].feature === f2, "[deactivate] correct feature");
|
||||||
t.eq(log[0].modified, false, "[deactivate] feature not actually modified");
|
t.eq(log[0].modified, false, "[deactivate] feature not actually modified");
|
||||||
|
|
||||||
|
// reactivate control and select a point feature to see if we can drag
|
||||||
|
// another point feature;
|
||||||
|
control.activate();
|
||||||
|
control.selectFeature(f3);
|
||||||
|
control.dragControl.handlers.feature.triggerCallback("mousemove", "in", [f4]);
|
||||||
|
t.eq(control.dragControl.handlers.drag.active, false, "cannot drag unselected feature f4");
|
||||||
|
control.dragControl.handlers.feature.triggerCallback("mousemove", "in", [f3]);
|
||||||
|
t.eq(control.dragControl.handlers.drag.active, true, "can drag selected feature f3");
|
||||||
|
|
||||||
|
// select the polygon feature to make sure that we can drag vertices and
|
||||||
|
// virtual vertices
|
||||||
|
control.selectFeature(f2);
|
||||||
|
control.dragControl.handlers.feature.triggerCallback("mousemove", "in", [control.vertices[0]]);
|
||||||
|
t.eq(control.dragControl.handlers.drag.active, true, "can drag vertex of feature f2");
|
||||||
|
control.dragControl.handlers.feature.triggerCallback("mousemove", "in", [control.virtualVertices[0]]);
|
||||||
|
t.eq(control.dragControl.handlers.drag.active, true, "can drag virtual vertex of feature f2");
|
||||||
|
control.deactivate();
|
||||||
|
|
||||||
map.destroy();
|
map.destroy();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user