diff --git a/lib/OpenLayers/Control/ModifyFeature.js b/lib/OpenLayers/Control/ModifyFeature.js index 30eb7b5d16..89bae51ce0 100644 --- a/lib/OpenLayers/Control/ModifyFeature.js +++ b/lib/OpenLayers/Control/ModifyFeature.js @@ -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( diff --git a/tests/Control/ModifyFeature.html b/tests/Control/ModifyFeature.html index 8d04fd32ce..75de50970e 100644 --- a/tests/Control/ModifyFeature.html +++ b/tests/Control/ModifyFeature.html @@ -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}); @@ -662,7 +668,7 @@ log = []; control.selectFeature(f2); t.ok(control.feature === f2, "[select f2] control.feature set to f2"); - + // deactivate control and confirm feature is unselected control.deactivate(); t.eq(log.length, 1, "[deactivate] event logged"); @@ -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(); }