mobility-toolbox-js 3.0.0-beta.2 → 3.0.0-beta.21

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 (125) hide show
  1. package/api/HttpAPI.d.ts +20 -0
  2. package/api/HttpAPI.js +0 -11
  3. package/api/RealtimeAPI.d.ts +404 -0
  4. package/api/RealtimeAPI.js +342 -276
  5. package/api/RoutingAPI.d.ts +47 -0
  6. package/api/RoutingAPI.js +17 -7
  7. package/api/StopsAPI.d.ts +44 -0
  8. package/api/StopsAPI.js +16 -10
  9. package/api/WebSocketAPI.d.ts +147 -0
  10. package/api/WebSocketAPI.js +164 -164
  11. package/api/index.d.ts +3 -0
  12. package/api/index.js +1 -1
  13. package/api/typedefs.d.ts +76 -0
  14. package/api/typedefs.js +27 -42
  15. package/common/controls/StopFinderControlCommon.d.ts +53 -0
  16. package/common/controls/StopFinderControlCommon.js +31 -31
  17. package/common/index.d.ts +2 -0
  18. package/common/index.js +1 -1
  19. package/common/mixins/RealtimeLayerMixin.d.ts +267 -0
  20. package/common/mixins/RealtimeLayerMixin.js +401 -393
  21. package/common/styles/index.d.ts +4 -0
  22. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  23. package/common/styles/realtimeDefaultStyle.js +6 -6
  24. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  25. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  26. package/common/styles/realtimeHeadingStyle.js +5 -5
  27. package/common/styles/realtimeSimpleStyle.d.ts +4 -0
  28. package/common/typedefs.d.ts +219 -0
  29. package/common/typedefs.js +7 -1
  30. package/common/utils/compareDepartures.d.ts +10 -0
  31. package/common/utils/compareDepartures.js +2 -2
  32. package/common/utils/constants.d.ts +5 -0
  33. package/common/utils/createCanvas.d.ts +10 -0
  34. package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
  35. package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
  36. package/common/utils/createRealtimeFilters.d.ts +12 -0
  37. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  38. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  39. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  40. package/common/utils/getLayersAsFlatArray.js +5 -1
  41. package/common/utils/getMapGlCopyrights.d.ts +17 -0
  42. package/common/utils/getMapGlCopyrights.js +3 -3
  43. package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
  44. package/common/utils/getRealtimeModeSuffix.js +1 -0
  45. package/common/utils/getUrlWithParams.d.ts +8 -0
  46. package/common/utils/getVehiclePosition.d.ts +17 -0
  47. package/common/utils/getVehiclePosition.js +9 -3
  48. package/common/utils/index.d.ts +16 -0
  49. package/common/utils/realtimeConfig.d.ts +64 -0
  50. package/common/utils/removeDuplicate.d.ts +9 -0
  51. package/common/utils/renderTrajectories.d.ts +16 -0
  52. package/common/utils/renderTrajectories.js +6 -6
  53. package/common/utils/sortAndFilterDepartures.d.ts +15 -0
  54. package/common/utils/sortAndFilterDepartures.js +1 -1
  55. package/common/utils/sortByDelay.d.ts +3 -0
  56. package/common/utils/sortByDelay.js +5 -1
  57. package/common/utils/timeUtils.d.ts +23 -0
  58. package/common/utils/toMercatorExtent.d.ts +5 -0
  59. package/iife.d.ts +2 -0
  60. package/index.d.ts +9 -0
  61. package/maplibre/controls/CopyrightControl.d.ts +35 -0
  62. package/maplibre/controls/index.d.ts +1 -0
  63. package/maplibre/index.d.ts +5 -0
  64. package/maplibre/layers/Layer.d.ts +28 -0
  65. package/maplibre/layers/Layer.js +1 -1
  66. package/maplibre/layers/RealtimeLayer.d.ts +181 -0
  67. package/maplibre/layers/RealtimeLayer.js +29 -5
  68. package/maplibre/layers/index.d.ts +2 -0
  69. package/maplibre/utils/getMercatorResolution.d.ts +7 -0
  70. package/maplibre/utils/getSourceCoordinates.d.ts +7 -0
  71. package/maplibre/utils/getSourceCoordinates.js +5 -5
  72. package/maplibre/utils/index.d.ts +2 -0
  73. package/mbt.js +22103 -14430
  74. package/mbt.js.map +4 -4
  75. package/mbt.min.js +61 -58
  76. package/mbt.min.js.map +4 -4
  77. package/ol/controls/CopyrightControl.d.ts +31 -0
  78. package/ol/controls/CopyrightControl.js +18 -8
  79. package/ol/controls/RoutingControl.d.ts +202 -0
  80. package/ol/controls/RoutingControl.js +220 -219
  81. package/ol/controls/StopFinderControl.d.ts +37 -0
  82. package/ol/controls/StopFinderControl.js +4 -1
  83. package/ol/controls/index.d.ts +3 -0
  84. package/ol/index.d.ts +7 -0
  85. package/ol/index.js +1 -0
  86. package/ol/layers/Layer.d.ts +101 -0
  87. package/ol/layers/Layer.js +25 -0
  88. package/ol/layers/MaplibreLayer.d.ts +160 -0
  89. package/ol/layers/MaplibreLayer.js +97 -27
  90. package/ol/layers/MaplibreStyleLayer.d.ts +237 -0
  91. package/ol/layers/MaplibreStyleLayer.js +291 -267
  92. package/ol/layers/RealtimeLayer.d.ts +283 -0
  93. package/ol/layers/RealtimeLayer.js +143 -128
  94. package/ol/layers/VectorLayer.d.ts +18 -0
  95. package/ol/layers/VectorLayer.js +31 -0
  96. package/ol/layers/index.d.ts +5 -0
  97. package/ol/layers/index.js +3 -0
  98. package/ol/mixins/MobilityLayerMixin.d.ts +96 -0
  99. package/ol/mixins/MobilityLayerMixin.js +1 -4
  100. package/ol/mixins/PropertiesLayerMixin.d.ts +135 -0
  101. package/ol/mixins/PropertiesLayerMixin.js +112 -140
  102. package/ol/mixins/index.d.ts +1 -0
  103. package/ol/mixins/index.js +2 -0
  104. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
  105. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  106. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
  107. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  108. package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
  109. package/ol/renderers/RealtimeLayerRenderer.js +58 -53
  110. package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
  111. package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
  112. package/ol/styles/index.d.ts +3 -0
  113. package/ol/styles/routingStyle.d.ts +4 -0
  114. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
  115. package/ol/utils/getFeatureInfoAtCoordinate.js +12 -18
  116. package/ol/utils/index.d.ts +1 -0
  117. package/package.json +31 -31
  118. package/setupTests.d.ts +1 -0
  119. package/setupTests.js +3 -4
  120. package/types/common.d.ts +55 -48
  121. package/types/index.d.ts +1 -1
  122. package/types/realtime.d.ts +91 -93
  123. package/types/routing.d.ts +60 -60
  124. package/types/stops.d.ts +62 -62
  125. package/ol/layers/MapGlLayer.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;