33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
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;
|
|
map.removeLayer(GisState.baseLayers['Limiti amministrativi']);
|
|
map.removeLayer(GisState.cartography.buildings);
|
|
GisState.layers.walls.removeFrom(map);
|
|
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-border');
|
|
}
|
|
}
|