hubertokf / vue2-leaflet-draw

MIT License
32 stars 25 forks source link

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

Open fdvsilva opened 3 years ago

fdvsilva commented 3 years ago

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?

trevelyanuk commented 3 years ago

@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());
    });
  },
};
fdvsilva commented 3 years ago

@trevelyanuk , thank you! It worked ;)