mobility-toolbox-js 1.3.9 → 1.3.11

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.
@@ -1,6 +1,6 @@
1
1
  import Control from '../../common/controls/Control';
2
2
  import mixin from '../../common/mixins/CopyrightMixin';
3
- import getMapboxMapCopyrights from '../../common/utils/getMapboxMapCopyrights';
3
+ import { getMapboxMapCopyrights } from '../../common/utils';
4
4
 
5
5
  /**
6
6
  * Display layer's copyrights.
@@ -10,6 +10,14 @@ import RoutingAPI from '../../api/routing/RoutingAPI';
10
10
  import Control from '../../common/controls/Control';
11
11
  import RoutingLayer from '../layers/RoutingLayer';
12
12
 
13
+ const getFlatCoordinatesFromSegments = (segmentArray) => {
14
+ const coords = [];
15
+ segmentArray.forEach((seg) => {
16
+ coords.push(...seg.getGeometry().getCoordinates());
17
+ });
18
+ return coords;
19
+ };
20
+
13
21
  /**
14
22
  * Display a route of a specified mean of transport.
15
23
  *
@@ -85,6 +93,9 @@ class RoutingControl extends Control {
85
93
  /** @ignore */
86
94
  this.stopsApiKey = options.stopsApiKey || this.apiKey;
87
95
 
96
+ /** @ignore */
97
+ this.segments = [];
98
+
88
99
  /** @ignore */
89
100
  this.stopsApiUrl =
90
101
  options.stopsApiUrl || 'https://api.geops.io/stops/v1/lookup/';
@@ -252,13 +263,38 @@ class RoutingControl extends Control {
252
263
  this.abortController,
253
264
  )
254
265
  .then((featureCollection) => {
255
- const segments = this.format.readFeatures(featureCollection);
266
+ this.segments = this.format.readFeatures(featureCollection);
267
+
268
+ if (this.mot === 'foot') {
269
+ // Extract unique values from viaPoint target value
270
+ const uniqueVias = this.segments.reduce(
271
+ (resultVias, currentFeat) => {
272
+ const segTrg = currentFeat.get('trg');
273
+ return resultVias.find(
274
+ (via) => via[0] === segTrg[0] && via[1] === segTrg[1],
275
+ )
276
+ ? resultVias
277
+ : [...resultVias, segTrg];
278
+ },
279
+ [],
280
+ );
281
+
282
+ // Create LineString features from segments with same unique value
283
+ this.segments = uniqueVias.map((via) => {
284
+ const viaSegments = this.segments.filter((seg) => {
285
+ const segTrg = seg.get('trg');
286
+ return segTrg[0] === via[0] && segTrg[1] === via[1];
287
+ });
288
+
289
+ const coords = getFlatCoordinatesFromSegments(viaSegments);
290
+ return new Feature({
291
+ geometry: new LineString(coords),
292
+ });
293
+ });
294
+ }
256
295
 
257
296
  // Create the new route. This route will be modifiable by the Modifiy interaction.
258
- const coords = [];
259
- segments.forEach((seg) => {
260
- coords.push(...seg.getGeometry().getCoordinates());
261
- });
297
+ const coords = getFlatCoordinatesFromSegments(this.segments);
262
298
 
263
299
  const routeFeature = new Feature({
264
300
  geometry: new LineString(coords),
@@ -274,6 +310,7 @@ class RoutingControl extends Control {
274
310
  // Ignore abort error
275
311
  return;
276
312
  }
313
+ this.segments = [];
277
314
  // Dispatch error event and execute error function
278
315
  this.dispatchEvent({
279
316
  type: 'error',
@@ -5,8 +5,7 @@ import Source from 'ol/source/Source';
5
5
  import OLLayer from 'ol/layer/Layer';
6
6
  import GeoJSON from 'ol/format/GeoJSON';
7
7
  import Layer from './Layer';
8
- import getMapboxMapCopyrights from '../../common/utils/getMapboxMapCopyrights';
9
- import getMapboxStyleUrl from '../../common/utils/getMapboxStyleUrl';
8
+ import { getMapboxMapCopyrights, getMapboxStyleUrl } from '../../common/utils';
10
9
 
11
10
  /**
12
11
  * A class representing Mapboxlayer to display on BasicMap
@@ -162,10 +162,10 @@ class MapboxStyleLayer extends Layer {
162
162
 
163
163
  // Apply the visibiltity when layer's visibility change.
164
164
  this.olListenersKeys.push(
165
- this.on('change:visible', () => {
165
+ this.on('change:visible', (evt) => {
166
166
  // Once the map is loaded we can apply vsiiblity without waiting
167
167
  // the style. Mapbox take care of the application of style changes.
168
- this.applyLayoutVisibility();
168
+ this.applyLayoutVisibility(evt);
169
169
  }),
170
170
  );
171
171
 
@@ -393,6 +393,7 @@ class MapboxStyleLayer extends Layer {
393
393
 
394
394
  /**
395
395
  * Apply visibility to style layers that fits the styleLayersFilter function.
396
+ * @param {Event} evt Layer's event that has called the function.
396
397
  * @private
397
398
  */
398
399
  applyLayoutVisibility() {
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": "1.3.9",
5
+ "version": "1.3.11",
6
6
  "main": "index.js",
7
7
  "module": "module.js",
8
8
  "dependencies": {
@@ -161,7 +161,7 @@
161
161
  "./module": "./module.js",
162
162
  "./api": "./api/index.js",
163
163
  "./common": "./common/*.js",
164
- "./common/utils": "./common/utils/*.js",
164
+ "./common/utils": "./common/utils/index.js",
165
165
  "./mapbox": "./mapbox/index.js",
166
166
  "./ol": "./ol/index.js"
167
167
  },