mobility-toolbox-js 2.0.0 → 2.0.1-beta.13

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 (102) hide show
  1. package/api/RoutingAPI.js +15 -0
  2. package/api/RoutingAPI.test.js +25 -0
  3. package/api/StopsAPI.js +12 -0
  4. package/api/StopsAPI.test.js +22 -0
  5. package/api/TralisAPI.js +359 -0
  6. package/api/TralisAPI.test.js +67 -0
  7. package/api/{tralis/TralisAPIUtils.js → TralisAPIUtils.js} +2 -32
  8. package/api/index.js +3 -3
  9. package/{ol/README.md → api/typedefs.js} +0 -0
  10. package/common/Tracker.js +14 -118
  11. package/common/api/HttpAPI.js +30 -0
  12. package/common/api/HttpAPI.test.js +50 -0
  13. package/common/api/WebSocketAPI.js +175 -0
  14. package/{api/tralis/WebSocketConnector.test.js → common/api/WebSocketAPI.test.js} +100 -145
  15. package/common/controls/Control.js +26 -91
  16. package/common/controls/Control.test.js +32 -43
  17. package/common/index.js +4 -0
  18. package/common/layers/Layer.js +53 -244
  19. package/common/layers/Layer.test.js +185 -244
  20. package/common/mixins/CopyrightMixin.js +20 -44
  21. package/common/mixins/SearchMixin.js +100 -166
  22. package/common/mixins/TralisLayerMixin.js +443 -894
  23. package/common/styles/index.js +4 -4
  24. package/common/styles/trackerDefaultStyle.js +39 -175
  25. package/common/styles/trackerDelayStyle.js +2 -11
  26. package/common/styles/trackerSimpleStyle.js +4 -8
  27. package/common/trackerConfig.js +61 -99
  28. package/common/trackerConfig.test.js +15 -17
  29. package/common/typedefs.js +0 -23
  30. package/common/utils/createTrackerFilters.js +10 -41
  31. package/common/utils/createTrackerFilters.test.js +40 -56
  32. package/common/utils/getMapboxMapCopyrights.js +3 -16
  33. package/common/utils/getMapboxMapCopyrights.test.js +32 -39
  34. package/common/utils/getMapboxStyleUrl.js +3 -13
  35. package/common/utils/getVehiclePosition.js +3 -33
  36. package/common/utils/index.js +5 -6
  37. package/common/utils/removeDuplicate.js +3 -17
  38. package/common/utils/removeDuplicate.test.js +17 -20
  39. package/common/utils/sortByDelay.js +2 -7
  40. package/common/utils/timeUtils.js +8 -32
  41. package/common/utils/timeUtils.test.js +7 -13
  42. package/index.js +8 -2
  43. package/mapbox/controls/CopyrightControl.js +9 -38
  44. package/mapbox/controls/index.js +1 -0
  45. package/mapbox/index.js +4 -3
  46. package/mapbox/layers/Layer.js +15 -76
  47. package/mapbox/layers/Layer.test.js +81 -101
  48. package/mapbox/layers/TralisLayer.js +46 -193
  49. package/mapbox/layers/TralisLayer.test.js +12 -14
  50. package/mapbox/layers/index.js +2 -0
  51. package/mapbox/utils.js +7 -21
  52. package/mbt.js +50444 -0
  53. package/mbt.js.map +7 -0
  54. package/mbt.min.js +1005 -0
  55. package/mbt.min.js.map +7 -0
  56. package/ol/controls/CopyrightControl.js +8 -46
  57. package/ol/controls/CopyrightControl.test.js +75 -121
  58. package/ol/controls/RoutingControl.js +167 -532
  59. package/ol/controls/RoutingControl.test.js +99 -164
  60. package/ol/controls/StopFinderControl.js +3 -31
  61. package/ol/controls/StopFinderControl.test.js +18 -29
  62. package/ol/controls/index.js +3 -0
  63. package/ol/index.js +5 -13
  64. package/ol/layers/Layer.js +23 -128
  65. package/ol/layers/Layer.test.js +79 -102
  66. package/ol/layers/MapboxLayer.js +62 -237
  67. package/ol/layers/MapboxLayer.test.js +58 -84
  68. package/ol/layers/MapboxStyleLayer.js +38 -268
  69. package/ol/layers/MapboxStyleLayer.test.js +97 -128
  70. package/ol/layers/MaplibreLayer.js +46 -187
  71. package/ol/layers/RoutingLayer.js +21 -51
  72. package/ol/layers/RoutingLayer.test.js +15 -24
  73. package/ol/layers/TralisLayer.js +102 -276
  74. package/ol/layers/TralisLayer.test.js +32 -50
  75. package/ol/layers/VectorLayer.js +3 -24
  76. package/ol/layers/VectorLayer.test.js +34 -45
  77. package/ol/layers/WMSLayer.js +15 -57
  78. package/ol/layers/WMSLayer.test.js +35 -43
  79. package/ol/layers/index.js +8 -0
  80. package/ol/styles/fullTrajectoryDelayStyle.js +11 -15
  81. package/ol/styles/fullTrajectoryStyle.js +17 -25
  82. package/ol/styles/index.js +2 -2
  83. package/package.json +35 -62
  84. package/api/routing/RoutingAPI.js +0 -44
  85. package/api/routing/RoutingAPI.test.js +0 -41
  86. package/api/stops/StopsAPI.js +0 -41
  87. package/api/stops/StopsAPI.test.js +0 -34
  88. package/api/tralis/TralisAPI.js +0 -731
  89. package/api/tralis/TralisAPI.test.js +0 -75
  90. package/api/tralis/WebSocketConnector.js +0 -338
  91. package/api/tralis/typedefs.js +0 -81
  92. package/common/api/api.js +0 -64
  93. package/common/api/api.test.js +0 -68
  94. package/index.js.map +0 -1
  95. package/module.js +0 -23
  96. package/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
  97. package/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
  98. package/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
  99. package/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
  100. package/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
  101. package/ol/controls/snapshots/RoutingControlStation1.json +0 -60
  102. package/ol/controls/snapshots/RoutingControlStation2.json +0 -49
@@ -1,48 +1,24 @@
1
- /* eslint-disable class-methods-use-this */
2
- /* eslint-disable max-classes-per-file */
3
-
4
- /**
5
- * Copyright control interface.
6
- *
7
- */
8
1
  export class CopyrightInterface {
9
- /**
10
- * Return an array of layer's copyright.
11
- *
12
- * @return {String[]} A list of copyrights to render.
13
- */
14
- getCopyrights() {}
2
+ getCopyrights() {
3
+ }
15
4
  }
16
-
17
- /**
18
- * Mixin for CopyrightInterface.
19
- *
20
- * @param {Class} Base A class to extend with {CopyrightInterface} functionnalities.
21
- * @return {Class} A class that implements <CopyrightInterface> class and extends Base;
22
- * @private
23
- */
24
- const CopyrightMixin = (Base) =>
25
- class extends Base {
26
- render() {
27
- if (!this.element) {
28
- return;
29
- }
30
- this.element.innerHTML = this.active
31
- ? this.getCopyrights().join(' | ')
32
- : '';
5
+ const CopyrightMixin = (Base) => class extends Base {
6
+ render() {
7
+ if (!this.element) {
8
+ return;
33
9
  }
34
-
35
- createDefaultElement() {
36
- this.element = document.createElement('div');
37
- this.element.id = 'mbt-copyright';
38
- Object.assign(this.element.style, {
39
- position: 'absolute',
40
- bottom: 0,
41
- right: 0,
42
- fontSize: '.8rem',
43
- padding: '0 10px',
44
- });
45
- }
46
- };
47
-
10
+ this.element.innerHTML = this.active ? this.getCopyrights().join(" | ") : "";
11
+ }
12
+ createDefaultElement() {
13
+ this.element = document.createElement("div");
14
+ this.element.id = "mbt-copyright";
15
+ Object.assign(this.element.style, {
16
+ position: "absolute",
17
+ bottom: 0,
18
+ right: 0,
19
+ fontSize: ".8rem",
20
+ padding: "0 10px"
21
+ });
22
+ }
23
+ };
48
24
  export default CopyrightMixin;
@@ -1,176 +1,110 @@
1
- /* eslint-disable no-empty-function */
2
- /* eslint-disable no-useless-constructor */
3
- /* eslint-disable class-methods-use-this */
4
- /* eslint-disable max-classes-per-file */
5
- import StopsAPI from '../../api/stops/StopsAPI';
6
-
7
- /**
8
- * Search control interface.
9
- *
10
- * @classproperty {StopsSearchParams} apiParams - Default request parameters used by the search method. See [Stops service documentation](https://developer.geops.io/apis/5dcbd702a256d90001cf1361/).
11
- */
1
+ import { StopsAPI } from "../../api";
12
2
  export class SearchInterface {
13
- /**
14
- * Constructor.
15
- *
16
- * @param {Object} options Map options
17
- * @param {string} options.apiKey Access key for [geOps services](https://developer.geops.io/). See StopsAPI.
18
- * @param {string} [options.url='https://api.geops.io/tracker/v1'] Stops service url. See StopsAPI.
19
- * @param {string} [options.placeholder='Search for a stop...'] Input field placeholder.
20
- * @param {StopsSearchParams} [options.apiParams={ limit: 20 }] Request parameters. See [Stops service documentation](https://developer.geops.io/apis/5dcbd702a256d90001cf1361/).
21
- */
22
- // eslint-disable-next-line no-unused-vars
23
- constructor(options = {}) {}
24
-
25
- /**
26
- * Launch a search.
27
- *
28
- * @param {String} query The query to search for.
29
- * @param {AbortController} abortController Abort controller used to cancel the request.
30
- * @return {Promise<Array<GeoJSONFeature>>} An array of GeoJSON features with coordinates in [EPSG:4326](http://epsg.io/4326).
31
- */
32
- // eslint-disable-next-line no-unused-vars
33
- search(query, abortController) {}
3
+ constructor(options = {}) {
4
+ }
5
+ search(query, abortController) {
6
+ }
34
7
  }
35
-
36
- /**
37
- * Mixin for SearchInterface.
38
- *
39
- * @param {Class} Base A class to extend with {SearchInterface} functionnalities.
40
- * @return {Class} A class that implements <SearchInterface> class and extends Base;
41
- * @private
42
- */
43
- const SearchMixin = (Base) =>
44
- class extends Base {
45
- constructor(options = {}) {
46
- super(options);
47
- const { apiParams, apiKey, url } = options;
48
-
49
- this.apiParams = { limit: 20, ...(apiParams || {}) };
50
- this.placeholder = options.placeholder || 'Search for a stop...';
51
-
52
- const apiOptions = { apiKey };
53
- if (url) {
54
- apiOptions.url = url;
55
- }
56
- this.api = new StopsAPI(apiOptions);
57
- this.abortController = new AbortController();
8
+ const SearchMixin = (Base) => class extends Base {
9
+ constructor(options = {}) {
10
+ super(options);
11
+ const { apiParams, apiKey, url } = options;
12
+ this.apiParams = { limit: 20, ...apiParams || {} };
13
+ this.placeholder = options.placeholder || "Search for a stop...";
14
+ const apiOptions = { apiKey };
15
+ if (url) {
16
+ apiOptions.url = url;
58
17
  }
59
-
60
- render(suggestions = []) {
61
- if (!this.suggestionsElt) {
62
- return;
63
- }
64
-
65
- this.suggestionsElt.style.display = suggestions.length ? 'block' : 'none';
66
-
67
- this.suggestionsElt.innerHTML = '';
68
-
69
- suggestions.forEach((suggestion) => {
70
- const { properties } = suggestion;
71
- const suggElt = document.createElement('div');
72
- suggElt.innerHTML = properties.name;
73
- suggElt.onclick = () => {
74
- this.onSuggestionClick(suggestion);
75
- };
76
- Object.assign(suggElt.style, {
77
- padding: '5px 12px',
78
- });
79
- this.suggestionsElt.appendChild(suggElt);
80
- });
18
+ this.api = new StopsAPI(apiOptions);
19
+ this.abortController = new AbortController();
20
+ }
21
+ render(featureCollection) {
22
+ const suggestions = featureCollection?.features || [];
23
+ if (!this.suggestionsElt) {
24
+ return;
81
25
  }
82
-
83
- createDefaultElement() {
84
- /**
85
- * Define a default element.
86
- */
87
- this.element = document.createElement('div');
88
- this.element.id = 'mbt-search';
89
- Object.assign(this.element.style, {
90
- position: 'absolute',
91
- top: 0,
92
- left: '50px',
93
- margin: '10px',
94
- display: 'flex',
95
- flexDirection: 'column',
96
- width: '320px',
97
- });
98
-
99
- // Create input element
100
- this.inputElt = document.createElement('input');
101
- this.inputElt.type = 'text';
102
- this.inputElt.placeholder = this.placeholder;
103
- this.inputElt.autoComplete = 'off';
104
- this.inputElt.onkeyup = (evt) => {
105
- this.abortController.abort();
106
- this.abortController = new AbortController();
107
- this.search(evt.target.value, this.abortController);
26
+ this.suggestionsElt.style.display = suggestions.length ? "block" : "none";
27
+ this.suggestionsElt.innerHTML = "";
28
+ suggestions.forEach((suggestion) => {
29
+ const { properties } = suggestion;
30
+ const suggElt = document.createElement("div");
31
+ suggElt.innerHTML = properties.name;
32
+ suggElt.onclick = () => {
33
+ this.onSuggestionClick(suggestion);
108
34
  };
109
- Object.assign(this.inputElt.style, {
110
- padding: '10px 30px 10px 10px',
35
+ Object.assign(suggElt.style, {
36
+ padding: "5px 12px"
111
37
  });
112
- this.element.appendChild(this.inputElt);
113
-
114
- // Create suggestions list element
115
- this.suggestionsElt = document.createElement('div');
116
- Object.assign(this.suggestionsElt.style, {
117
- backgroundColor: 'white',
118
- overflowY: 'auto',
119
- cursor: 'pointer',
120
- });
121
- this.element.appendChild(this.suggestionsElt);
122
-
123
- this.clearElt = document.createElement('div');
124
- Object.assign(this.clearElt.style, {
125
- display: 'none',
126
- position: 'absolute',
127
- right: '0',
128
- padding: '0 10px',
129
- fontSize: '200%',
130
- cursor: 'pointer',
131
- });
132
- this.clearElt.innerHTML = '×';
133
- this.clearElt.onclick = () => this.clear();
134
- this.element.appendChild(this.clearElt);
38
+ this.suggestionsElt.appendChild(suggElt);
39
+ });
40
+ }
41
+ createDefaultElement() {
42
+ this.element = document.createElement("div");
43
+ this.element.id = "mbt-search";
44
+ Object.assign(this.element.style, {
45
+ position: "absolute",
46
+ top: 0,
47
+ left: "50px",
48
+ margin: "10px",
49
+ display: "flex",
50
+ flexDirection: "column",
51
+ width: "320px"
52
+ });
53
+ this.inputElt = document.createElement("input");
54
+ this.inputElt.type = "text";
55
+ this.inputElt.placeholder = this.placeholder;
56
+ this.inputElt.autoComplete = "off";
57
+ this.inputElt.onkeyup = (evt) => {
58
+ this.abortController.abort();
59
+ this.abortController = new AbortController();
60
+ this.search(evt.target.value, this.abortController);
61
+ };
62
+ Object.assign(this.inputElt.style, {
63
+ padding: "10px 30px 10px 10px"
64
+ });
65
+ this.element.appendChild(this.inputElt);
66
+ this.suggestionsElt = document.createElement("div");
67
+ Object.assign(this.suggestionsElt.style, {
68
+ backgroundColor: "white",
69
+ overflowY: "auto",
70
+ cursor: "pointer"
71
+ });
72
+ this.element.appendChild(this.suggestionsElt);
73
+ this.clearElt = document.createElement("div");
74
+ Object.assign(this.clearElt.style, {
75
+ display: "none",
76
+ position: "absolute",
77
+ right: "0",
78
+ padding: "0 10px",
79
+ fontSize: "200%",
80
+ cursor: "pointer"
81
+ });
82
+ this.clearElt.innerHTML = "\xD7";
83
+ this.clearElt.onclick = () => this.clear();
84
+ this.element.appendChild(this.clearElt);
85
+ }
86
+ search(q, abortController) {
87
+ if (q !== void 0 || q !== null) {
88
+ this.apiParams.q = q;
135
89
  }
136
-
137
- search(q, abortController) {
138
- if (q !== undefined || q !== null) {
139
- this.apiParams.q = q;
140
- }
141
-
142
- if (this.clearElt) {
143
- this.clearElt.style.display = 'block';
144
- }
145
-
146
- return this.api
147
- .search(this.apiParams, abortController)
148
- .then((data) => {
149
- this.render(data);
150
- })
151
- .catch(() => {
152
- this.render();
153
- });
90
+ if (this.clearElt) {
91
+ this.clearElt.style.display = "block";
154
92
  }
155
-
156
- /**
157
- * To be defined in inherited class
158
- */
159
- // eslint-disable-next-line no-unused-vars
160
- onSuggestionClick(suggestion) {}
161
-
162
- /**
163
- * Clear the search field and close the control.
164
- */
165
- clear() {
166
- if (!this.suggestionsElt) {
167
- return;
168
- }
169
-
170
- this.inputElt.value = '';
171
- this.suggestionsElt.innerHTML = '';
172
- this.clearElt.style.display = 'none';
93
+ return this.api.search(this.apiParams, abortController).then((data) => {
94
+ this.render(data);
95
+ }).catch(() => {
96
+ this.render();
97
+ });
98
+ }
99
+ onSuggestionClick(suggestion) {
100
+ }
101
+ clear() {
102
+ if (!this.suggestionsElt) {
103
+ return;
173
104
  }
174
- };
175
-
105
+ this.inputElt.value = "";
106
+ this.suggestionsElt.innerHTML = "";
107
+ this.clearElt.style.display = "none";
108
+ }
109
+ };
176
110
  export default SearchMixin;