leaflet.js 599 B

1234567891011121314151617181920
  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", {
  6. attribution: '&copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>',
  7. }).addTo(this.map);
  8. },
  9. methods: {
  10. set_location(latitude, longitude) {
  11. this.target = L.latLng(latitude, longitude);
  12. this.map.setView(this.target, 9);
  13. if (this.marker) {
  14. this.map.removeLayer(this.marker);
  15. }
  16. this.marker = L.marker(this.target);
  17. this.marker.addTo(this.map);
  18. },
  19. },
  20. };