[OpenLayers-Users] Drag cancellation ?

Eric Lemoine eric.c2c at gmail.com
Mon Jan 7 00:59:01 EST 2008


On Jan 5, 2008 7:13 PM, Attila Csipa <plists at prometheus.org.yu> wrote:
> I was writing functions for a DragFreature control and wanted to implement an
> undo/invalid choice type of feature, but I can't seem to find how to cancel a
> drag (if f.e. the drop location is found to be invalid in the onComplete
> function). I tried restoring geometry (which I saved in onStart) but that
> didn't quite work as expected (leaves me with 2 drawn features, on both new
> AND old locations, although the number of features in the layer has not
> changed) so I'm under the impression there is a simpler way of doing this or
> it's just that I can't see the forest from the tree...
>
> var undogeometry = null;
> var drag = new OpenLayers.Control.DragFeature(pointlayer,{
>                 onStart: function(feature, pixel)
>                 {
>                         undogeometry = feature.geometry.clone();
>                 },
>                 onComplete: function(feature, pixel)
>                 {
>                         if (invalid_loc(feature.geometry))
>                         {
>                                 feature.geometry.destroy();
>                                 feature.geometry = undogeometry.clone();
>                                 undogeometry.destroy();
>                                 feature.layer.redraw();
>                                 alert('Invalid location !');
>                         }
>                 }
>         });

Hi Attila

Off the top of my head: you could try to erase the feature before
calling layer.redraw() in the onComplete() callback. To erase the
feature use feature.layer.eraseFeatures([feature]).

--
Eric



More information about the Users mailing list