No point layers in control; add visibility toggle in menu

This commit is contained in:
2025-02-10 15:07:13 +01:00
parent be6398b1aa
commit 64af485a54
5 changed files with 97 additions and 28 deletions

View File

@@ -0,0 +1,44 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ['sites', 'findings', 'notconserved', 'prehist',];
/**
* @param {Event} event
*/
toggle(event) {
let map = window.LMap;
let target = event.currentTarget;
const id = target.parentElement.getAttribute('data-id');
const layers = {
'siti': window.Sites,
'non-conser': window.NotConserved,
'rinv': window.Findings,
'preist': window.Prehistoric,
}
let group = layers[id];
this.toggleIcon(event.currentTarget);
if (map.hasLayer(group)) {
map.removeLayer(group);
target.title = "Mostra";
}
else {
map.addLayer(group);
target.title = "Nascondi";
}
}
/**
* Toggle visibility icon...
* @param {HTMLElement} target
*/
toggleIcon(target) {
const icon = target.firstElementChild;
const className = icon.className;
icon.className = className.includes('slash') ?
className.replace('-slash', '') :
className.replace('eye', 'eye-slash');
}
}

View File

@@ -9,6 +9,9 @@ export default class extends Controller {
easeLinearity: 0.25
};
/**
* @param {Event} event
*/
go(event) {
let map = window.LMap;
const coords = event.currentTarget
@@ -44,4 +47,3 @@ export default class extends Controller {
return marker;
}
}