mobility-toolbox-js 3.0.0-beta.2 → 3.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/mbt.js +12 -12
- package/mbt.js.map +2 -2
- package/mbt.min.js +9 -9
- package/mbt.min.js.map +3 -3
- package/ol/layers/MaplibreStyleLayer.js +19 -19
- package/package.json +1 -1
|
@@ -135,25 +135,27 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
135
135
|
if (!this.map || !this.maplibreLayer) {
|
|
136
136
|
return;
|
|
137
137
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (!maplibreMap) {
|
|
141
|
-
// If the maplibreMap is not yet created because the map has no target yet, we
|
|
138
|
+
if (!this.map.getTargetElement()) {
|
|
139
|
+
// If ther e is no target element the maplibreMap is not yet created, we
|
|
142
140
|
// relaunch the initialisation when it's the case.
|
|
143
141
|
this.olListenersKeys.push(this.map.on('change:target', () => {
|
|
144
142
|
this.attachToMap(map);
|
|
145
143
|
}));
|
|
146
144
|
return;
|
|
147
145
|
}
|
|
148
|
-
//
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
146
|
+
// Apply the initial visibility if possible otherwise we wait for the load event of the layer
|
|
147
|
+
const { maplibreMap } = this.maplibreLayer;
|
|
148
|
+
if (maplibreMap) {
|
|
149
|
+
// maplibreMap.loaded() and maplibreMap.isStyleLoaded() are reliable only on the first call of init.
|
|
150
|
+
// On the next call (when a topic change for example), these functions returns false because
|
|
151
|
+
// the style is being modified.
|
|
152
|
+
// That's why we rely on a property instead for the next calls.
|
|
153
|
+
if (maplibreMap.loaded()) {
|
|
154
|
+
this.onLoad();
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
maplibreMap.once('load', this.onLoad);
|
|
158
|
+
}
|
|
157
159
|
}
|
|
158
160
|
// Apply the visibiltity when layer's visibility change.
|
|
159
161
|
this.olListenersKeys.push(
|
|
@@ -185,13 +187,12 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
185
187
|
/** @private */
|
|
186
188
|
addSources() {
|
|
187
189
|
var _a;
|
|
188
|
-
if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !
|
|
190
|
+
if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !this.sources) {
|
|
189
191
|
return;
|
|
190
192
|
}
|
|
191
193
|
const { maplibreMap } = this.maplibreLayer;
|
|
192
194
|
if (maplibreMap) {
|
|
193
|
-
this.sources.forEach((source) => {
|
|
194
|
-
const { id } = source;
|
|
195
|
+
Object.entries(this.sources).forEach(([id, source]) => {
|
|
195
196
|
if (!maplibreMap.getSource(id)) {
|
|
196
197
|
maplibreMap.addSource(id, source);
|
|
197
198
|
}
|
|
@@ -201,13 +202,12 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
201
202
|
/** @private */
|
|
202
203
|
removeSources() {
|
|
203
204
|
var _a;
|
|
204
|
-
if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !
|
|
205
|
+
if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !this.sources) {
|
|
205
206
|
return;
|
|
206
207
|
}
|
|
207
208
|
const { maplibreMap } = this.maplibreLayer;
|
|
208
209
|
if (maplibreMap) {
|
|
209
|
-
this.sources.forEach((
|
|
210
|
-
const { id } = source;
|
|
210
|
+
Object.keys(this.sources).forEach((id) => {
|
|
211
211
|
if (maplibreMap.getSource(id)) {
|
|
212
212
|
maplibreMap.removeSource(id);
|
|
213
213
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "mobility-toolbox-js",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"description": "Toolbox for JavaScript applications in the domains of mobility and logistics.",
|
|
5
|
-
"version": "3.0.0-beta.
|
|
5
|
+
"version": "3.0.0-beta.4",
|
|
6
6
|
"homepage": "https://mobility-toolbox-js.geops.io/",
|
|
7
7
|
"module": "index.js",
|
|
8
8
|
"exports": {
|