Refine building view dynamics
This commit is contained in:
@@ -1,13 +1,41 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
import { GisState } from '../state.js';
|
||||
import { TECH_LAYERS } from "../map.js";
|
||||
|
||||
const LEGEND_DEF = [
|
||||
"puntatore",
|
||||
"icona",
|
||||
];
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ['bar', 'legend'];
|
||||
|
||||
openView() {
|
||||
const map = GisState.map;
|
||||
// Remove all other layers first!
|
||||
for (const key of Object.keys(GisState.layers)) {
|
||||
if (GisState.layers[key] instanceof L.Layer && key !== 'geometries') {
|
||||
map.removeLayer(GisState.layers[key]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @type {string[]}
|
||||
*/
|
||||
const currentTechs = [...TECH_LAYERS[GisState.currentBView], ...LEGEND_DEF];
|
||||
this.barTarget.classList.remove('is-hidden');
|
||||
this.legendTarget.classList.remove('is-hidden');
|
||||
GisState.map._container.classList.add('bview-active');
|
||||
|
||||
/**
|
||||
* @type {HTMLDivElement}
|
||||
*/
|
||||
const legend = this.legendTarget;
|
||||
const items = legend.querySelectorAll('li');
|
||||
|
||||
for (let item of items) {
|
||||
if (!currentTechs.includes(item.id)) item.classList.add('is-hidden');
|
||||
}
|
||||
|
||||
legend.classList.remove('is-hidden');
|
||||
map._container.classList.add('bview-active');
|
||||
}
|
||||
|
||||
closeView(event) {
|
||||
@@ -15,13 +43,13 @@ export default class extends Controller {
|
||||
// is not fired from the building view
|
||||
if (event instanceof KeyboardEvent && !GisState.bViewActive) return;
|
||||
|
||||
this.resetMap();
|
||||
this.reset();
|
||||
this.barTarget.classList.add('is-hidden');
|
||||
this.legendTarget.classList.add('is-hidden');
|
||||
GisState.bViewActive = false;
|
||||
}
|
||||
|
||||
resetMap() {
|
||||
reset() {
|
||||
// Restore previous map state before closing view
|
||||
const map = GisState.map;
|
||||
// Hard-coded...
|
||||
@@ -29,6 +57,14 @@ export default class extends Controller {
|
||||
|
||||
const walls = GisState.layers.walls;
|
||||
|
||||
// Re-add all layers first (except techniques)! (TODO: Should this be filtered by map state??)
|
||||
for (const key of Object.keys(GisState.layers)) {
|
||||
if (GisState.layers[key] instanceof L.Layer
|
||||
&& key !== 'geometries'
|
||||
&& key !== 'buildingTechs') {
|
||||
map.addLayer(GisState.layers[key]);
|
||||
}
|
||||
}
|
||||
// map.removeLayer(GisState.layers.walls) doesn't work, i.e.
|
||||
// it doesn't remove the layer group (fails silently)
|
||||
walls.eachLayer(layer => map.removeLayer(layer));
|
||||
@@ -41,5 +77,14 @@ export default class extends Controller {
|
||||
GisState.currentMapState.zoom
|
||||
);
|
||||
map._container.classList.remove('bview-active');
|
||||
/**
|
||||
* @type {HTMLDivElement}
|
||||
*/
|
||||
const legend = this.legendTarget;
|
||||
const items = legend.querySelectorAll('li');
|
||||
|
||||
for (let item of items) {
|
||||
item.classList.remove('is-hidden');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user