leaflet-paintpolygon icon indicating copy to clipboard operation
leaflet-paintpolygon copied to clipboard

Drawing over start of line deletes part of the line

Open Jakst3r opened this issue 6 years ago • 7 comments

This is an awesome plugin but there is one issue thats preventing me from using it.

When drawing it seems if you draw over that start of the line it deletes part of the line, I have linked a screen recording to help explain.

Video: https://youtu.be/AiDOzJPEdRs

Unrelated but after drawing for about 20 seconds chrome bug out and the page has to be reloaded.

Regards Jack

Jakst3r avatar Jun 15 '18 10:06 Jakst3r

Thanks for trying using it !

I've tried some optimization (stack event to process one by one, cache some values in variables) but bug seems to be style there.

I think this issue is related to https://github.com/Turfjs/turf/issues/1393 when 2 events are fired on the same latlng

tcoupin avatar Jun 17 '18 17:06 tcoupin

Difference is for erasing...

The turfjs lib has issue for union too: https://github.com/Turfjs/turf/issues/1209#issuecomment-354592272

tcoupin avatar Jun 17 '18 18:06 tcoupin

I reproduce the bug : https://www.youtube.com/watch?v=4orbvl_xyg0&feature=youtu.be

The 2 functions uses 'martinez-polygon-clipping' : https://github.com/w8r/martinez

tcoupin avatar Jun 17 '18 18:06 tcoupin

Hi @tcoupin thanks for your plugin. Are some updates for these issues? In particular, trying to use you demo page I see a lot of times the Chrome page crashes

gianluigiruggeri avatar Jul 17 '18 20:07 gianluigiruggeri

I'm guessing that @tcoupin wants to wait for the official v7 release of turfjs, which is built with a martinez version that fixes these bugs.

If you really need these bugs gone and don't care about potential other bugs, you can easily build this yourself with the v7-alpha by replacing the _draw function in PaintPolygon,js with:

_draw: function (latlng, zoom, radius) {
        if (this._data === undefined || this._data === null) {
            this.setData(this._getCircleAsPolygon(latlng, zoom, radius));
        } else {
            let fc = {
                type: "FeatureCollection",
                features:[this._data, this._getCircleAsPolygon(latlng, zoom, radius)]
            };
            this.setData(turf.union(fc));
        }
    }

replacing the myTurf.js with:

import circle from 'turf/src/circle';
import union from 'turf/src/union/';
import difference from 'turf/src/difference';


let turf = {
	circle: circle,
	union: union,
	difference: difference
};

export default turf;

and adding

"turf": "7.0.0-alpha.1"

to your package.json

lukszi avatar Mar 07 '19 07:03 lukszi

Sorry for delay, I am not an expert of Turf (@lukszi seems to be one ;) ) and I don't work no more with leaflet and geodata (only on my free time).

I just publish 1.2.1-alpha.1 based on turf 7.0.0-alpha.1 following @lukszi instructions.

tcoupin avatar Apr 13 '19 06:04 tcoupin

Hello, Do you have a solution to display the coordinates of the final polygon in a text area (textarea) or other Or as a message like "alert...." thanks

papajds avatar Mar 06 '22 15:03 papajds