Skip to content

Commit

Permalink
Merge pull request #5024 from neo-garaix/red-ml-dep/legend-module
Browse files Browse the repository at this point in the history
Reduce mainLizmap dependencies in Legend module
  • Loading branch information
rldhont authored Dec 2, 2024
2 parents dbd0133 + dd9daf2 commit 6d72c72
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions assets/src/modules/Legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @license MPL-2.0
*/

import { mainLizmap } from './Globals.js';
import { LayerTreeGroupState } from '../modules/state/LayerTree.js'
import { updateLayerTreeLayerSymbology, updateLayerTreeGroupLayersSymbology } from '../modules/action/Symbology.js';

/**
Expand All @@ -14,18 +14,22 @@ import { updateLayerTreeLayerSymbology, updateLayerTreeGroupLayersSymbology } fr
*/
export default class Legend {

constructor() {
/**
* Create a legend instance
* @param {LayerTreeGroupState} layerTree - Root tree layer group
*/
constructor(layerTree) {
// Init all symbologies
if(mainLizmap.state.layerTree.childrenCount === 0){
if(layerTree.childrenCount === 0){
return;
}

updateLayerTreeGroupLayersSymbology(mainLizmap.state.layerTree);
updateLayerTreeGroupLayersSymbology(layerTree);

// Refresh symbology when a layer's style changes
mainLizmap.state.rootMapGroup.addListener(
layerTree.addListener(
evt => {
updateLayerTreeLayerSymbology(mainLizmap.state.layerTree.getTreeLayerByName(evt.name));
updateLayerTreeLayerSymbology(layerTree.getTreeLayerByName(evt.name));
},['layer.style.changed']
);
}
Expand Down
2 changes: 1 addition & 1 deletion assets/src/modules/Lizmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export default class Lizmap {
this.action = new Action();
this.featureStorage = new FeatureStorage();
this.popup = new Popup();
this.legend = new Legend();
this.legend = new Legend(this.state.layerTree);
this.search = new Search();
this.tooltip = new Tooltip();

Expand Down

0 comments on commit 6d72c72

Please sign in to comment.