caprigis/webgis/js/controllers/marker_controller.js
Nicolò P 7f4bd571f0 Update menu
TODO: coords for sites
2024-11-27 13:52:28 +01:00

43 lines
1004 B
JavaScript

import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ['coords'];
mapAnimate = {
animate: true,
duration: 1,
easeLinearity: 0.25
};
go(event) {
let map = window.LMap;
const coords = event.currentTarget.getAttribute('data-coords').split(' ');
map.setView(
coords,
19,
this.mapAnimate
);
let marker = this.getMarker(map, coords);
marker.openTooltip();
}
getMarker(map, coords) {
let marker;
map.eachLayer(l => {
if (l instanceof L.Marker) {
const latLng = l.getLatLng();
const lat = latLng['lat'];
const lng = latLng['lng'];
if (lat === Number(coords[0]) && lng === Number(coords[1])) {
marker = l;
return;
}
}
});
return marker;
}
}