import { Controller } from "@hotwired/stimulus" import { GisState } from '../state.js'; export default class extends Controller { static targets = ['bar']; closeView(event) { // Don't do anything if ESC keyboard event // is not fired from the building view if (event instanceof KeyboardEvent && !GisState.bViewActive) return; this.resetMap(); this.barTarget.remove(); GisState.bViewActive = false; } resetMap() { // Restore previous map state before closing view const map = GisState.map; // Hard-coded... map.removeLayer(GisState.baseLayers['Limiti amministrativi']); const walls = GisState.layers.walls; // 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)); map.addLayer(GisState.currentMapState.baseLayer); map.setMinZoom(GisState.currentMapState.minZoom); map.setMaxZoom(GisState.currentMapState.maxZoom); map.setView( GisState.currentMapState.center, GisState.currentMapState.zoom ); map._container.classList.remove('bview-active'); } }