leolmq
leolmq

Reputation: 261

How to handle click when using Vue2Leaflet?

I am using Vue2Leaflet(https://github.com/KoRiGaN/Vue2Leaflet) with vuejs2, I already render the map, and I want to add a function to handle when click the map, as I read the document https://korigan.github.io/Vue2Leaflet/#/ but still don't how to do.

Any advice would be appreciated.

Upvotes: 2

Views: 896

Answers (1)

Vadim Gremyachev
Vadim Gremyachev

Reputation: 59318

The following example demonstrates how handle map click event in Vue2Leaflet:

<l-map :zoom="zoom" :center="center" @click="handleMapClick">
   <l-tile-layer :url="url" :attribution="attribution"></l-tile-layer>
</l-map>



export default {
  name: "LeafletMap",
  components: {
    "l-map": LMap,
    "l-tile-layer": LTileLayer,
    "l-marker": LMarker
  },
  data() {
    return {
      zoom: 13,
      center: L.latLng(47.41322, -1.219482),
      url: "http://{s}.tile.osm.org/{z}/{x}/{y}.png",
      attribution:
        '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
    };
  },

  methods: {
    handleMapClick(event) {
       //...
    }
  }
};

Here is a demo

Upvotes: 3

Related Questions