The modify feature control destroys the vertex that was dragged in the drag

complete callback. Thus, the drag feature control won't detect a mouse-out on
that vertex and won't deactivate its drag handler. This causes errors because
the drag feature control has a feature to drag but that feature is destroyed
(feature.geometry is null). To prevent this, we make resetVertices explicitely
call outFeature on the drag feature control if the control has a feature to
drag. tschaub did most of the investigation on the problem. r=tschaub,me
(closes #1235)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@5974 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2008-02-03 17:10:03 +00:00
parent 5a176d7852
commit 3acc19ae3d
2 changed files with 26 additions and 1 deletions

View File

@@ -428,6 +428,16 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
* Method: resetVertices * Method: resetVertices
*/ */
resetVertices: function() { resetVertices: function() {
// if coming from a drag complete we're about to destroy the vertex
// that was just dragged. For that reason, the drag feature control
// will never detect a mouse-out on that vertex, meaning that the drag
// handler won't be deactivated. This can cause errors because the drag
// feature control still has a feature to drag but that feature is
// destroyed. To prevent this, we call outFeature on the drag feature
// control if the control actually has a feature to drag.
if(this.dragControl.feature) {
this.dragControl.outFeature(this.dragControl.feature);
}
if(this.vertices.length > 0) { if(this.vertices.length > 0) {
this.layer.removeFeatures(this.vertices); this.layer.removeFeatures(this.vertices);
this.vertices = []; this.vertices = [];

View File

@@ -249,7 +249,7 @@
} }
function test_ModifyFeature_resetVertices(t) { function test_ModifyFeature_resetVertices(t) {
t.plan(17); t.plan(18);
var layer = new OpenLayers.Layer.Vector(); var layer = new OpenLayers.Layer.Vector();
var control = new OpenLayers.Control.ModifyFeature(layer); var control = new OpenLayers.Control.ModifyFeature(layer);
var point = new OpenLayers.Geometry.Point(5,6); var point = new OpenLayers.Geometry.Point(5,6);
@@ -299,6 +299,21 @@
t.ok(control.radiusHandle != null, "Radius handle is set"); t.ok(control.radiusHandle != null, "Radius handle is set");
t.eq(control.vertices.length, 3, "Correct vertices length with polygon (RESHAPE | RESIZE)"); t.eq(control.vertices.length, 3, "Correct vertices length with polygon (RESHAPE | RESIZE)");
t.eq(control.virtualVertices.length, 3, "Correct virtual vertices length (RESHAPE | RESIZE)"); t.eq(control.virtualVertices.length, 3, "Correct virtual vertices length (RESHAPE | RESIZE)");
control.dragControl.feature = new OpenLayers.Feature.Vector(polygon);
control.dragControl.map = {};
control.dragControl.map.div = {};
control.dragControl.map.div.style = {};
control.dragControl.map.div.cursor = "foo";
control.dragControl.dragHandler.deactivate = function() {
this.active = false;
}
control.resetVertices();
t.ok(!control.dragControl.dragHandler.active, "resetVertices deactivates drag handler");
control.dragControl.map = null;
control.destroy();
layer.destroy();
} }
function test_ModifyFeature_onDrag(t) { function test_ModifyFeature_onDrag(t) {