From 1098cc46afff7b59bccbf215434fd72596844808 Mon Sep 17 00:00:00 2001 From: neo Date: Fri, 29 Nov 2024 12:29:19 +0100 Subject: [PATCH] UPDATE: Remove mainLizmap --- assets/src/modules/Lizmap.js | 2 +- assets/src/modules/Popup.js | 50 ++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/assets/src/modules/Lizmap.js b/assets/src/modules/Lizmap.js index 351583288f..cdd880d483 100644 --- a/assets/src/modules/Lizmap.js +++ b/assets/src/modules/Lizmap.js @@ -163,7 +163,7 @@ export default class Lizmap { this.wms = new WMS(); this.action = new Action(); this.featureStorage = new FeatureStorage(); - this.popup = new Popup(); + this.popup = new Popup(this.initialConfig, this.state, this.map, this.digitizing); this.legend = new Legend(this.state.layerTree); this.search = new Search(); this.tooltip = new Tooltip(); diff --git a/assets/src/modules/Popup.js b/assets/src/modules/Popup.js index d03badbc6f..44f474b6f2 100644 --- a/assets/src/modules/Popup.js +++ b/assets/src/modules/Popup.js @@ -6,7 +6,6 @@ */ -import { mainLizmap } from '../modules/Globals.js'; import Overlay from 'ol/Overlay.js'; import WMS from '../modules/WMS.js'; import Utils from '../modules/Utils.js'; @@ -16,7 +15,26 @@ import Utils from '../modules/Utils.js'; * @name Popup */ export default class Popup { - constructor() { + + /** + * Create a popup instance + * + * @param {Config} initialConfig - The lizmap initial config instance + * @param {State} lizmapState - The lizmap user interface state + * @param {Map} map - OpenLayers map + * @param {Digitizing} digitizing - The Lizmap digitizing instance + */ + constructor(initialConfig, lizmapState, map, digitizing) { + + this._initialConfig = initialConfig; + this._lizmapState = lizmapState; + this._map = map; + this._digitizing = digitizing; + + this._pointTolerance = initialConfig.options?.pointTolerance || 25; + this._lineTolerance = initialConfig.options?.lineTolerance || 10; + this._polygonTolerance = initialConfig.options?.polygonTolerance || 5; + // Allow toggling of active state this.active = true; @@ -57,7 +75,7 @@ export default class Popup { */ document.getElementById('liz_layer_popup_closer').onclick = () => { this._overlay.setPosition(undefined); - mainLizmap.map.clearHighlightFeatures(); + this._map.clearHighlightFeatures(); return false; }; this._overlay = new Overlay({ @@ -69,8 +87,8 @@ export default class Popup { }, }); - mainLizmap.map.addOverlay(this._overlay); - mainLizmap.map.on('singleclick', evt => this.handleClickOnMap(evt)); + this._map.addOverlay(this._overlay); + this._map.on('singleclick', evt => this.handleClickOnMap(evt)); } get mapPopup() { @@ -78,18 +96,18 @@ export default class Popup { } handleClickOnMap(evt) { - const pointTolerance = mainLizmap.config.options?.pointTolerance || 25; - const lineTolerance = mainLizmap.config.options?.lineTolerance || 10; - const polygonTolerance = mainLizmap.config.options?.polygonTolerance || 5; + const pointTolerance = this._pointTolerance; + const lineTolerance = this._lineTolerance; + const polygonTolerance = this._polygonTolerance; - if (!this.active || lizMap.editionPending || mainLizmap.digitizing.toolSelected != 'deactivate' || mainLizmap.digitizing.isEdited || mainLizmap.digitizing.isErasing) { + if (!this.active || lizMap.editionPending || this._digitizing.toolSelected != 'deactivate' || this._digitizing.isEdited || this._digitizing.isErasing) { return; } const xCoord = evt?.xy?.x || evt?.pixel?.[0]; const yCoord = evt?.xy?.y || evt?.pixel?.[1]; - let candidateLayers = mainLizmap.state.rootMapGroup.findMapLayers().reverse(); + let candidateLayers = this._lizmapState.rootMapGroup.findMapLayers().reverse(); // Only request visible layers candidateLayers = candidateLayers.filter(layer => layer.visibility); @@ -101,8 +119,8 @@ export default class Popup { let editionLayerCapabilities; - if (mainLizmap.initialConfig?.editionLayers?.layerNames.includes(layer.name)) { - editionLayerCapabilities = mainLizmap.initialConfig?.editionLayers?.getLayerConfigByLayerName(layer.name)?.capabilities; + if (this._initialConfig?.editionLayers?.layerNames.includes(layer.name)) { + editionLayerCapabilities = this._initialConfig?.editionLayers?.getLayerConfigByLayerName(layer.name)?.capabilities; } return layerCfg.popup || editionLayerCapabilities?.modifyAttribute || editionLayerCapabilities?.modifyGeometry || editionLayerCapabilities?.deleteFeature; }); @@ -141,11 +159,11 @@ export default class Popup { const wms = new WMS(); - const [width, height] = lizMap.mainLizmap.map.getSize(); + const [width, height] = this._map.getSize(); - let bbox = mainLizmap.map.getView().calculateExtent(); + let bbox = this._map.getView().calculateExtent(); - if (mainLizmap.map.getView().getProjection().getAxisOrientation().substring(0, 2) === 'ne') { + if (this._map.getView().getProjection().getAxisOrientation().substring(0, 2) === 'ne') { bbox = [bbox[1], bbox[0], bbox[3], bbox[2]]; } @@ -153,7 +171,7 @@ export default class Popup { QUERY_LAYERS: layersNames.join(','), LAYERS: layersNames.join(','), STYLE: layersStyles.join(','), - CRS: mainLizmap.projection, + CRS: this._map.getView().getProjection().getCode(), BBOX: bbox, WIDTH: width, HEIGHT: height,