From bf4d277e626eb50bc00b53421a20ae0b8564d4c0 Mon Sep 17 00:00:00 2001 From: rldhont Date: Wed, 31 Jul 2024 13:24:24 +0200 Subject: [PATCH] [JavaScript] Remove mainLizmap from FeaturesTable module --- assets/src/modules/FeaturesTable.js | 18 ++++++++++++------ assets/src/modules/Lizmap.js | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/assets/src/modules/FeaturesTable.js b/assets/src/modules/FeaturesTable.js index f481d3e266..4ceb45c5a1 100644 --- a/assets/src/modules/FeaturesTable.js +++ b/assets/src/modules/FeaturesTable.js @@ -4,7 +4,7 @@ * @copyright 2024 3Liz * @license MPL-2.0 */ -import { mainLizmap, mainEventDispatcher } from '../modules/Globals.js'; +import { Config } from './Config.js'; import Utils from './Utils.js'; /** @@ -13,8 +13,14 @@ import Utils from './Utils.js'; */ export default class FeaturesTable { - constructor() { - + /** + * Create a features table instance + * @param {Config} initialConfig - The lizmap initial config instance + * @param {object} lizmap3 - The old lizmap object + */ + constructor(initialConfig, lizmap3) { + this._initialConfig = initialConfig; + this._lizmap3 = lizmap3; } /** @@ -69,7 +75,7 @@ export default class FeaturesTable { let previousMessage = document.getElementById('lizmap-features-table-message'); if (previousMessage) previousMessage.remove(); - mainLizmap.lizmap3.addMessage( + this._lizmap3.addMessage( message, type, true, duration ).attr('id', 'lizmap-features-table-message'); } @@ -88,10 +94,10 @@ export default class FeaturesTable { openPopup(layerId, feature, uniqueField, targetElement, aCallBack) { // Get the layer name & configuration - if (!mainLizmap.initialConfig.layers.layerIds.includes(layerId)) { + if (!this._initialConfig.layers.layerIds.includes(layerId)) { return null; } - const layerConfig = mainLizmap.initialConfig.layers.getLayerConfigByLayerId(layerId); + const layerConfig = this._initialConfig.layers.getLayerConfigByLayerId(layerId); const layerName = layerConfig.name; // Layer WMS name diff --git a/assets/src/modules/Lizmap.js b/assets/src/modules/Lizmap.js index f537e3055d..2132151761 100644 --- a/assets/src/modules/Lizmap.js +++ b/assets/src/modules/Lizmap.js @@ -148,7 +148,7 @@ export default class Lizmap { this.permalink = new Permalink(); this.map = new map('newOlMap', this.initialConfig, this.serviceURL, this.state.map, this.state.baseLayers, this.state.rootMapGroup, this.lizmap3); this.edition = new Edition(this.lizmap3); - this.featuresTable = new FeaturesTable(); + this.featuresTable = new FeaturesTable(this.initialConfig, this.lizmap3); this.geolocation = new Geolocation(this.map, this.lizmap3); this.geolocationSurvey = new GeolocationSurvey(this.geolocation, this.edition); this.selectionTool = new SelectionTool();