Open stuporglue opened 7 years ago
It seems that the newly added vertext is immediately given the same event that was used to create the vertex.
The following patch allows drawing to work, but doesn't feel like it's the real fix.
Instead of immediately setting up the click handler for the last marker in the Polyline, this patch uses setTimeout to delay that. It seems that the timeout needs to be greater than 50ms to work at all, and higher values seem more reliable.
index fbb7877..c988d85 100644
--- a/src/draw/handler/Draw.Polyline.js
+++ b/src/draw/handler/Draw.Polyline.js
@@ -368,7 +368,13 @@ L.Draw.Polyline = L.Draw.Feature.extend({
var markerCount = this._markers.length;
// The last marker should have a click handler to close the polyline
if (markerCount > 1) {
- this._markers[markerCount - 1].on('click', this._finishShape, this);
+ setTimeout(function(){
+ if ( this._markers === undefined ) {
+ return;
+ }
+
+ this._markers[this._markers.length - 1].on('click', this._finishShape, this);
+ }.bind(this), 75);
}
// Remove the old marker click handler (as only the last point should close the polyline)
This bug is worse than simply ending after two lines. If you click "wrong" the first time, you'll end up with a point rather than a polyline, which is an invalid geometry.
More observations:
Error: shape edges cannot cross!
(but after second point all get right).We can get rid of polyline issue if we disable TouchExtend
handler (create map with touchExtend: false
option).
It is still can be workarounded with some tricks:
Edit: this workaround is not good for iOS
Workaround: #926
It seems related to #695 (fix included)
Hi @johnd0e I am also experiencing below issue
When placing 1st point it's often shown non-zero distance. Perhaps similar issue is with polygon: when placing first point we get red tooltip Error: shape edges cannot cross! (but after second point all get right).
were you able to resolve this ?
Sure, read from this: https://github.com/Leaflet/Leaflet.draw/issues/695#issuecomment-577151966
I don't think that this is the same as the other touch issues that have been reported, but I could be wrong.
How to reproduce
Environment
Steps
On OSX, in Chrome
The steps to reproduce this on Android are the same, except you don't have to enable dev tools since you're already in a touch enabled browser.
What behaviour I'm expecting and which behaviour I'm seeing
I expect to be able to continue to add points.
Instead, the polyline completes after the second click.
Minimal example reproducing the issue
http://leaflet.github.io/Leaflet.draw/docs/examples/full.html