문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top