Vue2leaflet: Get mouse position on the map

Created on 28 May 2018  路  4Comments  路  Source: vue-leaflet/Vue2Leaflet

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

Most helpful comment



methods: {
addMarker(event) {
console.log(event.latlng)
//this.markers.push(event.latlng);
}
}

All 4 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mnboos picture mnboos  路  3Comments

digEmAll picture digEmAll  路  4Comments

tiltec picture tiltec  路  4Comments

lufias picture lufias  路  3Comments

srtonz picture srtonz  路  4Comments