leaflet.js 484 B

123456789101112131415161718
  1. export default {
  2. template: "<div></div>",
  3. mounted() {
  4. this.map = L.map(this.$el);
  5. L.tileLayer("http://{s}.tile.osm.org/{z}/{x}/{y}.png").addTo(this.map);
  6. },
  7. methods: {
  8. set_location(latitude, longitude) {
  9. this.target = L.latLng(latitude, longitude);
  10. this.map.setView(this.target, 9);
  11. if (this.marker) {
  12. this.map.removeLayer(this.marker);
  13. }
  14. this.marker = L.marker(this.target);
  15. this.marker.addTo(this.map);
  16. },
  17. },
  18. };