Update menu
TODO: coords for sites
This commit is contained in:
42
webgis/js/controllers/marker_controller.js
Normal file
42
webgis/js/controllers/marker_controller.js
Normal file
@@ -0,0 +1,42 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,16 @@ export default class extends Controller {
|
||||
this.menuTarget.classList.add('is-hidden');
|
||||
}
|
||||
|
||||
openList(id) {
|
||||
document.querySelector(id).classList.remove('is-hidden');
|
||||
toggleList(id) {
|
||||
document.querySelector(`#${id}`).classList.toggle('is-hidden');
|
||||
}
|
||||
|
||||
openSubList(event) {
|
||||
const target = event.currentTarget;
|
||||
const targetIcon = target.querySelector('.fa');
|
||||
const id = target.getAttribute('data-list-id');
|
||||
this.toggleList(id);
|
||||
this.toggleIcon(targetIcon);
|
||||
}
|
||||
|
||||
toggle(event) {
|
||||
|
||||
@@ -11,4 +11,3 @@ export default class extends Controller {
|
||||
this.modalTarget.classList.remove('is-active');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user