Leaflet / Leaflet.Editable

Make geometries editable in Leaflet.
http://leaflet.github.io/Leaflet.Editable/doc/api.html
553 stars 198 forks source link

get marker coordinate #186

Open meteerogl opened 5 years ago

meteerogl commented 5 years ago

I want to collect line point (markers) coordinates. how can ı do.

kajeagentspi commented 5 years ago

If you are just using the map to add markers only you can do this. `this.mapInstance.on('editable:drawing:end', (event) => { console.log(event.layer.getLatLng()) })`

However if you are using the map to draw Polylines or other shapes. You'll get an error using that. I am still looking for a way to get the layer type.

This should do the trick

this.mapInstance.on('editable:drawing:end', ({ layer }) => {
      if (layer instanceof L.Marker) {
        console.log(layer.getLatLng())
      } else if (layer instanceof L.Polyline) {
        console.log(layer.getLatLngs())
      }
    })
meteerogl commented 5 years ago

thamks this solution worked

meteerogl commented 5 years ago

also ı have another question. İf change marker position. the data doesnt be change. how can get live marker position data....

kajeagentspi commented 5 years ago

Try changing editable:drawing:end to other events from this page. http://leaflet.github.io/Leaflet.Editable/doc/api.html