Home > Back-end >  How to add a marker by clicking on the map in leaflet js on vue 3
How to add a marker by clicking on the map in leaflet js on vue 3

Time:01-06

Hi guys I have such a problem Can't get click coordinates to generate a new Marker

enter image description here enter image description here

CodePudding user response:

The click handler should be @click="save", not @:click="save"

CodePudding user response:

If you want to get the click coordinates, you should declare your save function like so:

function save(event) {
console.log(event.clientX, event.clientY)
}

And if you want to get those click coordinates relative to the map, you can use the following code:

      const map = event.target.getBoundingClientRect();
      const x = event.clientX - map.left
      const y = event.clientY - map.top;
      console.log(x, y)

  • Related