mobility-toolbox-js 3.0.0-beta.8 → 3.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 (130) hide show
  1. package/README.md +11 -3
  2. package/api/HttpAPI.d.ts +20 -0
  3. package/api/HttpAPI.js +1 -14
  4. package/api/RealtimeAPI.d.ts +404 -0
  5. package/api/RealtimeAPI.js +265 -206
  6. package/api/RoutingAPI.d.ts +47 -0
  7. package/api/RoutingAPI.js +17 -7
  8. package/api/StopsAPI.d.ts +44 -0
  9. package/api/StopsAPI.js +17 -11
  10. package/api/WebSocketAPI.d.ts +147 -0
  11. package/api/WebSocketAPI.js +164 -165
  12. package/api/index.d.ts +3 -0
  13. package/api/index.js +1 -1
  14. package/api/typedefs.d.ts +76 -0
  15. package/api/typedefs.js +27 -42
  16. package/common/controls/StopFinderControlCommon.d.ts +53 -0
  17. package/common/controls/StopFinderControlCommon.js +32 -32
  18. package/common/index.d.ts +2 -0
  19. package/common/index.js +1 -1
  20. package/common/styles/index.d.ts +4 -0
  21. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  22. package/common/styles/realtimeDefaultStyle.js +6 -11
  23. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  24. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  25. package/common/styles/realtimeHeadingStyle.js +5 -10
  26. package/common/styles/realtimeSimpleStyle.d.ts +3 -0
  27. package/common/styles/realtimeSimpleStyle.js +0 -1
  28. package/common/typedefs.d.ts +102 -0
  29. package/common/typedefs.js +6 -31
  30. package/common/utils/RealtimeEngine.d.ts +214 -0
  31. package/common/utils/RealtimeEngine.js +554 -0
  32. package/common/utils/compareDepartures.d.ts +10 -0
  33. package/common/utils/compareDepartures.js +2 -2
  34. package/common/utils/constants.d.ts +5 -0
  35. package/common/utils/createCanvas.d.ts +10 -0
  36. package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
  37. package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
  38. package/common/utils/createRealtimeFilters.d.ts +12 -0
  39. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  40. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  41. package/common/utils/getLayersAsFlatArray.d.ts +2 -0
  42. package/common/utils/getLayersAsFlatArray.js +0 -1
  43. package/common/utils/getMapGlCopyrights.d.ts +17 -0
  44. package/common/utils/getMapGlCopyrights.js +3 -3
  45. package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
  46. package/common/utils/getRealtimeModeSuffix.js +1 -0
  47. package/common/utils/getUrlWithParams.d.ts +8 -0
  48. package/common/utils/getVehiclePosition.d.ts +17 -0
  49. package/common/utils/getVehiclePosition.js +6 -3
  50. package/common/utils/index.d.ts +16 -0
  51. package/common/utils/realtimeConfig.d.ts +64 -0
  52. package/common/utils/realtimeConfig.js +0 -1
  53. package/common/utils/removeDuplicate.d.ts +9 -0
  54. package/common/utils/renderTrajectories.d.ts +17 -0
  55. package/common/utils/renderTrajectories.js +7 -6
  56. package/common/utils/sortAndFilterDepartures.d.ts +16 -0
  57. package/common/utils/sortAndFilterDepartures.js +2 -1
  58. package/common/utils/sortByDelay.d.ts +3 -0
  59. package/common/utils/sortByDelay.js +5 -1
  60. package/common/utils/timeUtils.d.ts +23 -0
  61. package/common/utils/toMercatorExtent.d.ts +5 -0
  62. package/iife.d.ts +2 -0
  63. package/index.d.ts +9 -0
  64. package/maplibre/controls/CopyrightControl.d.ts +38 -0
  65. package/maplibre/controls/CopyrightControl.js +11 -8
  66. package/maplibre/controls/index.d.ts +1 -0
  67. package/maplibre/index.d.ts +5 -0
  68. package/maplibre/layers/Layer.d.ts +29 -0
  69. package/maplibre/layers/Layer.js +2 -3
  70. package/maplibre/layers/RealtimeLayer.d.ts +124 -0
  71. package/maplibre/layers/RealtimeLayer.js +154 -118
  72. package/maplibre/layers/index.d.ts +2 -0
  73. package/maplibre/utils/getMercatorResolution.d.ts +7 -0
  74. package/maplibre/utils/getSourceCoordinates.d.ts +8 -0
  75. package/maplibre/utils/getSourceCoordinates.js +6 -5
  76. package/maplibre/utils/index.d.ts +2 -0
  77. package/mbt.js +14585 -14557
  78. package/mbt.js.map +4 -4
  79. package/mbt.min.js +75 -75
  80. package/mbt.min.js.map +4 -4
  81. package/ol/controls/CopyrightControl.d.ts +39 -0
  82. package/ol/controls/CopyrightControl.js +13 -5
  83. package/ol/controls/RoutingControl.d.ts +213 -0
  84. package/ol/controls/RoutingControl.js +250 -264
  85. package/ol/controls/StopFinderControl.d.ts +56 -0
  86. package/ol/controls/StopFinderControl.js +24 -5
  87. package/ol/controls/index.d.ts +3 -0
  88. package/ol/index.d.ts +6 -0
  89. package/ol/layers/Layer.d.ts +26 -0
  90. package/ol/layers/Layer.js +39 -0
  91. package/ol/layers/MaplibreLayer.d.ts +91 -0
  92. package/ol/layers/MaplibreLayer.js +154 -31
  93. package/ol/layers/MaplibreStyleLayer.d.ts +157 -0
  94. package/ol/layers/MaplibreStyleLayer.js +281 -210
  95. package/ol/layers/RealtimeLayer.d.ts +150 -0
  96. package/ol/layers/RealtimeLayer.js +210 -206
  97. package/ol/layers/VectorLayer.d.ts +17 -0
  98. package/ol/layers/VectorLayer.js +33 -0
  99. package/ol/layers/index.d.ts +5 -0
  100. package/ol/layers/index.js +3 -0
  101. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
  102. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  103. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
  104. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  105. package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
  106. package/ol/renderers/RealtimeLayerRenderer.js +50 -70
  107. package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
  108. package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
  109. package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
  110. package/ol/styles/fullTrajectoryStyle.js +5 -7
  111. package/ol/styles/index.d.ts +3 -0
  112. package/ol/styles/routingStyle.d.ts +3 -0
  113. package/ol/styles/routingStyle.js +13 -10
  114. package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
  115. package/ol/utils/defineDeprecatedProperties.js +180 -0
  116. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
  117. package/ol/utils/getFeatureInfoAtCoordinate.js +11 -17
  118. package/ol/utils/index.d.ts +1 -0
  119. package/package.json +44 -44
  120. package/setupTests.d.ts +1 -0
  121. package/setupTests.js +17 -4
  122. package/types/common.d.ts +53 -69
  123. package/types/index.d.ts +1 -1
  124. package/types/realtime.d.ts +98 -95
  125. package/types/routing.d.ts +60 -60
  126. package/types/stops.d.ts +62 -62
  127. package/common/mixins/RealtimeLayerMixin.js +0 -743
  128. package/ol/layers/MapGlLayer.js +0 -142
  129. package/ol/mixins/MobilityLayerMixin.js +0 -9
  130. package/ol/mixins/PropertiesLayerMixin.js +0 -142
@@ -1,142 +0,0 @@
1
- import Source from 'ol/source/Source';
2
- import BaseEvent from 'ol/events/Event';
3
- import Layer from 'ol/layer/Layer';
4
- import debounce from 'lodash.debounce';
5
- import { getUrlWithParams, getMapGlCopyrights } from '../../common/utils';
6
- import MobilityLayerMixin from '../mixins/MobilityLayerMixin';
7
- /**
8
- * Common class for Maplibre and Maplibre and potential other fork from Maplibre.
9
- * It's used to share code between Maplibre and Maplibre layers without importing both libs.
10
- * @private
11
- */
12
- class MapGlLayer extends MobilityLayerMixin(Layer) {
13
- get apiKey() {
14
- return this.get('apiKey');
15
- }
16
- set apiKey(newValue) {
17
- this.set('apiKey', newValue);
18
- }
19
- get apiKeyName() {
20
- return this.get('apiKeyName');
21
- }
22
- set apiKeyName(newValue) {
23
- this.set('apiKeyName', newValue);
24
- }
25
- get style() {
26
- return this.get('style');
27
- }
28
- set style(newValue) {
29
- this.set('style', newValue);
30
- }
31
- get url() {
32
- return this.get('url');
33
- }
34
- set url(newValue) {
35
- this.set('url', newValue);
36
- }
37
- get queryRenderedFeaturesOptions() {
38
- return this.get('queryRenderedFeaturesOptions');
39
- }
40
- set queryRenderedFeaturesOptions(newValue) {
41
- this.set('queryRenderedFeaturesOptions', newValue);
42
- }
43
- constructor(options) {
44
- super(Object.assign(Object.assign({ source: new Source({
45
- attributions: () => {
46
- return (this.mbMap && getMapGlCopyrights(this.mbMap)) || [];
47
- },
48
- }), apiKeyName: 'key', style: 'travic_v2', url: 'https://maps.geops.io' }, (options || {})), { mapOptions: Object.assign({ interactive: false, trackResize: false, attributionControl: false }, ((options === null || options === void 0 ? void 0 : options.mapOptions) || {})), queryRenderedFeaturesOptions: Object.assign({}, ((options === null || options === void 0 ? void 0 : options.queryRenderedFeaturesOptions) || {})) }));
49
- }
50
- /**
51
- * Initialize the layer and listen to feature clicks.
52
- * @param {ol/Map~Map} map
53
- */
54
- attachToMap(map) {
55
- super.attachToMap(map);
56
- this.loadMbMap();
57
- const updateMbMapDebounced = debounce(this.updateMbMap.bind(this), 150);
58
- this.olListenersKeys.push(this.on('propertychange', (evt) => {
59
- if (/(apiKey|apiKeyName|url|style)/.test(evt.key)) {
60
- updateMbMapDebounced();
61
- }
62
- }));
63
- }
64
- /**
65
- * Terminate what was initialized in init function. Remove layer, events...
66
- */
67
- detachFromMap() {
68
- if (this.mbMap) {
69
- // Some asynchrone repaints are triggered even if the mbMap has been removed,
70
- // to avoid display of errors we set an empty function.
71
- this.mbMap.triggerRepaint = () => { };
72
- this.mbMap.remove();
73
- this.mbMap = undefined;
74
- }
75
- this.loaded = false;
76
- super.detachFromMap();
77
- }
78
- /**
79
- * Create the Maplibre map.
80
- * @private
81
- */
82
- loadMbMap() {
83
- var _a, _b, _c;
84
- this.loaded = false;
85
- this.olListenersKeys.push(
86
- // @ts-ignore
87
- (_a = this.map) === null || _a === void 0 ? void 0 : _a.on('change:target', this.loadMbMap.bind(this)));
88
- if (!((_b = this.map) === null || _b === void 0 ? void 0 : _b.getTargetElement())) {
89
- return;
90
- }
91
- if (!this.visible) {
92
- // On next change of visibility we load the map
93
- this.olListenersKeys.push(
94
- // @ts-ignore
95
- this.once('change:visible', this.loadMbMap.bind(this)));
96
- return;
97
- }
98
- const container = document.createElement('div');
99
- container.style.position = 'absolute';
100
- container.style.width = '100%';
101
- container.style.height = '100%';
102
- /**
103
- * A Maplibre map
104
- * @type {maplibregl.Map}
105
- */
106
- this.mbMap = this.createMap(Object.assign({ style: this.getStyle(), container }, (((_c = this.options) === null || _c === void 0 ? void 0 : _c.mapOptions) || {})));
107
- this.mbMap.on('sourcedata', () => {
108
- var _a;
109
- (_a = this.getSource()) === null || _a === void 0 ? void 0 : _a.refresh(); // Refresh attribution
110
- });
111
- this.mbMap.once('load', () => {
112
- this.loaded = true;
113
- this.dispatchEvent(new BaseEvent('load'));
114
- });
115
- }
116
- getStyle() {
117
- // If the style is a complete style object, use it directly.
118
- if (this.style &&
119
- typeof this.style === 'object' &&
120
- this.style.name &&
121
- this.style.version) {
122
- return this.style;
123
- }
124
- // If the url set is already a complete style url, use it directly.
125
- if (this.url.includes('style.json')) {
126
- return this.url;
127
- }
128
- /// Otherwise build the complete style url.
129
- return getUrlWithParams(`${this.url}/styles/${this.style}/style.json`, {
130
- [this.apiKeyName]: this.apiKey,
131
- }).toString();
132
- }
133
- // eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
134
- createMap(options) {
135
- throw new Error('createMap must be implemented in child class');
136
- }
137
- updateMbMap() {
138
- var _a;
139
- (_a = this.mbMap) === null || _a === void 0 ? void 0 : _a.setStyle(this.getStyle(), { diff: false });
140
- }
141
- }
142
- export default MapGlLayer;
@@ -1,9 +0,0 @@
1
- import PropertiesLayerMixin from './PropertiesLayerMixin';
2
- function MobilityLayerMixin(Base) {
3
- return class extends PropertiesLayerMixin(Base) {
4
- constructor(options = {}) {
5
- super(options);
6
- }
7
- };
8
- }
9
- export default MobilityLayerMixin;
@@ -1,142 +0,0 @@
1
- import { getUid } from 'ol';
2
- import getLayersAsFlatArray from '../../common/utils/getLayersAsFlatArray';
3
- /**
4
- * This mixin adds some properties to access some ol properties easily ansd also
5
- * the management of a hierarchy of layers using children, parent and group property.
6
- */
7
- function PropertiesLayerMixin(Base) {
8
- return class extends Base {
9
- get children() {
10
- return this.get('children') || [];
11
- }
12
- set children(newValue) {
13
- this.set('children', newValue || []);
14
- }
15
- get copyrights() {
16
- // eslint-disable-next-line no-console
17
- console.warn('Deprecated. Use the source object to get the attributions');
18
- return this.get('copyrights');
19
- }
20
- set copyrights(newCopyrights) {
21
- // eslint-disable-next-line no-console
22
- console.warn('Deprecated. Use the source object to set the attributions');
23
- const arrValue = newCopyrights && !Array.isArray(newCopyrights)
24
- ? [newCopyrights]
25
- : newCopyrights;
26
- this.set('copyrights', arrValue || []);
27
- }
28
- get disabled() {
29
- return this.get('disabled');
30
- }
31
- set disabled(newValue) {
32
- this.set('disabled', newValue);
33
- }
34
- get group() {
35
- return this.get('group');
36
- }
37
- get hitTolerance() {
38
- // eslint-disable-next-line no-console
39
- console.warn('Deprecated. Pass the pixelTolerance when you request the features.');
40
- return this.get('hitTolerance') || 5;
41
- }
42
- get key() {
43
- return this.get('key') || this.get('name') || getUid(this);
44
- }
45
- get map() {
46
- return this.getMapInternal();
47
- }
48
- get name() {
49
- return this.get('name');
50
- }
51
- get olLayer() {
52
- // eslint-disable-next-line no-console
53
- console.warn("Deprecated property: mobility-toolbox-js/ol layers inherits now from ol/layer/Layer class. This getter is only a redirect to the current 'this' object.");
54
- return this;
55
- }
56
- // eslint-disable-next-line class-methods-use-this
57
- set olLayer(newValue) {
58
- // eslint-disable-next-line no-console
59
- console.log('Deprecated property: mobility-toolbox-js/ol layers inherits now from ol/layer/Layer class. This setter has no effect.');
60
- }
61
- get parent() {
62
- return this.get('parent');
63
- }
64
- set parent(newValue) {
65
- this.set('parent', newValue);
66
- }
67
- get visible() {
68
- return this.getVisible();
69
- }
70
- set visible(newValue) {
71
- this.setVisible(newValue);
72
- }
73
- constructor(options) {
74
- var _a;
75
- super(options);
76
- this.options = {};
77
- this.olListenersKeys = [];
78
- if (options.properties) {
79
- // eslint-disable-next-line no-console
80
- console.warn("Deprecated. Don't use properties options. Pass the values directly in options object.");
81
- this.setProperties(options.properties);
82
- }
83
- (_a = this.olListenersKeys) === null || _a === void 0 ? void 0 : _a.push(
84
- // Update parent property
85
- this.on('propertychange', (evt) => {
86
- if (evt.key === 'children') {
87
- this.onChildrenChange(evt.oldValue);
88
- }
89
- }));
90
- this.options = options;
91
- this.children = options.children || []; // Trigger the on children change event
92
- }
93
- setMapInternal(map) {
94
- super.setMapInternal(map);
95
- if (map) {
96
- this.attachToMap(map);
97
- }
98
- else {
99
- this.detachFromMap();
100
- }
101
- }
102
- /** @private */
103
- onChildrenChange(oldValue) {
104
- // Set the parent property
105
- (oldValue || []).forEach((child) => {
106
- child.set('parent', undefined);
107
- });
108
- (this.children || []).forEach((child) => {
109
- child.set('parent', this);
110
- });
111
- }
112
- /**
113
- * Initialize the layer with the map passed in parameters.
114
- *
115
- * @param {ol/Map~Map} map A map.
116
- */
117
- attachToMap(map) {
118
- // @ts-ignore
119
- (super.attachToMap || (() => { }))(map);
120
- (this.get('children') || []).forEach((child) => {
121
- map.addLayer(child);
122
- });
123
- }
124
- /**
125
- * Terminate what was initialized in init function. Remove layer, events...
126
- */
127
- detachFromMap() {
128
- (this.get('children') || []).forEach((child) => {
129
- this.map.removeLayer(child);
130
- });
131
- // @ts-ignore
132
- (super.detachFromMap || (() => { }))();
133
- }
134
- /**
135
- * Return the an array containing all the descendants of the layer in a flat array. Including the current layer.
136
- */
137
- flat() {
138
- return getLayersAsFlatArray(this);
139
- }
140
- };
141
- }
142
- export default PropertiesLayerMixin;