Skip to content

Commit

Permalink
Merge pull request #5025 from neo-garaix/red-ml-dep/popup-module
Browse files Browse the repository at this point in the history
Reduce mainLizmap dependencies in Popup module
  • Loading branch information
rldhont authored Dec 3, 2024
2 parents cb02310 + 1098cc4 commit 3962b38
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion assets/src/modules/Lizmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
50 changes: 34 additions & 16 deletions assets/src/modules/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;

Expand Down Expand Up @@ -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({
Expand All @@ -69,27 +87,27 @@ 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() {
return this._overlay;
}

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);
Expand All @@ -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;
});
Expand Down Expand Up @@ -141,19 +159,19 @@ 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]];
}

const wmsParams = {
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,
Expand Down

0 comments on commit 3962b38

Please sign in to comment.