Skip to content

Commit 8f07dfc

Browse files
committed
JS: Main Event lizmap.modules.initialized
1 parent 9975250 commit 8f07dfc

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

assets/src/index.js

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,30 @@ const waitFor = async function waitFor(maxWait, sleepStep, f){
5454
return waitingTime;
5555
};
5656

57+
const definedCustomElements = () => {
58+
window.customElements.define('lizmap-geolocation', Geolocation);
59+
window.customElements.define('lizmap-geolocation-survey', GeolocationSurvey);
60+
window.customElements.define('lizmap-features-table', FeaturesTable);
61+
window.customElements.define('lizmap-selection-tool', SelectionTool);
62+
window.customElements.define('lizmap-selection-invert', SelectionInvert);
63+
window.customElements.define('lizmap-snapping', Snapping);
64+
window.customElements.define('lizmap-scaleline', Scaleline);
65+
window.customElements.define('lizmap-mouse-position', MousePosition);
66+
window.customElements.define('lizmap-digitizing', Digitizing);
67+
window.customElements.define('lizmap-overviewmap', OverviewMap);
68+
window.customElements.define('lizmap-feature-toolbar', FeatureToolbar);
69+
window.customElements.define('lizmap-reverse-geom', ReverseGeom);
70+
window.customElements.define('lizmap-paste-geom', PasteGeom);
71+
window.customElements.define('lizmap-action-selector', ActionSelector);
72+
window.customElements.define('lizmap-print', Print);
73+
window.customElements.define('lizmap-fullscreen', FullScreen);
74+
window.customElements.define('lizmap-base-layers', BaseLayers);
75+
window.customElements.define('lizmap-treeview', Treeview);
76+
window.customElements.define('lizmap-navbar', NavBar);
77+
window.customElements.define('lizmap-tooltip', Tooltip);
78+
window.customElements.define('lizmap-message', Message);
79+
}
80+
5781
/**
5882
* Init Lizmap application
5983
* This function is called when the Lizmap application is ready to be initialized.
@@ -74,27 +98,14 @@ const initLizmapApp = () => {
7498

7599
},
76100
uicreated: () => {
77-
window.customElements.define('lizmap-geolocation', Geolocation);
78-
window.customElements.define('lizmap-geolocation-survey', GeolocationSurvey);
79-
window.customElements.define('lizmap-features-table', FeaturesTable);
80-
window.customElements.define('lizmap-selection-tool', SelectionTool);
81-
window.customElements.define('lizmap-selection-invert', SelectionInvert);
82-
window.customElements.define('lizmap-snapping', Snapping);
83-
window.customElements.define('lizmap-scaleline', Scaleline);
84-
window.customElements.define('lizmap-mouse-position', MousePosition);
85-
window.customElements.define('lizmap-digitizing', Digitizing);
86-
window.customElements.define('lizmap-overviewmap', OverviewMap);
87-
window.customElements.define('lizmap-feature-toolbar', FeatureToolbar);
88-
window.customElements.define('lizmap-reverse-geom', ReverseGeom);
89-
window.customElements.define('lizmap-paste-geom', PasteGeom);
90-
window.customElements.define('lizmap-action-selector', ActionSelector);
91-
window.customElements.define('lizmap-print', Print);
92-
window.customElements.define('lizmap-fullscreen', FullScreen);
93-
window.customElements.define('lizmap-base-layers', BaseLayers);
94-
window.customElements.define('lizmap-treeview', Treeview);
95-
window.customElements.define('lizmap-navbar', NavBar);
96-
window.customElements.define('lizmap-tooltip', Tooltip);
97-
window.customElements.define('lizmap-message', Message);
101+
if (lizMap.mainLizmap.legend !== undefined) {
102+
definedCustomElements();
103+
} else {
104+
lizMap.mainEventDispatcher.addListener(
105+
definedCustomElements,
106+
'lizmap.modules.initialized'
107+
);
108+
}
98109
}
99110
});
100111

assets/src/modules/Globals.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import Lizmap from './Lizmap.js';
77
import EventDispatcher from '../utils/EventDispatcher.js';
88

9-
const mainLizmap = new Lizmap();
109
const mainEventDispatcher = new EventDispatcher();
10+
const mainLizmap = new Lizmap(mainEventDispatcher);
1111

1212
export {
1313
mainLizmap,

assets/src/modules/Lizmap.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ import { MapLayerLoadStatus } from './state/MapLayer.js';
5151
*/
5252
export default class Lizmap {
5353

54-
constructor() {
54+
constructor(eventDispatcher) {
55+
this._eventDispatcher = eventDispatcher;
5556
lizMap.events.on({
5657
configsloaded: (configs) => {
5758
const wmsParser = new WMSCapabilities();
@@ -186,6 +187,7 @@ export default class Lizmap {
186187
this.map,
187188
this._lizmap3
188189
);
190+
eventDispatcher.dispatch('lizmap.modules.initialized');
189191
}
190192
};
191193
const visibleLayers = this.state.rootMapGroup.findMapLayers().filter(layer => layer.visibility);
@@ -221,6 +223,14 @@ export default class Lizmap {
221223
});
222224
}
223225

226+
/**
227+
* The main event dispatcher
228+
* @type {object}
229+
*/
230+
get eventDispatcher() {
231+
return this._eventDispatcher;
232+
}
233+
224234
/**
225235
* Is new OL map on top of OL2 one?
226236
* @type {boolean}

0 commit comments

Comments
 (0)