Leaflet / Path.Drag.js

Add dragging capability to Leaflet paths.
27 stars 14 forks source link

Fix bug: missing dragging after map is moved #4

Closed brandonxiang closed 8 years ago

brandonxiang commented 8 years ago

On the condition of preferCanvas in Leaflet 1.0, after I moved the map viewer, the dragging capability became disable.

I found out that the bug is caused by the error of this._startPoint in Line 21 of Path.Drag.js

this._startPoint = new L.Point(first.clientX, first.clientY);

A conversion is needed for the coordinate transformation from sreen coordinate to map layer coordinate.

Therefore, it should be replaced by this._path._map.mouseEventToLayerPoint.

this._startPoint = this._path._map.mouseEventToLayerPoint(first);
yohanboniface commented 8 years ago

Humm, but the offset is then computed with event coordinates, I'm not sure this will work. Can you be clearer in how to reproduce the issue? Maybe setting up a minimal example in http://playground-leaflet.rhcloud.com/ ?

brandonxiang commented 8 years ago

No problem.

http://playground-leaflet.rhcloud.com/ner/2/edit?html,output

All this problem is discussed in the L.canvas condition.

If I drag the triangle first, the triangle is draggable as usual.

If I drag the triangle first

However, if I move the map first, then the triangle will become undraggable. Only the map is moved.

movemapfirst

yohanboniface commented 8 years ago

OK, got it, thanks! Fix sounds good, but you then should also update here https://github.com/Leaflet/Path.Drag.js/pull/4/files#diff-50ed3b9a9a28a38d8a12041bc4d297daR69 to compare points on same reference.