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) {
|
||||
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(
|
||||
|
||||
@@ -612,7 +612,7 @@
|
||||
|
||||
function test_standalone(t) {
|
||||
|
||||
t.plan(13);
|
||||
t.plan(17);
|
||||
var map = new OpenLayers.Map("map");
|
||||
var layer = new OpenLayers.Layer.Vector();
|
||||
|
||||
@@ -622,7 +622,13 @@
|
||||
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))")
|
||||
);
|
||||
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);
|
||||
var control = new OpenLayers.Control.ModifyFeature(layer, {standalone: true});
|
||||
@@ -670,6 +676,24 @@
|
||||
t.ok(log[0].feature === f2, "[deactivate] correct feature");
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user