I'm trying to make the user click on the map to create new markers
For this I need to know where you clicked
I try this
methods:{
markernew(){
console.log(L.DomEvent.getMousePosition(LMap))
},
}
and try with
methods:{
markernew(){
console.log(L.DomEvent.getMousePosition('#map'))
},
}
but it returns me
Point {x: undefined, y: undefined}
Or if you already have something to create geofence
Leaflet will give you an event object on click. You just need to use it.
methods: {
addMarker(event) {
this.markers.push(event.latlng);
}
}
Sorry you have some complete example
I try this
<l-map @click="addMarker(this)" :center="center">
</l-map>
methods: {
addMarker(event) {
console.log(event.latlng)
//this.markers.push(event.latlng);
}
}
I get this in console
Uncaught TypeError: Cannot read property 'latlng' of null
methods: {
addMarker(event) {
console.log(event.latlng)
//this.markers.push(event.latlng);
}
}
Thanks @KoRiGaN its work
Very good work with vue2leaflet
Most helpful comment
methods: {
addMarker(event) {
console.log(event.latlng)
//this.markers.push(event.latlng);
}
}