2

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.

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.