mobility-toolbox-js 2.0.0-beta.1 → 2.0.0

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.
Files changed (67) hide show
  1. package/README.md +7 -4
  2. package/api/index.js +0 -1
  3. package/api/tralis/TralisAPI.js +1 -1
  4. package/common/controls/Control.js +4 -1
  5. package/common/layers/Layer.js +18 -49
  6. package/common/layers/Layer.test.js +2 -106
  7. package/common/mixins/SearchMixin.js +1 -1
  8. package/common/mixins/TralisLayerMixin.js +549 -21
  9. package/common/styles/index.js +4 -0
  10. package/common/{utils/delayTrackerStyle.js → styles/trackerDefaultStyle.js} +8 -8
  11. package/common/styles/trackerDelayStyle.js +17 -0
  12. package/common/styles/trackerSimpleStyle.js +22 -0
  13. package/common/trackerConfig.test.js +0 -13
  14. package/common/utils/getMapboxMapCopyrights.js +1 -0
  15. package/common/utils/index.js +2 -3
  16. package/common/utils/sortByDelay.js +23 -0
  17. package/index.js +1 -1
  18. package/index.js.map +1 -1
  19. package/mapbox/controls/CopyrightControl.js +5 -1
  20. package/mapbox/index.js +0 -2
  21. package/mapbox/layers/Layer.test.js +2 -2
  22. package/mapbox/layers/TralisLayer.js +270 -5
  23. package/mapbox/layers/TralisLayer.test.js +40 -0
  24. package/module.js +1 -9
  25. package/ol/controls/CopyrightControl.js +4 -4
  26. package/ol/controls/CopyrightControl.test.js +16 -16
  27. package/ol/controls/RoutingControl.js +9 -7
  28. package/ol/controls/RoutingControl.test.js +1 -1
  29. package/ol/controls/StopFinderControl.js +8 -6
  30. package/ol/controls/StopFinderControl.test.js +1 -1
  31. package/ol/index.js +3 -3
  32. package/ol/layers/Layer.js +9 -0
  33. package/ol/layers/Layer.test.js +22 -7
  34. package/ol/layers/MapboxLayer.js +39 -44
  35. package/ol/layers/MapboxLayer.test.js +5 -5
  36. package/ol/layers/MapboxStyleLayer.js +0 -6
  37. package/ol/layers/MapboxStyleLayer.test.js +22 -6
  38. package/ol/layers/MaplibreLayer.js +280 -0
  39. package/ol/layers/RoutingLayer.test.js +1 -1
  40. package/ol/layers/TralisLayer.js +258 -76
  41. package/ol/layers/TralisLayer.test.js +1 -49
  42. package/ol/layers/VectorLayer.test.js +1 -1
  43. package/ol/layers/WMSLayer.test.js +6 -2
  44. package/ol/styles/fullTrajectoryDelayStyle.js +35 -0
  45. package/ol/styles/fullTrajectoryStyle.js +51 -0
  46. package/ol/styles/index.js +2 -0
  47. package/package.json +16 -8
  48. package/api/trajserv/TrajservAPI.js +0 -71
  49. package/api/trajserv/TrajservAPI.test.js +0 -171
  50. package/api/trajserv/TrajservAPIUtils.js +0 -191
  51. package/api/trajserv/TrajservAPIUtils.test.js +0 -40
  52. package/api/trajserv/typedefs.js +0 -44
  53. package/common/mixins/MapMixin.js +0 -103
  54. package/common/mixins/TrackerLayerMixin.js +0 -745
  55. package/common/mixins/TrajservLayerMixin.js +0 -544
  56. package/common/utils/simpleTrackerStyle.js +0 -18
  57. package/mapbox/Map.js +0 -87
  58. package/mapbox/layers/TrackerLayer.js +0 -282
  59. package/mapbox/layers/TrackerLayer.test.js +0 -68
  60. package/mapbox/layers/TrajservLayer.js +0 -114
  61. package/mapbox/layers/TrajservLayer.test.js +0 -90
  62. package/ol/Map.js +0 -109
  63. package/ol/Map.test.js +0 -34
  64. package/ol/layers/TrackerLayer.js +0 -296
  65. package/ol/layers/TrackerLayer.test.js +0 -70
  66. package/ol/layers/TrajservLayer.js +0 -190
  67. package/ol/layers/TrajservLayer.test.js +0 -113
package/README.md CHANGED
@@ -7,14 +7,17 @@ The tools in this library have been inspired by many projects realized for publi
7
7
  [![Build](https://github.com/geops/mobility-toolbox-js/workflows/Build/badge.svg)](https://github.com/geops/mobility-toolbox-js/actions?query=workflow%3ABuild)
8
8
  [![Netlify Status](https://api.netlify.com/api/v1/badges/b368ab18-9dbf-416c-91f6-a82076b02c10/deploy-status)](https://app.netlify.com/sites/mobility-toolbox-js/deploys)
9
9
 
10
- ## Version 1.x.x
11
- The master branch is now open for the version 2 development. The version 1 is now available in 1.x.x branch.
12
-
13
10
  ## Main Features
11
+
14
12
  * Display [real-time vehicle positions and prognosis data](http://tracker.geops.ch/) on a map.
15
13
  * Search for [stops and stations](https://maps2.trafimage.ch) all over the world.
16
14
  * Get [precise geographic courses](https://geops.github.io/geops-routing-demo/) for all modes of transport.
17
15
  * Generate beautiful maps for public transport, mobility and logistics
18
16
 
19
17
  ## Documentation and examples
20
- Visit https://mobility-toolbox-js.geops.io
18
+
19
+ Visit https://master--mobility-toolbox-js.netlify.app/
20
+
21
+ ## Version 1.x.x
22
+
23
+ The master branch is now open for the version 2 development. The version 1 is still available in [1.x.x](https://github.com/geops/mobility-toolbox-js/tree/1.x.x) branch.
package/api/index.js CHANGED
@@ -1,4 +1,3 @@
1
1
  // eslint-disable-next-line import/prefer-default-export
2
2
  export { default as StopsAPI } from './stops/StopsAPI';
3
- export { default as TrajservAPI } from './trajserv/TrajservAPI';
4
3
  export { default as TralisAPI, TralisModes } from './tralis/TralisAPI';
@@ -81,7 +81,7 @@ class TralisAPI {
81
81
  const conn = new WebSocketConnector();
82
82
 
83
83
  if (apiKey) {
84
- url = `${url || 'wss://tralis-tracker-api.geops.io/ws'}?key=${apiKey}`;
84
+ url = `${url || 'wss://api.geops.io/tracker-ws/v1/'}?key=${apiKey}`;
85
85
  }
86
86
 
87
87
  Object.defineProperties(this, {
@@ -74,7 +74,10 @@ class Control extends BaseObject {
74
74
 
75
75
  if (this.map) {
76
76
  // Add new node
77
- const targett = this.target || this.map.getContainer();
77
+ const targett =
78
+ this.target ||
79
+ (this.map.getTargetElement && this.map.getTargetElement()) ||
80
+ (this.map.getContainer && this.map.getContainer());
78
81
 
79
82
  if (!this.element) {
80
83
  this.createDefaultElement();
@@ -16,7 +16,7 @@ import { v4 as uuid } from 'uuid';
16
16
  * @classproperty {boolean} isQueryable - Define if the layer can be queried. If false, it will set isHoverActive and isClickActive to false. Read-only.
17
17
  * @classproperty {boolean} isClickActive - If true feature information will be queried on user click event. See inherited layers for more informations. Read-only.
18
18
  * @classproperty {boolean} isHoverActive - If true feature information will be queried on pointer move event. See inherited layers for more informations. Read-only.
19
- * @classproperty {boolean} isReactSpatialLayer - Custom property for duck typing since `instanceof` is not working when the instance was created on different bundles. Read-only.
19
+ * @classproperty {boolean} isMobilityLayer - Custom property for duck typing since `instanceof` is not working when the instance was created on different bundles. Read-only.
20
20
  * @classproperty {Layer[]} children - List of children.
21
21
  * @classproperty {boolean} visible - Define if the layer is visible or not.
22
22
  * @classproperty {number} hitTolerance - Hit-detection tolerance in css pixels. Pixels inside the radius around the given position will be checked for features.
@@ -109,12 +109,15 @@ export default class Layer extends Observable {
109
109
  },
110
110
  isQueryable: {
111
111
  value: !!isQueryable,
112
+ writable: true,
112
113
  },
113
114
  isClickActive: {
114
115
  value: !!isQueryable && !!isClickActive,
116
+ writable: true,
115
117
  },
116
118
  isHoverActive: {
117
119
  value: !!isQueryable && !!isHoverActive,
120
+ writable: true,
118
121
  },
119
122
  hitTolerance: {
120
123
  value: hitTolerance || 5,
@@ -122,7 +125,7 @@ export default class Layer extends Observable {
122
125
  },
123
126
  // Custom property for duck typing since `instanceof` is not working
124
127
  // when the instance was created on different bundles.
125
- isReactSpatialLayer: {
128
+ isMobilityLayer: {
126
129
  value: true,
127
130
  },
128
131
  children: {
@@ -197,11 +200,13 @@ export default class Layer extends Observable {
197
200
  * @param {string} value Value.
198
201
  */
199
202
  set(name, value) {
200
- this.properties[name] = value;
201
- this.dispatchEvent({
202
- type: `change:${name}`,
203
- target: this,
204
- });
203
+ if (value !== this.properties[name]) {
204
+ this.properties[name] = value;
205
+ this.dispatchEvent({
206
+ type: `change:${name}`,
207
+ target: this,
208
+ });
209
+ }
205
210
  }
206
211
 
207
212
  /**
@@ -250,48 +255,7 @@ export default class Layer extends Observable {
250
255
  * @deprecated
251
256
  */
252
257
  hasVisibleChildren() {
253
- return !!this.hasChildren(true);
254
- }
255
-
256
- /**
257
- * Checks whether the layer has any child layers with visible equal to the input parameter
258
- *
259
- * @param {boolean} visible The state to check the childlayers against
260
- * @return {boolean} True if the layer has children with the given visibility
261
- */
262
- hasChildren(visible) {
263
- return !!this.children.find((child) => child.visible === visible);
264
- }
265
-
266
- /**
267
- * Add a child layer
268
- *
269
- * @param {Layer} layer Add a child layer
270
- */
271
- addChild(layer) {
272
- this.children.unshift(layer);
273
- this.dispatchEvent({
274
- type: `change:children`,
275
- target: this,
276
- });
277
- }
278
-
279
- /**
280
- * Removes a child layer by layer name
281
- *
282
- * @param {string} name Layer's name
283
- */
284
- removeChild(name) {
285
- for (let i = 0; i < this.children.length; i += 1) {
286
- if (this.children[i].name === name) {
287
- this.children.splice(i, 1);
288
- break;
289
- }
290
- }
291
- this.dispatchEvent({
292
- type: `change:children`,
293
- target: this,
294
- });
258
+ return !!this.children.find((child) => child.visible === true);
295
259
  }
296
260
 
297
261
  /**
@@ -310,6 +274,11 @@ export default class Layer extends Observable {
310
274
  this.key,
311
275
  );
312
276
 
277
+ // No response so we modify the properties accordingly, to avoid spaming the console.
278
+ this.isQueryable = false;
279
+ // this.isClickActive = false;
280
+ // this.isHoverActive = false;
281
+
313
282
  // This layer returns no feature info.
314
283
  // The function is implemented by inheriting layers.
315
284
  return Promise.resolve({
@@ -27,7 +27,7 @@ describe('Layer', () => {
27
27
  expect(layer.isClickActive).toBe(true);
28
28
  expect(layer.isHoverActive).toBe(true);
29
29
  expect(layer.hitTolerance).toBe(5);
30
- expect(layer.isReactSpatialLayer).toBe(true);
30
+ expect(layer.isMobilityLayer).toBe(true);
31
31
  expect(layer.copyrights).toBe();
32
32
  expect(layer.visible).toBe(true);
33
33
  expect(layer.properties).toEqual({});
@@ -115,19 +115,6 @@ describe('Layer', () => {
115
115
  });
116
116
  expect(layer.getVisibleChildren().length).toBe(1);
117
117
  expect(layer.hasVisibleChildren()).toBe(true);
118
- expect(layer.hasChildren(false)).toBe(true);
119
-
120
- layer.addChild(
121
- new Layer({
122
- name: 'bla',
123
- }),
124
- );
125
-
126
- expect(layer.getVisibleChildren().length).toBe(2);
127
-
128
- layer.removeChild('bla');
129
-
130
- expect(layer.getVisibleChildren().length).toBe(1);
131
118
  });
132
119
 
133
120
  test('should set onClick using constructor.', () => {
@@ -292,97 +279,6 @@ describe('Layer', () => {
292
279
  });
293
280
  });
294
281
 
295
- describe('#hasVisibleChildren()', () => {
296
- test('should return true for visible children.', () => {
297
- const layerVisible = { visible: true };
298
- const layerVisible2 = { visible: true };
299
- const layerHidden = { visible: false };
300
- const layer = new Layer({
301
- name: 'Layer',
302
- visible: false,
303
- olLayer,
304
- children: [layerVisible, layerHidden, layerVisible2],
305
- });
306
- expect(layer.hasChildren(true)).toEqual(true);
307
- });
308
-
309
- test('should return true with hidden children.', () => {
310
- const layerVisible = { visible: true };
311
- const layerVisible2 = { visible: true };
312
- const layerHidden = { visible: false };
313
- const layer = new Layer({
314
- name: 'Layer',
315
- visible: false,
316
- olLayer,
317
- children: [layerVisible, layerHidden, layerVisible2],
318
- });
319
- expect(layer.hasChildren(false)).toEqual(true);
320
- });
321
-
322
- test('should return false with hidden children.', () => {
323
- const layerVisible = { visible: true };
324
- const layerVisible2 = { visible: true };
325
- const layer = new Layer({
326
- name: 'Layer',
327
- visible: false,
328
- olLayer,
329
- children: [layerVisible, layerVisible2],
330
- });
331
- expect(layer.hasChildren(false)).toEqual(false);
332
- });
333
- });
334
-
335
- describe('#addChild()', () => {
336
- test('add a child.', () => {
337
- const layerVisible = { visible: true };
338
- const layerHidden = { visible: false };
339
- const layer = new Layer({
340
- name: 'Layer',
341
- visible: false,
342
- olLayer,
343
- });
344
- const spy = jest.spyOn(layer, 'dispatchEvent');
345
- expect(layer.children).toEqual([]);
346
- layer.addChild(layerVisible);
347
- expect(layer.children).toEqual([layerVisible]);
348
- expect(spy).toHaveBeenCalledTimes(1);
349
- expect(spy).toHaveBeenCalledWith({
350
- type: 'change:children',
351
- target: layer,
352
- });
353
- spy.mockReset();
354
- layer.addChild(layerHidden);
355
- expect(layer.children).toEqual([layerHidden, layerVisible]);
356
- expect(spy).toHaveBeenCalledTimes(1);
357
- expect(spy).toHaveBeenCalledWith({
358
- type: 'change:children',
359
- target: layer,
360
- });
361
- });
362
- });
363
-
364
- describe('#removeChild()', () => {
365
- test('removes a child using the name', () => {
366
- const layerVisible = { name: 'foo', visible: true };
367
- const layerHidden = { name: 'bar', visible: false };
368
- const layer = new Layer({
369
- name: 'Layer',
370
- visible: false,
371
- olLayer,
372
- children: [layerVisible, layerHidden],
373
- });
374
- const spy = jest.spyOn(layer, 'dispatchEvent');
375
- expect(layer.children).toEqual([layerVisible, layerHidden]);
376
- layer.removeChild('foo');
377
- expect(layer.children).toEqual([layerHidden]);
378
- expect(spy).toHaveBeenCalledTimes(1);
379
- expect(spy).toHaveBeenCalledWith({
380
- type: 'change:children',
381
- target: layer,
382
- });
383
- });
384
- });
385
-
386
282
  describe('#getFeatureInfoAtCoordinate()', () => {
387
283
  test('return an empty fetaureInfo object and display an error message', (done) => {
388
284
  // eslint-disable-next-line no-console
@@ -575,7 +471,7 @@ describe('Layer', () => {
575
471
  });
576
472
 
577
473
  describe('#unHover()', () => {
578
- test.only('removes function from clickCallbacks array', () => {
474
+ test('removes function from clickCallbacks array', () => {
579
475
  const layer = new Layer({
580
476
  name: 'Layer',
581
477
  olLayer,
@@ -125,7 +125,7 @@ const SearchMixin = (Base) =>
125
125
  display: 'none',
126
126
  position: 'absolute',
127
127
  right: '0',
128
- padding: '10px',
128
+ padding: '0 10px',
129
129
  fontSize: '200%',
130
130
  cursor: 'pointer',
131
131
  });