vue2-leaflet-draw icon indicating copy to clipboard operation
vue2-leaflet-draw copied to clipboard

On draw:created event for a polygon does not provide its coordinates.

Open fdvsilva opened this issue 3 years ago • 2 comments

Unlike happens when you create a rectangle, circle or a line you are not being provided with the polygon coordinates in the corresponding event.

{layer: NewClass, layerType: "polygon", type: "draw:created", target: NewClass, sourceTarget: NewClass}
layer: NewClass
layerType: "polygon"
sourceTarget: NewClass
target: NewClass
type: "draw:created"

I did not want to use the standard leaflet plugin for enable the draw functionality given that I have been able to get the most out of this project except for this little detail that is preventing me from deploying my app.

Can you point me in the right direction for overcoming this issue?

fdvsilva avatar Mar 04 '21 01:03 fdvsilva

@fdvsilva - you should be able to get to coordinates from layer with getLatLngs().

Assuming that your l-map component has ref:"map" on it, try this:

mounted() {
    this.map = this.$refs.map;
    this.map.mapObject.on('draw:created', (e) => {
      console.log(e.layer.getLatLngs());
    });
  },
};

trevelyanuk avatar Apr 21 '21 08:04 trevelyanuk

@trevelyanuk , thank you! It worked ;)

fdvsilva avatar Apr 21 '21 11:04 fdvsilva