No point layers in control; add visibility toggle in menu
This commit is contained in:
44
webgis/js/controllers/layer_controller.js
Normal file
44
webgis/js/controllers/layer_controller.js
Normal 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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user