mobility-toolbox-js 2.0.1-beta.13 → 2.2.0-beta.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 (259) hide show
  1. package/api/RealtimeAPI.d.ts +281 -0
  2. package/api/RealtimeAPI.d.ts.map +1 -0
  3. package/api/RealtimeAPI.js +490 -0
  4. package/api/RoutingAPI.d.ts +37 -0
  5. package/api/RoutingAPI.d.ts.map +1 -0
  6. package/api/RoutingAPI.js +32 -12
  7. package/api/StopsAPI.d.ts +38 -0
  8. package/api/StopsAPI.d.ts.map +1 -0
  9. package/api/StopsAPI.js +33 -9
  10. package/api/index.d.ts +4 -0
  11. package/api/index.d.ts.map +1 -0
  12. package/api/index.js +3 -3
  13. package/api/typedefs.d.ts +179 -0
  14. package/api/typedefs.d.ts.map +1 -0
  15. package/api/typedefs.js +75 -0
  16. package/common/api/HttpAPI.d.ts +31 -0
  17. package/common/api/HttpAPI.d.ts.map +1 -0
  18. package/common/api/HttpAPI.js +54 -27
  19. package/common/api/WebSocketAPI.d.ts +153 -0
  20. package/common/api/WebSocketAPI.d.ts.map +1 -0
  21. package/common/api/WebSocketAPI.js +330 -164
  22. package/common/controls/ControlCommon.d.ts +76 -0
  23. package/common/controls/ControlCommon.d.ts.map +1 -0
  24. package/common/controls/ControlCommon.js +150 -0
  25. package/common/controls/CopyrightControlCommon.d.ts +13 -0
  26. package/common/controls/CopyrightControlCommon.d.ts.map +1 -0
  27. package/common/controls/CopyrightControlCommon.js +34 -0
  28. package/common/controls/StopFinderControlCommon.d.ts +55 -0
  29. package/common/controls/StopFinderControlCommon.d.ts.map +1 -0
  30. package/common/controls/StopFinderControlCommon.js +144 -0
  31. package/common/index.d.ts +3 -0
  32. package/common/index.d.ts.map +1 -0
  33. package/common/index.js +2 -4
  34. package/common/layers/LayerCommon.d.ts +94 -0
  35. package/common/layers/LayerCommon.d.ts.map +1 -0
  36. package/common/layers/LayerCommon.js +244 -0
  37. package/common/mixins/RealtimeLayerMixin.d.ts +286 -0
  38. package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
  39. package/common/mixins/RealtimeLayerMixin.js +779 -0
  40. package/common/mixins/UserInteractionsLayerMixin.d.ts +60 -0
  41. package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
  42. package/common/mixins/UserInteractionsLayerMixin.js +241 -0
  43. package/common/styles/index.d.ts +5 -0
  44. package/common/styles/index.d.ts.map +1 -0
  45. package/common/styles/index.js +4 -4
  46. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  47. package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
  48. package/common/styles/realtimeDefaultStyle.js +275 -0
  49. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  50. package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
  51. package/common/styles/realtimeDelayStyle.js +13 -0
  52. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  53. package/common/styles/realtimeHeadingStyle.d.ts.map +1 -0
  54. package/common/styles/realtimeHeadingStyle.js +85 -0
  55. package/common/styles/realtimeSimpleStyle.d.ts +4 -0
  56. package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
  57. package/common/styles/realtimeSimpleStyle.js +23 -0
  58. package/common/typedefs.d.ts +111 -0
  59. package/common/typedefs.d.ts.map +1 -0
  60. package/common/typedefs.js +52 -0
  61. package/common/utils/compareDepartures.d.ts +11 -0
  62. package/common/utils/compareDepartures.d.ts.map +1 -0
  63. package/common/utils/compareDepartures.js +35 -0
  64. package/common/utils/createCanvas.d.ts +10 -0
  65. package/common/utils/createCanvas.d.ts.map +1 -0
  66. package/common/utils/createCanvas.js +27 -0
  67. package/common/utils/createRealtimeFilters.d.ts +13 -0
  68. package/common/utils/createRealtimeFilters.d.ts.map +1 -0
  69. package/common/utils/createRealtimeFilters.js +74 -0
  70. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  71. package/common/utils/debounceDeparturesMessages.d.ts.map +1 -0
  72. package/common/utils/debounceDeparturesMessages.js +24 -0
  73. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  74. package/common/utils/debounceWebsocketMessages.d.ts.map +1 -0
  75. package/common/utils/debounceWebsocketMessages.js +29 -0
  76. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  77. package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
  78. package/common/utils/getLayersAsFlatArray.js +15 -0
  79. package/common/utils/getMapboxMapCopyrights.d.ts +18 -0
  80. package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
  81. package/common/utils/getMapboxMapCopyrights.js +26 -15
  82. package/common/utils/getMapboxRender.d.ts +7 -0
  83. package/common/utils/getMapboxRender.d.ts.map +1 -0
  84. package/common/utils/getMapboxRender.js +87 -0
  85. package/common/utils/getMaplibreRender.d.ts +7 -0
  86. package/common/utils/getMaplibreRender.d.ts.map +1 -0
  87. package/common/utils/getMaplibreRender.js +38 -0
  88. package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
  89. package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
  90. package/common/utils/getRealtimeModeSuffix.js +7 -0
  91. package/common/utils/getUrlWithParams.d.ts +9 -0
  92. package/common/utils/getUrlWithParams.d.ts.map +1 -0
  93. package/common/utils/getUrlWithParams.js +18 -0
  94. package/common/utils/getVehiclePosition.d.ts +16 -0
  95. package/common/utils/getVehiclePosition.d.ts.map +1 -0
  96. package/common/utils/getVehiclePosition.js +67 -37
  97. package/common/utils/index.d.ts +17 -0
  98. package/common/utils/index.d.ts.map +1 -0
  99. package/common/utils/index.js +17 -5
  100. package/common/utils/realtimeConfig.d.ts +49 -0
  101. package/common/utils/realtimeConfig.d.ts.map +1 -0
  102. package/common/utils/realtimeConfig.js +173 -0
  103. package/common/utils/removeDuplicate.d.ts +10 -0
  104. package/common/utils/removeDuplicate.d.ts.map +1 -0
  105. package/common/utils/removeDuplicate.js +12 -5
  106. package/common/utils/renderTrajectories.d.ts +17 -0
  107. package/common/utils/renderTrajectories.d.ts.map +1 -0
  108. package/common/utils/renderTrajectories.js +110 -0
  109. package/common/utils/sortAndFilterDepartures.d.ts +16 -0
  110. package/common/utils/sortAndFilterDepartures.d.ts.map +1 -0
  111. package/common/utils/sortAndFilterDepartures.js +58 -0
  112. package/common/utils/sortByDelay.d.ts +3 -0
  113. package/common/utils/sortByDelay.d.ts.map +1 -0
  114. package/common/utils/sortByDelay.js +17 -15
  115. package/common/utils/timeUtils.d.ts +24 -0
  116. package/common/utils/timeUtils.d.ts.map +1 -0
  117. package/common/utils/timeUtils.js +34 -15
  118. package/iife.d.ts +3 -0
  119. package/iife.d.ts.map +1 -0
  120. package/iife.js +5 -0
  121. package/index.d.ts +10 -0
  122. package/index.d.ts.map +1 -0
  123. package/index.js +8 -6
  124. package/mapbox/controls/CopyrightControl.d.ts +29 -0
  125. package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
  126. package/mapbox/controls/CopyrightControl.js +44 -25
  127. package/mapbox/controls/index.d.ts +2 -0
  128. package/mapbox/controls/index.d.ts.map +1 -0
  129. package/mapbox/controls/index.js +2 -1
  130. package/mapbox/index.d.ts +6 -0
  131. package/mapbox/index.d.ts.map +1 -0
  132. package/mapbox/index.js +5 -4
  133. package/mapbox/layers/Layer.d.ts +59 -0
  134. package/mapbox/layers/Layer.d.ts.map +1 -0
  135. package/mapbox/layers/Layer.js +99 -55
  136. package/mapbox/layers/RealtimeLayer.d.ts +181 -0
  137. package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
  138. package/mapbox/layers/RealtimeLayer.js +276 -0
  139. package/mapbox/layers/index.d.ts +3 -0
  140. package/mapbox/layers/index.d.ts.map +1 -0
  141. package/mapbox/layers/index.js +2 -2
  142. package/mapbox/utils/getMercatorResolution.d.ts +9 -0
  143. package/mapbox/utils/getMercatorResolution.d.ts.map +1 -0
  144. package/mapbox/utils/getMercatorResolution.js +18 -0
  145. package/mapbox/utils/getSourceCoordinates.d.ts +9 -0
  146. package/mapbox/utils/getSourceCoordinates.d.ts.map +1 -0
  147. package/mapbox/utils/getSourceCoordinates.js +27 -0
  148. package/mapbox/utils/index.d.ts +3 -0
  149. package/mapbox/utils/index.d.ts.map +1 -0
  150. package/mapbox/utils/index.js +2 -0
  151. package/mbt.js +26074 -16501
  152. package/mbt.js.map +4 -4
  153. package/mbt.min.js +205 -126
  154. package/mbt.min.js.map +4 -4
  155. package/ol/controls/CopyrightControl.d.ts +31 -0
  156. package/ol/controls/CopyrightControl.d.ts.map +1 -0
  157. package/ol/controls/CopyrightControl.js +62 -36
  158. package/ol/controls/RoutingControl.d.ts +193 -0
  159. package/ol/controls/RoutingControl.d.ts.map +1 -0
  160. package/ol/controls/RoutingControl.js +601 -357
  161. package/ol/controls/StopFinderControl.d.ts +30 -0
  162. package/ol/controls/StopFinderControl.d.ts.map +1 -0
  163. package/ol/controls/StopFinderControl.js +30 -8
  164. package/ol/controls/index.d.ts +4 -0
  165. package/ol/controls/index.d.ts.map +1 -0
  166. package/ol/controls/index.js +3 -3
  167. package/ol/index.d.ts +6 -0
  168. package/ol/index.d.ts.map +1 -0
  169. package/ol/index.js +5 -5
  170. package/ol/layers/Layer.d.ts +86 -0
  171. package/ol/layers/Layer.d.ts.map +1 -0
  172. package/ol/layers/Layer.js +163 -77
  173. package/ol/layers/MapGlLayer.d.ts +67 -0
  174. package/ol/layers/MapGlLayer.d.ts.map +1 -0
  175. package/ol/layers/MapGlLayer.js +218 -0
  176. package/ol/layers/MapboxLayer.d.ts +50 -0
  177. package/ol/layers/MapboxLayer.d.ts.map +1 -0
  178. package/ol/layers/MapboxLayer.js +99 -193
  179. package/ol/layers/MapboxStyleLayer.d.ts +129 -0
  180. package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
  181. package/ol/layers/MapboxStyleLayer.js +362 -171
  182. package/ol/layers/MaplibreLayer.d.ts +28 -0
  183. package/ol/layers/MaplibreLayer.d.ts.map +1 -0
  184. package/ol/layers/MaplibreLayer.js +30 -135
  185. package/ol/layers/RealtimeLayer.d.ts +202 -0
  186. package/ol/layers/RealtimeLayer.d.ts.map +1 -0
  187. package/ol/layers/RealtimeLayer.js +340 -0
  188. package/ol/layers/RoutingLayer.d.ts +34 -0
  189. package/ol/layers/RoutingLayer.d.ts.map +1 -0
  190. package/ol/layers/RoutingLayer.js +72 -48
  191. package/ol/layers/VectorLayer.d.ts +25 -0
  192. package/ol/layers/VectorLayer.d.ts.map +1 -0
  193. package/ol/layers/VectorLayer.js +34 -18
  194. package/ol/layers/WMSLayer.d.ts +42 -0
  195. package/ol/layers/WMSLayer.d.ts.map +1 -0
  196. package/ol/layers/WMSLayer.js +84 -34
  197. package/ol/layers/index.d.ts +9 -0
  198. package/ol/layers/index.d.ts.map +1 -0
  199. package/ol/layers/index.js +8 -8
  200. package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
  201. package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
  202. package/ol/styles/fullTrajectoryDelayStyle.js +26 -24
  203. package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
  204. package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
  205. package/ol/styles/fullTrajectoryStyle.js +40 -39
  206. package/ol/styles/index.d.ts +3 -0
  207. package/ol/styles/index.d.ts.map +1 -0
  208. package/ol/styles/index.js +2 -2
  209. package/package.json +81 -133
  210. package/setupTests.d.ts +2 -0
  211. package/setupTests.d.ts.map +1 -0
  212. package/setupTests.js +26 -0
  213. package/types/common.d.ts +122 -0
  214. package/types/index.d.ts +13 -0
  215. package/types/realtime.d.ts +320 -0
  216. package/types/routing.d.ts +206 -0
  217. package/types/stops.d.ts +143 -0
  218. package/README.md +0 -23
  219. package/api/RoutingAPI.test.js +0 -25
  220. package/api/StopsAPI.test.js +0 -22
  221. package/api/TralisAPI.js +0 -359
  222. package/api/TralisAPI.test.js +0 -67
  223. package/api/TralisAPIUtils.js +0 -43
  224. package/common/Tracker.js +0 -93
  225. package/common/api/HttpAPI.test.js +0 -50
  226. package/common/api/WebSocketAPI.test.js +0 -311
  227. package/common/controls/Control.js +0 -81
  228. package/common/controls/Control.test.js +0 -87
  229. package/common/layers/Layer.js +0 -213
  230. package/common/layers/Layer.test.js +0 -526
  231. package/common/mixins/CopyrightMixin.js +0 -24
  232. package/common/mixins/SearchMixin.js +0 -110
  233. package/common/mixins/TralisLayerMixin.js +0 -479
  234. package/common/styles/trackerDefaultStyle.js +0 -197
  235. package/common/styles/trackerDelayStyle.js +0 -8
  236. package/common/styles/trackerSimpleStyle.js +0 -18
  237. package/common/trackerConfig.js +0 -152
  238. package/common/trackerConfig.test.js +0 -23
  239. package/common/utils/createTrackerFilters.js +0 -56
  240. package/common/utils/createTrackerFilters.test.js +0 -79
  241. package/common/utils/getMapboxMapCopyrights.test.js +0 -40
  242. package/common/utils/getMapboxStyleUrl.js +0 -22
  243. package/common/utils/removeDuplicate.test.js +0 -19
  244. package/common/utils/timeUtils.test.js +0 -10
  245. package/mapbox/layers/Layer.test.js +0 -182
  246. package/mapbox/layers/TralisLayer.js +0 -182
  247. package/mapbox/layers/TralisLayer.test.js +0 -38
  248. package/mapbox/utils.js +0 -32
  249. package/ol/controls/CopyrightControl.test.js +0 -165
  250. package/ol/controls/RoutingControl.test.js +0 -151
  251. package/ol/controls/StopFinderControl.test.js +0 -48
  252. package/ol/layers/Layer.test.js +0 -174
  253. package/ol/layers/MapboxLayer.test.js +0 -160
  254. package/ol/layers/MapboxStyleLayer.test.js +0 -231
  255. package/ol/layers/RoutingLayer.test.js +0 -40
  256. package/ol/layers/TralisLayer.js +0 -185
  257. package/ol/layers/TralisLayer.test.js +0 -79
  258. package/ol/layers/VectorLayer.test.js +0 -87
  259. package/ol/layers/WMSLayer.test.js +0 -76
@@ -0,0 +1,244 @@
1
+ import BaseObject from 'ol/Object';
2
+ import { v4 as uuid } from 'uuid';
3
+ import BaseEvent from 'ol/events/Event';
4
+ import getLayersAsFlatArray from '../utils/getLayersAsFlatArray';
5
+ /**
6
+ * A class representing a layer to display on map.
7
+ *
8
+ * @example
9
+ * const layer = new Layer({
10
+ * name: 'My Layer',
11
+ * });
12
+ *
13
+ * @classproperty {string} key - Identifier of the layer. Must be unique.
14
+ * @classproperty {string} name - Name of the layer
15
+ * @classproperty {string[]} copyrights - Array of copyrights.
16
+ * @classproperty {Layer[]} children - List of children layers.
17
+ * @classproperty {boolean} visible - Define if the layer is currently display on the map.
18
+ * @classproperty {boolean} disabled - Define if the layer is currently display on the map but can't be seen (extent, zoom ,data restrictions).
19
+ * @classproperty {number} hitTolerance - Hit-detection tolerance in css pixels. Pixels inside the radius around the given position will be checked for features.
20
+ * @classproperty {Object} properties - Custom properties.
21
+ * @classproperty {ol/Map~Map|mapboxgl.Map} map - The map where the layer is displayed.
22
+ */
23
+ export default class Layer extends BaseObject {
24
+ /**
25
+ * Constructor
26
+ *
27
+ * @param {Object} options
28
+ * @param {string} [options.key=uuid()] Identifier of the layer. Muste be unique. Default use a generated uuid.
29
+ * @param {string} [options.name] Name of the layer.
30
+ * @param {string[]} [options.copyrights] Array of copyrights.
31
+ * @param {Array<Layer>} [options.children=[]] Sublayers, all child layers will have a parent property associated to this layer.
32
+ * @param {boolean} [options.visible=true] Define if the layer is currently display on the map.
33
+ * @param {boolean} [options.disabled=false] Define if the layer is currently display on the map but can't be seen (extent, zoom ,data restrictions).
34
+ * @param {number} [options.hitTolerance=5] Hit-detection tolerance in css pixels. Pixels inside the radius around the given position will be checked for features.
35
+ * @param {Object} [options.properties={}] Application-specific layer properties.
36
+ */
37
+ constructor(options = {}) {
38
+ super();
39
+ this.properties = {};
40
+ this.options = {};
41
+ this.defineProperties(options);
42
+ if (options.properties) {
43
+ this.setProperties(options.properties);
44
+ }
45
+ this.options = options;
46
+ this.visible = options.visible === undefined ? true : !!options.visible;
47
+ this.group = options.group;
48
+ this.copyrights = options.copyrights;
49
+ this.children = options.children;
50
+ // Listen for group visiblity change
51
+ // if a layer from a group is newly visible we hide the others.
52
+ /* @ts-ignore */
53
+ this.on(`change:visible:group`, (evt) => {
54
+ // We hide layer of the same group
55
+ if (this.group === evt.target.group &&
56
+ this !== evt.target &&
57
+ this.visible) {
58
+ this.visible = false;
59
+ // Propagate event to parent
60
+ }
61
+ else if (this.children) {
62
+ this.children.forEach((child) => child.dispatchEvent(evt));
63
+ }
64
+ });
65
+ }
66
+ /**
67
+ * Define layer's properties that needs custom get and set.
68
+ *
69
+ * @ignore
70
+ */
71
+ defineProperties(options = {}) {
72
+ const { name, key, properties, hitTolerance } = Object.assign({}, options);
73
+ const uid = uuid();
74
+ Object.defineProperties(this, {
75
+ /* Layer's information properties */
76
+ name: {
77
+ value: name,
78
+ },
79
+ key: {
80
+ value: key || name || uid,
81
+ },
82
+ group: {
83
+ get: () => this.get('group'),
84
+ set: (newGroup) => {
85
+ this.set('group', newGroup);
86
+ },
87
+ },
88
+ copyrights: {
89
+ get: () => this.get('copyrights'),
90
+ set: (newCopyrights) => {
91
+ const arrValue = newCopyrights && !Array.isArray(newCopyrights)
92
+ ? [newCopyrights]
93
+ : newCopyrights;
94
+ this.set('copyrights', arrValue || []);
95
+ },
96
+ },
97
+ // options is used for clone function.
98
+ options: {
99
+ value: options,
100
+ },
101
+ map: {
102
+ writable: true,
103
+ },
104
+ /* Layer's state properties */
105
+ visible: {
106
+ get: () => this.get('visible'),
107
+ set: (newVisible) => {
108
+ if (newVisible === this.visible) {
109
+ return;
110
+ }
111
+ this.set('visible', newVisible);
112
+ if (this.visible) {
113
+ // We make the parent visible
114
+ if (this.parent) {
115
+ this.parent.visible = true;
116
+ }
117
+ // If children doesn't contain any visible layers, we display all children.
118
+ if (this.children &&
119
+ !this.children.some((child) => child.visible)) {
120
+ this.children.forEach((child) => {
121
+ // eslint-disable-next-line no-param-reassign
122
+ child.visible = true;
123
+ });
124
+ }
125
+ // Warn the same group that a new layer is visible
126
+ if (this.parent && this.group) {
127
+ // We search for the higher parent then it will dispatch to all the tree.
128
+ let higherParent = this.parent;
129
+ while (higherParent.parent) {
130
+ higherParent = higherParent.parent;
131
+ }
132
+ const evt = new BaseEvent(`change:visible:group`);
133
+ evt.target = this;
134
+ higherParent.dispatchEvent(evt);
135
+ }
136
+ }
137
+ else if (!this.visible) {
138
+ // We hide all the children
139
+ if (this.children) {
140
+ this.children.forEach((child) => {
141
+ // eslint-disable-next-line no-param-reassign
142
+ child.visible = false;
143
+ });
144
+ }
145
+ // If the parent has no more visible child we also hide it.
146
+ if (this.parent &&
147
+ this.parent.visible &&
148
+ this.parent.children &&
149
+ !this.parent.children.find((child) => child.visible)) {
150
+ this.parent.visible = false;
151
+ }
152
+ }
153
+ },
154
+ },
155
+ disabled: {
156
+ get: () => this.get('disabled'),
157
+ set: (newValue) => {
158
+ this.set('disabled', newValue);
159
+ },
160
+ },
161
+ /* Layer's hierarchy properties */
162
+ parent: {
163
+ value: null,
164
+ writable: true,
165
+ },
166
+ children: {
167
+ get: () => this.get('children') || [],
168
+ set: (newValue) => {
169
+ (this.children || []).forEach((child) => {
170
+ // eslint-disable-next-line no-param-reassign
171
+ child.parent = undefined;
172
+ });
173
+ if (Array.isArray(newValue)) {
174
+ newValue.forEach((child) => {
175
+ // eslint-disable-next-line no-param-reassign
176
+ child.parent = this;
177
+ });
178
+ }
179
+ this.set('children', newValue || []);
180
+ },
181
+ },
182
+ /* Layer's query properties */
183
+ hitTolerance: {
184
+ value: hitTolerance || 5,
185
+ writable: true,
186
+ },
187
+ /* Custom app specific properties */
188
+ properties: {
189
+ value: Object.assign({}, (properties || {})),
190
+ },
191
+ });
192
+ }
193
+ /**
194
+ * Initialize the layer with the map passed in parameters.
195
+ *
196
+ * @param {ol/Map~Map|mapboxgl.Map} map A map.
197
+ */
198
+ attachToMap(map) {
199
+ this.detachFromMap();
200
+ /** @ignore */
201
+ this.map = map;
202
+ if (this.children) {
203
+ this.children.forEach((child) => {
204
+ child.attachToMap(map);
205
+ });
206
+ }
207
+ }
208
+ /**
209
+ * Terminate what was initialized in init function. Remove layer, events...
210
+ */
211
+ // eslint-disable-next-line class-methods-use-this
212
+ detachFromMap() {
213
+ /** @ignore */
214
+ this.map = undefined;
215
+ }
216
+ /**
217
+ * Request feature information for a given coordinate.
218
+ * This function must be implemented by inheriting layers.
219
+ *
220
+ * @param {ol/coordinate~Coordinate} coordinate Coordinate.
221
+ * @param {Object} options Some options. See child classes to see which are supported.
222
+ * @return {Promise<FeatureInfo>} An empty response.
223
+ */
224
+ // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
225
+ getFeatureInfoAtCoordinate(coordinate,
226
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
227
+ options) {
228
+ // eslint-disable-next-line no-console
229
+ console.error('getFeatureInfoAtCoordinate must be implemented by inheriting layers', this.key);
230
+ // This layer returns no feature info.
231
+ // The function is implemented by inheriting layers.
232
+ return Promise.resolve({
233
+ layer: this,
234
+ features: [],
235
+ coordinate,
236
+ });
237
+ }
238
+ /**
239
+ * Return the an array containing all the descendants of the layer in a flat array. Including the current layer.
240
+ */
241
+ flat() {
242
+ return getLayersAsFlatArray(this);
243
+ }
244
+ }
@@ -0,0 +1,286 @@
1
+ import GeoJSON from 'ol/format/GeoJSON';
2
+ import { EventsKey } from 'ol/events';
3
+ import { Coordinate } from 'ol/coordinate';
4
+ import { Feature } from 'ol';
5
+ import { RealtimeAPI } from '../../api';
6
+ import { AnyCanvas, AnyLayerClass, AnyMap, AnyRealtimeLayer, LayerGetFeatureInfoOptions, RealtimeGeneralizationLevel, RealtimeMode, RealtimeMot, RealtimeRenderState, RealtimeStyleFunction, RealtimeStyleOptions, RealtimeTenant, RealtimeTrainId, ViewState, AnyLayer } from '../../types';
7
+ import { RealtimeTrajectory } from '../../api/typedefs';
8
+ import { WebSocketAPIMessageEventData } from '../api/WebSocketAPI';
9
+ import type { OlLayerOptions } from '../../ol/layers/Layer';
10
+ export type RealtimeLayerMixinOptions = OlLayerOptions & {
11
+ debug?: boolean;
12
+ mode?: RealtimeMode;
13
+ api?: RealtimeAPI;
14
+ tenant?: RealtimeTenant;
15
+ minZoomInterpolation?: number;
16
+ isUpdateBboxOnMoveEnd?: boolean;
17
+ motsByZoom?: RealtimeMot[][];
18
+ generalizationLevelByZoom?: RealtimeGeneralizationLevel[];
19
+ renderTimeIntervalByZoom?: number[];
20
+ style?: RealtimeStyleFunction;
21
+ speed?: number;
22
+ pixelRatio?: number;
23
+ hoverVehicleId?: RealtimeTrainId;
24
+ selectedVehicleId?: RealtimeTrainId;
25
+ filter?: FilterFunction;
26
+ sort?: SortFunction;
27
+ time?: number;
28
+ live?: boolean;
29
+ canvas?: HTMLCanvasElement;
30
+ styleOptions?: RealtimeStyleOptions;
31
+ useRequestAnimationFrame?: boolean;
32
+ useDebounce?: boolean;
33
+ useThrottle?: boolean;
34
+ getMotsByZoom: (zoom: number, motsByZoom: RealtimeMot[][]) => RealtimeMot[];
35
+ getGeneralizationLevelByZoom?: (zoom: number, generalizationLevelByZoom: RealtimeGeneralizationLevel[]) => RealtimeGeneralizationLevel;
36
+ getRenderTimeIntervalByZoom?: (zoom: number, renderTimeIntervalByZoom: number[]) => number;
37
+ onStart?: (realtimeLayer: AnyRealtimeLayer) => void;
38
+ onStop?: (realtimeLayer: AnyRealtimeLayer) => void;
39
+ url?: string;
40
+ apiKey?: string;
41
+ prefix?: string;
42
+ projection?: string;
43
+ bbox?: (number | string)[];
44
+ buffer?: number[];
45
+ pingIntervalMs?: number;
46
+ };
47
+ /**
48
+ * RealtimeLayerInterface.
49
+ */
50
+ export declare class RealtimeLayerInterface {
51
+ /**
52
+ * Start the clock.
53
+ */
54
+ start(): void;
55
+ /**
56
+ * Stop the clock.
57
+ */
58
+ stop(): void;
59
+ /**
60
+ * Set the Realtime api's bbox.
61
+ *
62
+ * @param {Array<number>} extent Extent to request, [minX, minY, maxX, maxY, zoom].
63
+ * @param {number} zoom Zoom level to request. Must be an integer.
64
+ */
65
+ setBbox(extent: [number, number, number, number], zoom: number): void;
66
+ /**
67
+ * Render the trajectories
68
+ */
69
+ renderTrajectories(): void;
70
+ /**
71
+ * Request the stopSequence and the fullTrajectory informations for a vehicle.
72
+ *
73
+ * @param {string} id The vehicle identifier (the train_id property).
74
+ * @param {RealtimeMode} mode The mode to request. If not defined, the layer´s mode propetrty will be used.
75
+ * @return {Promise<{stopSequence: StopSequence, fullTrajectory: FullTrajectory>} A promise that will be resolved with the trajectory informations.
76
+ */
77
+ getTrajectoryInfos(id: string, mode: RealtimeMode): void;
78
+ }
79
+ /**
80
+ * Mixin for RealtimeLayerInterface.
81
+ *
82
+ * @param {Class} Base A class to extend with {RealtimeLayerInterface} functionnalities.
83
+ * @return {Class} A class that implements {RealtimeLayerInterface} class and extends Base;
84
+ * @private
85
+ */
86
+ declare function RealtimeLayerMixin<T extends AnyLayerClass>(Base: T): {
87
+ new (options: RealtimeLayerMixinOptions): {
88
+ [x: string]: any;
89
+ debug: boolean;
90
+ trajectories?: {
91
+ [key: string]: GeoJSONFeature;
92
+ } | undefined;
93
+ canvas?: AnyCanvas | undefined;
94
+ mode: RealtimeMode;
95
+ api: RealtimeAPI;
96
+ tenant: RealtimeTenant;
97
+ time?: Date | undefined;
98
+ live?: boolean | undefined;
99
+ speed?: number | undefined;
100
+ filter?: Function | undefined;
101
+ sort?: Function | undefined;
102
+ style?: RealtimeStyleFunction | undefined;
103
+ styleOptions?: RealtimeStyleOptions | undefined;
104
+ pixelRatio?: number | undefined;
105
+ minZoomInterpolation: number;
106
+ isUpdateBboxOnMoveEnd: boolean;
107
+ hoverVehicleId?: string | undefined;
108
+ selectedVehicleId?: string | undefined;
109
+ renderState?: RealtimeRenderState | undefined;
110
+ useRequestAnimationFrame?: boolean | undefined;
111
+ useDebounce?: boolean | undefined;
112
+ useThrottle?: boolean | undefined;
113
+ mots?: RealtimeMot[] | undefined;
114
+ motsByZoom: RealtimeMot[][];
115
+ generalizationLevel?: RealtimeGeneralizationLevel | undefined;
116
+ generalizationLevelByZoom: RealtimeGeneralizationLevel[];
117
+ renderTimeIntervalByZoom: number[];
118
+ format: GeoJSON;
119
+ requestId?: number | undefined;
120
+ updateTimeInterval?: number | undefined;
121
+ updateTimeDelay?: number | undefined;
122
+ visibilityRef: EventsKey;
123
+ selectedVehicle: GeoJSONFeature;
124
+ getMotsByZoom: (zoom: number) => RealtimeMot[];
125
+ getGeneralizationLevelByZoom: (zoom: number) => RealtimeGeneralizationLevel;
126
+ getRenderTimeIntervalByZoom: (zoom: number) => number;
127
+ throttleRenderTrajectories: (viewState: ViewState, noInterpolate?: boolean) => void;
128
+ debounceRenderTrajectories: (viewState: ViewState, noInterpolate?: boolean) => void;
129
+ onStart?: ((realtimeLayer: AnyLayer) => void) | undefined;
130
+ onStop?: ((realtimeLayer: AnyLayer) => void) | undefined;
131
+ /**
132
+ * Define layer's properties.
133
+ *
134
+ * @ignore
135
+ */
136
+ defineProperties(options: RealtimeLayerMixinOptions): void;
137
+ attachToMap(map: AnyMap): void;
138
+ detachFromMap(): void;
139
+ start(): void;
140
+ /**
141
+ * Start the clock.
142
+ * @private
143
+ */
144
+ startUpdateTime(): void;
145
+ stop(): void;
146
+ /**
147
+ * Stop the clock.
148
+ * @private
149
+ */
150
+ stopUpdateTime(): void;
151
+ /**
152
+ * Launch renderTrajectories. it avoids duplicating code in renderTrajectories method.
153
+ *
154
+ * @param {object} viewState The view state of the map.
155
+ * @param {number[2]} viewState.center Center coordinate of the map in mercator coordinate.
156
+ * @param {number[4]} viewState.extent Extent of the map in mercator coordinates.
157
+ * @param {number[2]} viewState.size Size ([width, height]) of the canvas to render.
158
+ * @param {number} [viewState.rotation = 0] Rotation of the map to render.
159
+ * @param {number} viewState.resolution Resolution of the map to render.
160
+ * @param {boolean} noInterpolate If true trajectories are not interpolated but
161
+ * drawn at the last known coordinate. Use this for performance optimization
162
+ * during map navigation.
163
+ * @private
164
+ */
165
+ renderTrajectoriesInternal(viewState: ViewState, noInterpolate?: boolean): boolean;
166
+ /**
167
+ * Render the trajectories requesting an animation frame and cancelling the previous one.
168
+ * This function must be overrided by children to provide the correct parameters.
169
+ *
170
+ * @param {object} viewState The view state of the map.
171
+ * @param {number[2]} viewState.center Center coordinate of the map in mercator coordinate.
172
+ * @param {number[4]} viewState.extent Extent of the map in mercator coordinates.
173
+ * @param {number[2]} viewState.size Size ([width, height]) of the canvas to render.
174
+ * @param {number} [viewState.rotation = 0] Rotation of the map to render.
175
+ * @param {number} viewState.resolution Resolution of the map to render.
176
+ * @param {boolean} noInterpolate If true trajectories are not interpolated but
177
+ * drawn at the last known coordinate. Use this for performance optimization
178
+ * during map navigation.
179
+ * @private
180
+ */
181
+ renderTrajectories(viewState: ViewState | undefined, noInterpolate: boolean | undefined): void;
182
+ setBbox(extent?: [number, number, number, number], zoom?: number): void;
183
+ /**
184
+ * Get the duration before the next update depending on zoom level.
185
+ *
186
+ * @private
187
+ * @param {number} zoom
188
+ */
189
+ getRefreshTimeInMs(zoom?: number | undefined): number;
190
+ /**
191
+ * Get vehicle.
192
+ * @param {function} filterFc A function use to filter results.
193
+ * @return {Array<Object>} Array of vehicle.
194
+ */
195
+ getVehicle(filterFc: FilterFunction): GeoJSONFeature[];
196
+ /**
197
+ * Request feature information for a given coordinate.
198
+ *
199
+ * @param {ol/coordinate~Coordinate} coordinate Coordinate.
200
+ * @param {Object} options Options See child classes to see which options are supported.
201
+ * @param {number} [options.resolution=1] The resolution of the map.
202
+ * @param {number} [options.nb=Infinity] The max number of vehicles to return.
203
+ * @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
204
+ */
205
+ getFeatureInfoAtCoordinate(coordinate: Coordinate, options: LayerGetFeatureInfoOptions): Promise<{
206
+ layer: any;
207
+ features: Feature<import("ol/geom/Geometry").default>[];
208
+ coordinate: Coordinate;
209
+ }>;
210
+ /**
211
+ * Request the stopSequence and the fullTrajectory informations for a vehicle.
212
+ *
213
+ * @param {string} id The vehicle identifier (the train_id property).
214
+ * @return {Promise<{stopSequence: StopSequence, fullTrajectory: FullTrajectory>} A promise that will be resolved with the trajectory informations.
215
+ */
216
+ getTrajectoryInfos(id: RealtimeTrainId): Promise<{
217
+ stopSequence: WebSocketAPIMessageEventData<import("../../types").RealtimeFullTrajectory> | WebSocketAPIMessageEventData<GeoJSONFeature[]>;
218
+ fullTrajectory: WebSocketAPIMessageEventData<import("../../types").RealtimeFullTrajectory> | WebSocketAPIMessageEventData<GeoJSONFeature[]>;
219
+ }>;
220
+ /**
221
+ * Remove all trajectories that are in the past.
222
+ */
223
+ purgeOutOfDateTrajectories(): void;
224
+ /**
225
+ * Determine if the trajectory is useless and should be removed from the list or not.
226
+ * By default, this function exclude vehicles:
227
+ * - that have their trajectory outside the current extent and
228
+ * - that aren't in the MOT list.
229
+ *
230
+ * @param {RealtimeTrajectory} trajectory
231
+ * @param {Array<number>} extent
232
+ * @param {number} zoom
233
+ * @return {boolean} if the trajectory must be displayed or not.
234
+ * @ignore
235
+ */
236
+ purgeTrajectory(trajectory: GeoJSONFeature, extent: [number, number, number, number], zoom: number): boolean;
237
+ /**
238
+ * Add a trajectory.
239
+ * @param {RealtimeTrajectory} trajectory The trajectory to add.
240
+ * @private
241
+ */
242
+ addTrajectory(trajectory: GeoJSONFeature): void;
243
+ removeTrajectory(trajectoryOrId: RealtimeTrajectory | RealtimeTrainId): void;
244
+ /**
245
+ * On zoomend we adjust the time interval of the update of vehicles positions.
246
+ *
247
+ * @param evt Event that triggered the function.
248
+ * @private
249
+ */
250
+ onZoomEnd(): void;
251
+ onDocumentVisibilityChange(): void;
252
+ /**
253
+ * Callback on websocket's trajectory channel events.
254
+ * It adds a trajectory to the list.
255
+ *
256
+ * @private
257
+ */
258
+ onTrajectoryMessage(data: WebSocketAPIMessageEventData<RealtimeTrajectory>): void;
259
+ /**
260
+ * Callback on websocket's deleted_vehicles channel events.
261
+ * It removes the trajectory from the list.
262
+ *
263
+ * @private
264
+ * @override
265
+ */
266
+ onDeleteTrajectoryMessage(data: WebSocketAPIMessageEventData<RealtimeTrainId>): void;
267
+ /**
268
+ * Callback when user moves the mouse/pointer over the map.
269
+ * It sets the layer's hoverVehicleId property with the current hovered vehicle's id.
270
+ *
271
+ * @private
272
+ * @override
273
+ */
274
+ onFeatureHover(features: Feature[], layer: AnyRealtimeLayer, coordinate: Coordinate): void;
275
+ /**
276
+ * Callback when user clicks on the map.
277
+ * It sets the layer's selectedVehicleId property with the current selected vehicle's id.
278
+ *
279
+ * @private
280
+ * @override
281
+ */
282
+ onFeatureClick(features: Feature[], layer: AnyRealtimeLayer, coordinate: Coordinate): void;
283
+ };
284
+ } & T;
285
+ export default RealtimeLayerMixin;
286
+ //# sourceMappingURL=RealtimeLayerMixin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RealtimeLayerMixin.d.ts","sourceRoot":"","sources":["../../../src/common/mixins/RealtimeLayerMixin.ts"],"names":[],"mappings":"AAOA,OAAO,OAAO,MAAM,mBAAmB,CAAC;AAIxC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAiB,MAAM,WAAW,CAAC;AAGvD,OAAO,EACL,SAAS,EACT,aAAa,EACb,MAAM,EACN,gBAAgB,EAChB,0BAA0B,EAC1B,2BAA2B,EAC3B,YAAY,EACZ,WAAW,EACX,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,SAAS,EACT,QAAQ,EACT,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAEnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,MAAM,yBAAyB,GAAG,cAAc,GAAG;IACvD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,GAAG,CAAC,EAAE,WAAW,CAAC;IAClB,MAAM,CAAC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