mobility-toolbox-js 3.0.0-beta.1 → 3.0.0-beta.3

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.
@@ -103,7 +103,7 @@ class MapGlLayer extends MobilityLayerMixin(Layer) {
103
103
  * A Maplibre map
104
104
  * @type {maplibregl.Map}
105
105
  */
106
- this.mbMap = this.createMap(Object.assign({ style: this.getStyle() || { version: '8', sources: {}, layers: [] }, container }, (((_c = this.options) === null || _c === void 0 ? void 0 : _c.mapOptions) || {})));
106
+ this.mbMap = this.createMap(Object.assign({ style: this.getStyle(), container }, (((_c = this.options) === null || _c === void 0 ? void 0 : _c.mapOptions) || {})));
107
107
  this.mbMap.on('sourcedata', () => {
108
108
  var _a;
109
109
  (_a = this.getSource()) === null || _a === void 0 ? void 0 : _a.refresh(); // Refresh attribution
@@ -156,13 +156,13 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
156
156
  maplibreMap.once('load', this.onLoad);
157
157
  }
158
158
  // Apply the visibiltity when layer's visibility change.
159
- this.olListenersKeys.push(this.on('change:visible', (evt) => {
159
+ this.olListenersKeys.push(
160
+ // @ts-expect-error 'load' is a custom event form mobility-toolbox-js
161
+ this.maplibreLayer.on('load', this.onLoad.bind(this)), this.on('change:visible', (evt) => {
160
162
  // Once the map is loaded we can apply visiblity without waiting
161
163
  // the style. Maplibre take care of the application of style changes.
162
164
  this.applyLayoutVisibility(evt);
163
- }),
164
- // @ts-expect-error 'load' is a custom event form mobility-toolbox-js
165
- this.maplibreLayer.on('load', this.onLoad), this.on('propertychange', (evt) => {
165
+ }), this.on('propertychange', (evt) => {
166
166
  if (/(sources|layers|layersFilter|maplibreLayer|beforeId|)/.test(evt.key)) {
167
167
  this.detachFromMap();
168
168
  this.attachToMap(map);
@@ -185,13 +185,12 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
185
185
  /** @private */
186
186
  addSources() {
187
187
  var _a;
188
- if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !Array.isArray(this.sources)) {
188
+ if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !this.sources) {
189
189
  return;
190
190
  }
191
191
  const { maplibreMap } = this.maplibreLayer;
192
192
  if (maplibreMap) {
193
- this.sources.forEach((source) => {
194
- const { id } = source;
193
+ Object.entries(this.sources).forEach(([id, source]) => {
195
194
  if (!maplibreMap.getSource(id)) {
196
195
  maplibreMap.addSource(id, source);
197
196
  }
@@ -201,13 +200,12 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
201
200
  /** @private */
202
201
  removeSources() {
203
202
  var _a;
204
- if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !Array.isArray(this.layers)) {
203
+ if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !this.sources) {
205
204
  return;
206
205
  }
207
206
  const { maplibreMap } = this.maplibreLayer;
208
207
  if (maplibreMap) {
209
- this.sources.forEach((source) => {
210
- const { id } = source;
208
+ Object.keys(this.sources).forEach((id) => {
211
209
  if (maplibreMap.getSource(id)) {
212
210
  maplibreMap.removeSource(id);
213
211
  }
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.1",
5
+ "version": "3.0.0-beta.3",
6
6
  "homepage": "https://mobility-toolbox-js.geops.io/",
7
7
  "module": "index.js",
8
8
  "exports": {