geoman-io / leaflet-geoman

🍂🗺️ The most powerful leaflet plugin for drawing and editing geometry layers
https://geoman.io
MIT License
2.21k stars 433 forks source link

Issue on edit LatLongs programmatically #914

Closed contibru closed 3 years ago

contibru commented 3 years ago

Hey everyone, I notice a problem when I change de coordinates of a polygon programmatically. The vertices remain in map. This code bellow doesn`t allow the user overllaping a polygon into another.

This is the code:

let intersection = turf.intersect(overlay.toGeoJSON(), this.polygon.toGeoJSON());
if (intersection) {
        const diff = turf.difference(this.polygon.toGeoJSON(), intersection);
        const path = L.GeoJSON.coordsToLatLngs(diff.geometry.coordinates, 1);
        this.polygon.setLatLngs(path);
}

A gif showing the problem:

polygon

Falke-Design commented 3 years ago

We can't detect if a layer is moved / changed programmatically, look for this into: #308

You can use the interal functions of Geoman to re-render the vertex markers:

      layer.setLatLngs(coords);
      // re-enable markers for the new coords
      layer.pm._initMarkers();

With layer.pm._handleLayerStyle(true); you can flash the layer red, if you want this.

contibru commented 3 years ago

Thank`s @Falke-Design , it works like a charm.

Is there a way to put this function external? I ask that because the vs code keep sayng that function doesn`t exist.

image

contibru commented 3 years ago

So, I used this to avoid the error for now.

// @ts-ignore
this.polygon.pm._initMarkers();
SellingSystems commented 2 years ago

How would this work with a marker? I am allowing the user to either drag the marker or enter new coords which are used in a setLatLng command. When I try to drag the marker after updating the position with a setLatLng it snaps back to the position it was at before the setLatLng. I have tried using toggleEdit and disabling and enabling PM but it doesn't seem to help.