Question

I'm using OpenLayers and I have already found the implementation of dragging a marker, but there's no documentation about how to return the dragged position. I've tried this:

drag = new OpenLayers.Control.DragFeature(vectors, {
  autoActivate: true,
  onComplete: function () {
    alert('hello')
  }
});

It doesn't return which marker was dragged so I can't get its longitude or latitude after dragging.

Was it helpful?

Solution

Actually the official documentation clearly states that the first argument to the onComplete callback is the affected feature. You can easily inspect its features in the handler.

For an example go to http://dev.openlayers.org/examples/drag-feature.html, open your browser's JS console and execute this snippet:

map.addControl(new OpenLayers.Control.DragFeature(vectors, {
  autoActivate: true,
  onComplete: function (feature) {
    alert('x=' + feature.geometry.x + ', y=' + feature.geometry.x);
  }
}));

Then add a point and try dragging it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top