mobility-toolbox-js 2.0.0-beta.6 → 2.0.0-beta.62

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 (487) hide show
  1. package/README.md +29 -8
  2. package/api/RealtimeAPI.d.ts +279 -0
  3. package/api/RealtimeAPI.d.ts.map +1 -0
  4. package/api/RealtimeAPI.js +462 -0
  5. package/api/RoutingAPI.d.ts +37 -0
  6. package/api/RoutingAPI.d.ts.map +1 -0
  7. package/api/RoutingAPI.js +35 -0
  8. package/api/StopsAPI.d.ts +38 -0
  9. package/api/StopsAPI.d.ts.map +1 -0
  10. package/api/StopsAPI.js +36 -0
  11. package/api/index.d.ts +4 -0
  12. package/api/index.d.ts.map +1 -0
  13. package/api/index.js +3 -0
  14. package/api/typedefs.d.ts +179 -0
  15. package/api/typedefs.d.ts.map +1 -0
  16. package/{src/api/tralis → api}/typedefs.js +4 -10
  17. package/common/api/HttpAPI.d.ts +31 -0
  18. package/common/api/HttpAPI.d.ts.map +1 -0
  19. package/common/api/HttpAPI.js +57 -0
  20. package/common/api/WebSocketAPI.d.ts +153 -0
  21. package/common/api/WebSocketAPI.d.ts.map +1 -0
  22. package/common/api/WebSocketAPI.js +328 -0
  23. package/common/controls/ControlCommon.d.ts +76 -0
  24. package/common/controls/ControlCommon.d.ts.map +1 -0
  25. package/common/controls/ControlCommon.js +150 -0
  26. package/common/controls/CopyrightControlCommon.d.ts +13 -0
  27. package/common/controls/CopyrightControlCommon.d.ts.map +1 -0
  28. package/common/controls/CopyrightControlCommon.js +34 -0
  29. package/common/controls/StopFinderControlCommon.d.ts +55 -0
  30. package/common/controls/StopFinderControlCommon.d.ts.map +1 -0
  31. package/common/controls/StopFinderControlCommon.js +144 -0
  32. package/common/index.d.ts +3 -0
  33. package/common/index.d.ts.map +1 -0
  34. package/common/index.js +2 -0
  35. package/common/layers/LayerCommon.d.ts +94 -0
  36. package/common/layers/LayerCommon.d.ts.map +1 -0
  37. package/common/layers/LayerCommon.js +244 -0
  38. package/common/mixins/RealtimeLayerMixin.d.ts +289 -0
  39. package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
  40. package/common/mixins/RealtimeLayerMixin.js +746 -0
  41. package/common/mixins/UserInteractionsLayerMixin.d.ts +60 -0
  42. package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
  43. package/common/mixins/UserInteractionsLayerMixin.js +241 -0
  44. package/common/styles/index.d.ts +5 -0
  45. package/common/styles/index.d.ts.map +1 -0
  46. package/common/styles/index.js +4 -0
  47. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  48. package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
  49. package/common/styles/realtimeDefaultStyle.js +261 -0
  50. package/{src/common/styles/trackerDelayStyle.js → common/styles/realtimeDelayStyle.d.ts} +4 -9
  51. package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
  52. package/common/styles/realtimeDelayStyle.js +13 -0
  53. package/common/styles/realtimeSimpleStyle.d.ts +4 -0
  54. package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
  55. package/common/styles/realtimeSimpleStyle.js +24 -0
  56. package/common/typedefs.d.ts +111 -0
  57. package/common/typedefs.d.ts.map +1 -0
  58. package/common/typedefs.js +52 -0
  59. package/common/utils/compareDepartures.d.ts +11 -0
  60. package/common/utils/compareDepartures.d.ts.map +1 -0
  61. package/common/utils/compareDepartures.js +35 -0
  62. package/common/utils/createCanvas.d.ts +10 -0
  63. package/common/utils/createCanvas.d.ts.map +1 -0
  64. package/common/utils/createCanvas.js +27 -0
  65. package/common/utils/createRealtimeFilters.d.ts +13 -0
  66. package/common/utils/createRealtimeFilters.d.ts.map +1 -0
  67. package/common/utils/createRealtimeFilters.js +74 -0
  68. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  69. package/common/utils/debounceDeparturesMessages.d.ts.map +1 -0
  70. package/common/utils/debounceDeparturesMessages.js +24 -0
  71. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  72. package/common/utils/debounceWebsocketMessages.d.ts.map +1 -0
  73. package/common/utils/debounceWebsocketMessages.js +29 -0
  74. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  75. package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
  76. package/common/utils/getLayersAsFlatArray.js +15 -0
  77. package/common/utils/getMapboxMapCopyrights.d.ts +18 -0
  78. package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
  79. package/common/utils/getMapboxMapCopyrights.js +30 -0
  80. package/common/utils/getMapboxRender.d.ts +7 -0
  81. package/common/utils/getMapboxRender.d.ts.map +1 -0
  82. package/common/utils/getMapboxRender.js +87 -0
  83. package/common/utils/getMaplibreRender.d.ts +7 -0
  84. package/common/utils/getMaplibreRender.d.ts.map +1 -0
  85. package/common/utils/getMaplibreRender.js +38 -0
  86. package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
  87. package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
  88. package/common/utils/getRealtimeModeSuffix.js +7 -0
  89. package/common/utils/getUrlWithParams.d.ts +9 -0
  90. package/common/utils/getUrlWithParams.d.ts.map +1 -0
  91. package/common/utils/getUrlWithParams.js +18 -0
  92. package/common/utils/getVehiclePosition.d.ts +16 -0
  93. package/common/utils/getVehiclePosition.d.ts.map +1 -0
  94. package/common/utils/getVehiclePosition.js +63 -0
  95. package/common/utils/index.d.ts +16 -0
  96. package/common/utils/index.d.ts.map +1 -0
  97. package/common/utils/index.js +16 -0
  98. package/common/utils/realtimeConfig.d.ts +49 -0
  99. package/common/utils/realtimeConfig.d.ts.map +1 -0
  100. package/common/utils/realtimeConfig.js +173 -0
  101. package/common/utils/removeDuplicate.d.ts +10 -0
  102. package/common/utils/removeDuplicate.d.ts.map +1 -0
  103. package/common/utils/removeDuplicate.js +15 -0
  104. package/common/utils/renderTrajectories.d.ts +17 -0
  105. package/common/utils/renderTrajectories.d.ts.map +1 -0
  106. package/common/utils/renderTrajectories.js +121 -0
  107. package/common/utils/sortAndFilterDepartures.d.ts +16 -0
  108. package/common/utils/sortAndFilterDepartures.d.ts.map +1 -0
  109. package/common/utils/sortAndFilterDepartures.js +58 -0
  110. package/common/utils/sortByDelay.d.ts +3 -0
  111. package/common/utils/sortByDelay.d.ts.map +1 -0
  112. package/common/utils/sortByDelay.js +20 -0
  113. package/common/utils/timeUtils.d.ts +24 -0
  114. package/common/utils/timeUtils.d.ts.map +1 -0
  115. package/{src/common → common}/utils/timeUtils.js +13 -18
  116. package/iife.d.ts +3 -0
  117. package/iife.d.ts.map +1 -0
  118. package/{src/iife.js → iife.js} +2 -4
  119. package/index.d.ts +10 -0
  120. package/index.d.ts.map +1 -0
  121. package/index.js +10 -0
  122. package/mapbox/controls/CopyrightControl.d.ts +29 -0
  123. package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
  124. package/mapbox/controls/CopyrightControl.js +48 -0
  125. package/mapbox/controls/index.d.ts +2 -0
  126. package/mapbox/controls/index.d.ts.map +1 -0
  127. package/mapbox/controls/index.js +2 -0
  128. package/mapbox/index.d.ts +6 -0
  129. package/mapbox/index.d.ts.map +1 -0
  130. package/mapbox/index.js +5 -0
  131. package/mapbox/layers/Layer.d.ts +59 -0
  132. package/mapbox/layers/Layer.d.ts.map +1 -0
  133. package/mapbox/layers/Layer.js +101 -0
  134. package/mapbox/layers/RealtimeLayer.d.ts +180 -0
  135. package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
  136. package/mapbox/layers/RealtimeLayer.js +276 -0
  137. package/mapbox/layers/index.d.ts +3 -0
  138. package/mapbox/layers/index.d.ts.map +1 -0
  139. package/mapbox/layers/index.js +2 -0
  140. package/mapbox/utils/getMercatorResolution.d.ts +9 -0
  141. package/mapbox/utils/getMercatorResolution.d.ts.map +1 -0
  142. package/mapbox/utils/getMercatorResolution.js +18 -0
  143. package/mapbox/utils/getSourceCoordinates.d.ts +9 -0
  144. package/mapbox/utils/getSourceCoordinates.d.ts.map +1 -0
  145. package/mapbox/utils/getSourceCoordinates.js +27 -0
  146. package/mapbox/utils/index.d.ts +3 -0
  147. package/mapbox/utils/index.d.ts.map +1 -0
  148. package/mapbox/utils/index.js +2 -0
  149. package/mbt.js +50787 -0
  150. package/mbt.js.map +7 -0
  151. package/mbt.min.js +1083 -0
  152. package/mbt.min.js.map +7 -0
  153. package/ol/controls/CopyrightControl.d.ts +31 -0
  154. package/ol/controls/CopyrightControl.d.ts.map +1 -0
  155. package/ol/controls/CopyrightControl.js +68 -0
  156. package/ol/controls/RoutingControl.d.ts +193 -0
  157. package/ol/controls/RoutingControl.d.ts.map +1 -0
  158. package/ol/controls/RoutingControl.js +632 -0
  159. package/ol/controls/StopFinderControl.d.ts +30 -0
  160. package/ol/controls/StopFinderControl.d.ts.map +1 -0
  161. package/{src/ol → ol}/controls/StopFinderControl.js +10 -16
  162. package/ol/controls/index.d.ts +4 -0
  163. package/ol/controls/index.d.ts.map +1 -0
  164. package/ol/controls/index.js +3 -0
  165. package/ol/index.d.ts +6 -0
  166. package/ol/index.d.ts.map +1 -0
  167. package/ol/index.js +5 -0
  168. package/ol/layers/Layer.d.ts +86 -0
  169. package/ol/layers/Layer.d.ts.map +1 -0
  170. package/ol/layers/Layer.js +159 -0
  171. package/ol/layers/MapGlLayer.d.ts +67 -0
  172. package/ol/layers/MapGlLayer.d.ts.map +1 -0
  173. package/ol/layers/MapGlLayer.js +218 -0
  174. package/ol/layers/MapboxLayer.d.ts +50 -0
  175. package/ol/layers/MapboxLayer.d.ts.map +1 -0
  176. package/ol/layers/MapboxLayer.js +109 -0
  177. package/ol/layers/MapboxStyleLayer.d.ts +129 -0
  178. package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
  179. package/ol/layers/MapboxStyleLayer.js +374 -0
  180. package/ol/layers/MaplibreLayer.d.ts +28 -0
  181. package/ol/layers/MaplibreLayer.d.ts.map +1 -0
  182. package/ol/layers/MaplibreLayer.js +34 -0
  183. package/ol/layers/RealtimeLayer.d.ts +201 -0
  184. package/ol/layers/RealtimeLayer.d.ts.map +1 -0
  185. package/ol/layers/RealtimeLayer.js +310 -0
  186. package/ol/layers/RoutingLayer.d.ts +34 -0
  187. package/ol/layers/RoutingLayer.d.ts.map +1 -0
  188. package/ol/layers/RoutingLayer.js +85 -0
  189. package/ol/layers/VectorLayer.d.ts +25 -0
  190. package/ol/layers/VectorLayer.d.ts.map +1 -0
  191. package/ol/layers/VectorLayer.js +38 -0
  192. package/ol/layers/WMSLayer.d.ts +42 -0
  193. package/ol/layers/WMSLayer.d.ts.map +1 -0
  194. package/ol/layers/WMSLayer.js +88 -0
  195. package/ol/layers/index.d.ts +9 -0
  196. package/ol/layers/index.d.ts.map +1 -0
  197. package/ol/layers/index.js +8 -0
  198. package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
  199. package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
  200. package/ol/styles/fullTrajectoryDelayStyle.js +33 -0
  201. package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
  202. package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
  203. package/ol/styles/fullTrajectoryStyle.js +44 -0
  204. package/ol/styles/index.d.ts +3 -0
  205. package/ol/styles/index.d.ts.map +1 -0
  206. package/{src/ol → ol}/styles/index.js +0 -0
  207. package/package.json +71 -126
  208. package/setupTests.d.ts +2 -0
  209. package/setupTests.d.ts.map +1 -0
  210. package/{src/setupTests.js → setupTests.js} +0 -2
  211. package/types/common.d.ts +120 -0
  212. package/types/index.d.ts +11 -0
  213. package/types/realtime.d.ts +315 -0
  214. package/types/routing.d.ts +206 -0
  215. package/types/stops.d.ts +143 -0
  216. package/.babelrc +0 -6
  217. package/.esdoc.json +0 -17
  218. package/.eslintignore +0 -1
  219. package/.github/workflows/conventional-pr-title.yml +0 -21
  220. package/.github/workflows/cypress.yml +0 -29
  221. package/.github/workflows/nodejs.yml +0 -28
  222. package/.husky/commit-msg +0 -4
  223. package/.husky/post-checkout +0 -4
  224. package/.husky/post-merge +0 -4
  225. package/.husky/post-rebase +0 -4
  226. package/.husky/pre-commit +0 -4
  227. package/.neutrinorc.js +0 -176
  228. package/.nvmrc +0 -1
  229. package/CHANGELOG.md +0 -10
  230. package/LICENSE +0 -21
  231. package/Layer.js +0 -2
  232. package/Layer.js.map +0 -7
  233. package/__mocks__/mapbox-gl.js +0 -81
  234. package/__mocks__/maplibre-gl.js +0 -81
  235. package/commitlint.config.js +0 -1
  236. package/cypress/fixtures/example.json +0 -5
  237. package/cypress/integration/examples/api.spec.js +0 -7
  238. package/cypress/integration/examples/examples.spec.js +0 -7
  239. package/cypress/integration/examples/navigation.spec.js +0 -29
  240. package/cypress/plugins/index.js +0 -21
  241. package/cypress/support/commands.js +0 -25
  242. package/cypress/support/index.js +0 -20
  243. package/cypress.json +0 -4
  244. package/data/fetchRoute.json +0 -292
  245. package/data/fetchTrajectories.json +0 -18
  246. package/data/fetchTrajectoryById.json +0 -3
  247. package/data/fetchTrajectoryStations.json +0 -18
  248. package/data/stopsSearch.json +0 -15
  249. package/documentation.yml +0 -4
  250. package/esdoc/README.md +0 -27
  251. package/esdoc/plugins/MyPlugin.js +0 -69
  252. package/esdoc/plugins/dynamic-property-plugin/Plugin.js +0 -50
  253. package/esdoc/plugins/externals-plugin/Plugin.js +0 -45
  254. package/esdoc/plugins/externals-plugin/externals.js +0 -96
  255. package/global-setup.js +0 -3
  256. package/index.html +0 -0
  257. package/indexweb.html +0 -49
  258. package/jest.config.js +0 -5
  259. package/pull_request_template.md +0 -17
  260. package/renovate.json +0 -4
  261. package/scripts/read-pkg-json.js +0 -22
  262. package/src/api/index.js +0 -3
  263. package/src/api/routing/RoutingAPI.js +0 -44
  264. package/src/api/routing/RoutingAPI.test.js +0 -41
  265. package/src/api/stops/StopsAPI.js +0 -41
  266. package/src/api/stops/StopsAPI.test.js +0 -34
  267. package/src/api/tralis/TralisAPI.js +0 -731
  268. package/src/api/tralis/TralisAPI.test.js +0 -75
  269. package/src/api/tralis/TralisAPIUtils.js +0 -73
  270. package/src/api/tralis/WebSocketConnector.js +0 -338
  271. package/src/api/tralis/WebSocketConnector.test.js +0 -356
  272. package/src/assets/Lato-Black.ttf +0 -0
  273. package/src/assets/Lato-BlackItalic.ttf +0 -0
  274. package/src/assets/Lato-Bold.ttf +0 -0
  275. package/src/assets/Lato-BoldItalic.ttf +0 -0
  276. package/src/assets/Lato-Italic.ttf +0 -0
  277. package/src/assets/Lato-Light.ttf +0 -0
  278. package/src/assets/Lato-LightItalic.ttf +0 -0
  279. package/src/assets/Lato-Regular.ttf +0 -0
  280. package/src/assets/Lato-Thin.ttf +0 -0
  281. package/src/assets/Lato-ThinItalic.ttf +0 -0
  282. package/src/assets/OFL.txt +0 -93
  283. package/src/common/Tracker.js +0 -197
  284. package/src/common/api/api.js +0 -64
  285. package/src/common/api/api.test.js +0 -68
  286. package/src/common/controls/Control.js +0 -146
  287. package/src/common/controls/Control.test.js +0 -98
  288. package/src/common/layers/Layer.js +0 -404
  289. package/src/common/layers/Layer.test.js +0 -585
  290. package/src/common/mixins/CopyrightMixin.js +0 -48
  291. package/src/common/mixins/SearchMixin.js +0 -176
  292. package/src/common/mixins/TralisLayerMixin.js +0 -930
  293. package/src/common/styles/index.js +0 -4
  294. package/src/common/styles/trackerDefaultStyle.js +0 -333
  295. package/src/common/styles/trackerSimpleStyle.js +0 -22
  296. package/src/common/trackerConfig.js +0 -190
  297. package/src/common/trackerConfig.test.js +0 -25
  298. package/src/common/typedefs.js +0 -23
  299. package/src/common/utils/createTrackerFilters.js +0 -87
  300. package/src/common/utils/createTrackerFilters.test.js +0 -95
  301. package/src/common/utils/getMapboxMapCopyrights.js +0 -32
  302. package/src/common/utils/getMapboxMapCopyrights.test.js +0 -47
  303. package/src/common/utils/getMapboxStyleUrl.js +0 -32
  304. package/src/common/utils/getVehiclePosition.js +0 -72
  305. package/src/common/utils/index.js +0 -6
  306. package/src/common/utils/removeDuplicate.js +0 -22
  307. package/src/common/utils/removeDuplicate.test.js +0 -22
  308. package/src/common/utils/sortByDelay.js +0 -23
  309. package/src/common/utils/timeUtils.test.js +0 -16
  310. package/src/doc/App.js +0 -116
  311. package/src/doc/App.scss +0 -51
  312. package/src/doc/_redirects +0 -2
  313. package/src/doc/components/CodeSandboxButton.js +0 -103
  314. package/src/doc/components/Documentation.js +0 -40
  315. package/src/doc/components/Esdoc/Anchor.js +0 -57
  316. package/src/doc/components/Esdoc/ClassDoc.js +0 -272
  317. package/src/doc/components/Esdoc/DeprecatedHTML.js +0 -16
  318. package/src/doc/components/Esdoc/DetailDocs.js +0 -281
  319. package/src/doc/components/Esdoc/DetailHTML.js +0 -33
  320. package/src/doc/components/Esdoc/DirectSubclassHTML.js +0 -30
  321. package/src/doc/components/Esdoc/DocBuilderUtils.js +0 -694
  322. package/src/doc/components/Esdoc/DocLinkHTML.js +0 -62
  323. package/src/doc/components/Esdoc/DocsLinkHTML.js +0 -38
  324. package/src/doc/components/Esdoc/Esdoc.js +0 -63
  325. package/src/doc/components/Esdoc/EsdocContent.js +0 -51
  326. package/src/doc/components/Esdoc/EsdocNavigation.js +0 -13
  327. package/src/doc/components/Esdoc/EsdocSearch.js +0 -81
  328. package/src/doc/components/Esdoc/ExperimentalHTML.js +0 -17
  329. package/src/doc/components/Esdoc/ExtendsChainHTML.js +0 -32
  330. package/src/doc/components/Esdoc/FileDocLinkHTML.js +0 -60
  331. package/src/doc/components/Esdoc/IdentifiersDoc.js +0 -113
  332. package/src/doc/components/Esdoc/IndirectSubclassHTML.js +0 -30
  333. package/src/doc/components/Esdoc/InheritedSummaryDoc.js +0 -70
  334. package/src/doc/components/Esdoc/InheritedSummaryHTML.js +0 -38
  335. package/src/doc/components/Esdoc/MixinClassesHTML.js +0 -29
  336. package/src/doc/components/Esdoc/NavDoc.js +0 -112
  337. package/src/doc/components/Esdoc/OverrideMethod.js +0 -44
  338. package/src/doc/components/Esdoc/OverrideMethodDescription.js +0 -35
  339. package/src/doc/components/Esdoc/Properties.js +0 -89
  340. package/src/doc/components/Esdoc/README.md +0 -45
  341. package/src/doc/components/Esdoc/SignatureHTML.js +0 -123
  342. package/src/doc/components/Esdoc/SingleDoc.js +0 -31
  343. package/src/doc/components/Esdoc/SummaryDoc.js +0 -160
  344. package/src/doc/components/Esdoc/SummaryHTML.js +0 -96
  345. package/src/doc/components/Esdoc/TypeDocLinkHTML.js +0 -249
  346. package/src/doc/components/Esdoc/css/identifiers.css +0 -38
  347. package/src/doc/components/Esdoc/css/search.css +0 -76
  348. package/src/doc/components/Esdoc/css/style.css +0 -603
  349. package/src/doc/components/Esdoc/index.js +0 -7
  350. package/src/doc/components/Example.js +0 -153
  351. package/src/doc/components/Examples.js +0 -183
  352. package/src/doc/components/Home.js +0 -106
  353. package/src/doc/components/TrackerExample.js +0 -38
  354. package/src/doc/components/esm.min.js +0 -2
  355. package/src/doc/components/examples/assets/tralis-live-map/index.js +0 -11
  356. package/src/doc/components/examples/assets/tralis-live-map/s1kreis.svg +0 -105
  357. package/src/doc/components/examples/assets/tralis-live-map/s20kreis.svg +0 -101
  358. package/src/doc/components/examples/assets/tralis-live-map/s2kreis.svg +0 -95
  359. package/src/doc/components/examples/assets/tralis-live-map/s3kreis.svg +0 -95
  360. package/src/doc/components/examples/assets/tralis-live-map/s4kreis.svg +0 -95
  361. package/src/doc/components/examples/assets/tralis-live-map/s6kreis.svg +0 -95
  362. package/src/doc/components/examples/assets/tralis-live-map/s7kreis.svg +0 -95
  363. package/src/doc/components/examples/assets/tralis-live-map/s8kreis.svg +0 -93
  364. package/src/doc/components/examples/assets/tralis-live-map/unknown.svg +0 -107
  365. package/src/doc/components/examples/mb-copyright.html +0 -26
  366. package/src/doc/components/examples/mb-copyright.js +0 -37
  367. package/src/doc/components/examples/mb-tracker.html +0 -1
  368. package/src/doc/components/examples/mb-tracker.js +0 -39
  369. package/src/doc/components/examples/mb-tracker.md +0 -1
  370. package/src/doc/components/examples/mb-tralis.html +0 -1
  371. package/src/doc/components/examples/mb-tralis.js +0 -34
  372. package/src/doc/components/examples/ol-copyright.html +0 -26
  373. package/src/doc/components/examples/ol-copyright.js +0 -43
  374. package/src/doc/components/examples/ol-mapbox-layer.html +0 -1
  375. package/src/doc/components/examples/ol-mapbox-layer.js +0 -28
  376. package/src/doc/components/examples/ol-mapbox-layer.md +0 -0
  377. package/src/doc/components/examples/ol-mapbox-style-layer.html +0 -12
  378. package/src/doc/components/examples/ol-mapbox-style-layer.js +0 -44
  379. package/src/doc/components/examples/ol-query.html +0 -32
  380. package/src/doc/components/examples/ol-query.js +0 -83
  381. package/src/doc/components/examples/ol-routing.html +0 -26
  382. package/src/doc/components/examples/ol-routing.js +0 -59
  383. package/src/doc/components/examples/ol-routing.md +0 -1
  384. package/src/doc/components/examples/ol-stop-finder.html +0 -15
  385. package/src/doc/components/examples/ol-stop-finder.js +0 -31
  386. package/src/doc/components/examples/ol-stop-finder.md +0 -1
  387. package/src/doc/components/examples/ol-tracker.html +0 -1
  388. package/src/doc/components/examples/ol-tracker.js +0 -44
  389. package/src/doc/components/examples/ol-tracker.md +0 -1
  390. package/src/doc/components/examples/ol-tralis.html +0 -5
  391. package/src/doc/components/examples/ol-tralis.js +0 -57
  392. package/src/doc/components/examples/tralis-live-map.html +0 -1
  393. package/src/doc/components/examples/tralis-live-map.js +0 -51
  394. package/src/doc/components/examples/tralis-live-map.md +0 -3
  395. package/src/doc/examples/assets/tralis-live-map/index.js +0 -11
  396. package/src/doc/examples/assets/tralis-live-map/s1kreis.svg +0 -105
  397. package/src/doc/examples/assets/tralis-live-map/s20kreis.svg +0 -101
  398. package/src/doc/examples/assets/tralis-live-map/s2kreis.svg +0 -95
  399. package/src/doc/examples/assets/tralis-live-map/s3kreis.svg +0 -95
  400. package/src/doc/examples/assets/tralis-live-map/s4kreis.svg +0 -95
  401. package/src/doc/examples/assets/tralis-live-map/s6kreis.svg +0 -95
  402. package/src/doc/examples/assets/tralis-live-map/s7kreis.svg +0 -95
  403. package/src/doc/examples/assets/tralis-live-map/s8kreis.svg +0 -93
  404. package/src/doc/examples/assets/tralis-live-map/unknown.svg +0 -107
  405. package/src/doc/examples/mb-copyright.html +0 -26
  406. package/src/doc/examples/mb-copyright.js +0 -37
  407. package/src/doc/examples/mb-tracker.html +0 -1
  408. package/src/doc/examples/mb-tracker.js +0 -39
  409. package/src/doc/examples/mb-tracker.md +0 -1
  410. package/src/doc/examples/mb-tralis.html +0 -1
  411. package/src/doc/examples/mb-tralis.js +0 -34
  412. package/src/doc/examples/ol-copyright.html +0 -26
  413. package/src/doc/examples/ol-copyright.js +0 -43
  414. package/src/doc/examples/ol-mapbox-layer.html +0 -1
  415. package/src/doc/examples/ol-mapbox-layer.js +0 -28
  416. package/src/doc/examples/ol-mapbox-layer.md +0 -0
  417. package/src/doc/examples/ol-mapbox-style-layer.html +0 -12
  418. package/src/doc/examples/ol-mapbox-style-layer.js +0 -44
  419. package/src/doc/examples/ol-query.html +0 -32
  420. package/src/doc/examples/ol-query.js +0 -83
  421. package/src/doc/examples/ol-routing.html +0 -26
  422. package/src/doc/examples/ol-routing.js +0 -59
  423. package/src/doc/examples/ol-routing.md +0 -1
  424. package/src/doc/examples/ol-stop-finder.html +0 -15
  425. package/src/doc/examples/ol-stop-finder.js +0 -31
  426. package/src/doc/examples/ol-stop-finder.md +0 -1
  427. package/src/doc/examples/ol-tracker.html +0 -1
  428. package/src/doc/examples/ol-tracker.js +0 -44
  429. package/src/doc/examples/ol-tracker.md +0 -1
  430. package/src/doc/examples/ol-tralis.html +0 -5
  431. package/src/doc/examples/ol-tralis.js +0 -57
  432. package/src/doc/examples/tralis-live-map.html +0 -1
  433. package/src/doc/examples/tralis-live-map.js +0 -51
  434. package/src/doc/examples/tralis-live-map.md +0 -3
  435. package/src/doc/examples.js +0 -107
  436. package/src/doc/img/examples/live_tracker_mb.jpg +0 -0
  437. package/src/doc/img/examples/live_tracker_munich.jpg +0 -0
  438. package/src/doc/img/examples/live_tracker_ol.jpg +0 -0
  439. package/src/doc/img/examples/mapbox.jpg +0 -0
  440. package/src/doc/img/examples/mapbox_style.jpg +0 -0
  441. package/src/doc/img/examples/ol-copyright.png +0 -0
  442. package/src/doc/img/examples/query_objects.jpg +0 -0
  443. package/src/doc/img/examples/routing.jpg +0 -0
  444. package/src/doc/img/examples/simple_map.jpg +0 -0
  445. package/src/doc/img/examples/stops.jpg +0 -0
  446. package/src/doc/img/favico.ico +0 -0
  447. package/src/doc/index.js +0 -21
  448. package/src/index.js +0 -25
  449. package/src/mapbox/controls/CopyrightControl.js +0 -58
  450. package/src/mapbox/index.js +0 -3
  451. package/src/mapbox/layers/Layer.js +0 -118
  452. package/src/mapbox/layers/Layer.test.js +0 -202
  453. package/src/mapbox/layers/TralisLayer.js +0 -329
  454. package/src/mapbox/layers/TralisLayer.test.js +0 -40
  455. package/src/mapbox/utils.js +0 -46
  456. package/src/ol/README.md +0 -0
  457. package/src/ol/controls/CopyrightControl.js +0 -80
  458. package/src/ol/controls/CopyrightControl.test.js +0 -211
  459. package/src/ol/controls/RoutingControl.js +0 -752
  460. package/src/ol/controls/RoutingControl.test.js +0 -216
  461. package/src/ol/controls/StopFinderControl.test.js +0 -59
  462. package/src/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
  463. package/src/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
  464. package/src/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
  465. package/src/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
  466. package/src/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
  467. package/src/ol/controls/snapshots/RoutingControlStation1.json +0 -60
  468. package/src/ol/controls/snapshots/RoutingControlStation2.json +0 -49
  469. package/src/ol/index.js +0 -13
  470. package/src/ol/layers/Layer.js +0 -193
  471. package/src/ol/layers/Layer.test.js +0 -197
  472. package/src/ol/layers/MapboxLayer.js +0 -378
  473. package/src/ol/layers/MapboxLayer.test.js +0 -186
  474. package/src/ol/layers/MapboxStyleLayer.js +0 -417
  475. package/src/ol/layers/MapboxStyleLayer.test.js +0 -262
  476. package/src/ol/layers/MaplibreLayer.js +0 -280
  477. package/src/ol/layers/RoutingLayer.js +0 -91
  478. package/src/ol/layers/RoutingLayer.test.js +0 -49
  479. package/src/ol/layers/TralisLayer.js +0 -359
  480. package/src/ol/layers/TralisLayer.test.js +0 -97
  481. package/src/ol/layers/VectorLayer.js +0 -43
  482. package/src/ol/layers/VectorLayer.test.js +0 -98
  483. package/src/ol/layers/WMSLayer.js +0 -80
  484. package/src/ol/layers/WMSLayer.test.js +0 -84
  485. package/src/ol/styles/fullTrajectoryDelayStyle.js +0 -35
  486. package/src/ol/styles/fullTrajectoryStyle.js +0 -51
  487. package/webpack.config.js +0 -6
@@ -0,0 +1,746 @@
1
+ /* eslint-disable no-empty-function,@typescript-eslint/no-empty-function */
2
+ /* eslint-disable no-useless-constructor,@typescript-eslint/no-useless-constructor */
3
+ /* eslint-disable no-unused-vars,@typescript-eslint/no-unused-vars */
4
+ /* eslint-disable class-methods-use-this */
5
+ /* eslint-disable max-classes-per-file */
6
+ import { buffer, containsCoordinate, intersects } from 'ol/extent';
7
+ import { unByKey } from 'ol/Observable';
8
+ import GeoJSON from 'ol/format/GeoJSON';
9
+ import debounce from 'lodash.debounce';
10
+ import throttle from 'lodash.throttle';
11
+ import { fromLonLat } from 'ol/proj';
12
+ import realtimeDefaultStyle from '../styles/realtimeDefaultStyle';
13
+ import { RealtimeAPI, RealtimeModes } from '../../api';
14
+ import renderTrajectories from '../utils/renderTrajectories';
15
+ import * as realtimeConfig from '../utils/realtimeConfig';
16
+ /**
17
+ * RealtimeLayerInterface.
18
+ */
19
+ export class RealtimeLayerInterface {
20
+ /**
21
+ * Start the clock.
22
+ */
23
+ start() { }
24
+ /**
25
+ * Stop the clock.
26
+ */
27
+ stop() { }
28
+ /**
29
+ * Set the Realtime api's bbox.
30
+ *
31
+ * @param {Array<number>} extent Extent to request, [minX, minY, maxX, maxY, zoom].
32
+ * @param {number} zoom Zoom level to request. Must be an integer.
33
+ */
34
+ setBbox(extent, zoom) { }
35
+ /**
36
+ * Set the Realtime api's mode.
37
+ *
38
+ * @param {RealtimeMode} mode Realtime mode
39
+ */
40
+ setMode(mode) { }
41
+ /**
42
+ * Render the trajectories
43
+ */
44
+ renderTrajectories() { }
45
+ /**
46
+ * Request the stopSequence and the fullTrajectory informations for a vehicle.
47
+ *
48
+ * @param {string} id The vehicle identifier (the train_id property).
49
+ * @param {RealtimeMode} mode The mode to request. If not defined, the layer´s mode propetrty will be used.
50
+ * @return {Promise<{stopSequence: StopSequence, fullTrajectory: FullTrajectory>} A promise that will be resolved with the trajectory informations.
51
+ */
52
+ getTrajectoryInfos(id, mode) { }
53
+ }
54
+ /**
55
+ * Mixin for RealtimeLayerInterface.
56
+ *
57
+ * @param {Class} Base A class to extend with {RealtimeLayerInterface} functionnalities.
58
+ * @return {Class} A class that implements {RealtimeLayerInterface} class and extends Base;
59
+ * @private
60
+ */
61
+ function RealtimeLayerMixin(Base) {
62
+ // @ts-ignore
63
+ return class Mixin extends Base {
64
+ constructor(options) {
65
+ super(Object.assign({ hitTolerance: 10 }, options));
66
+ this.debug = options.debug || false;
67
+ this.mode = options.mode || RealtimeModes.TOPOGRAPHIC;
68
+ this.api = options.api || new RealtimeAPI(options);
69
+ this.tenant = options.tenant || ''; // sbb,sbh or sbm
70
+ this.minZoomInterpolation = options.minZoomInterpolation || 8; // Min zoom level from which trains positions are not interpolated.
71
+ this.format = new GeoJSON();
72
+ // MOTs by zoom
73
+ const allMots = [
74
+ 'tram',
75
+ 'subway',
76
+ 'rail',
77
+ 'bus',
78
+ 'ferry',
79
+ 'cablecar',
80
+ 'gondola',
81
+ 'funicular',
82
+ 'coach',
83
+ ];
84
+ // Server will block non train before zoom 9
85
+ this.motsByZoom = options.motsByZoom || [allMots];
86
+ this.getMotsByZoom = (zoom) => {
87
+ return ((options.getMotsByZoom &&
88
+ options.getMotsByZoom(zoom, this.motsByZoom)) ||
89
+ this.motsByZoom[zoom] ||
90
+ this.motsByZoom[this.motsByZoom.length - 1]);
91
+ };
92
+ // Generalization levels by zoom
93
+ this.generalizationLevelByZoom = options.generalizationLevelByZoom || [
94
+ 5, 5, 5, 5, 5, 5, 5, 5, 10, 30, 30, 100, 100, 100,
95
+ ];
96
+ this.getGeneralizationLevelByZoom = (zoom) => {
97
+ return ((options.getGeneralizationLevelByZoom &&
98
+ options.getGeneralizationLevelByZoom(zoom, this.generalizationLevelByZoom)) ||
99
+ this.generalizationLevelByZoom[zoom]);
100
+ };
101
+ // Render time interval by zoom
102
+ this.renderTimeIntervalByZoom = options.renderTimeIntervalByZoom || [
103
+ 100000, 50000, 40000, 30000, 20000, 15000, 10000, 5000, 2000, 1000, 400,
104
+ 300, 250, 180, 90, 60, 50, 50, 50, 50, 50,
105
+ ];
106
+ this.getRenderTimeIntervalByZoom = (zoom) => {
107
+ return ((options.getRenderTimeIntervalByZoom &&
108
+ options.getRenderTimeIntervalByZoom(zoom, this.renderTimeIntervalByZoom)) ||
109
+ this.renderTimeIntervalByZoom[zoom]);
110
+ };
111
+ // This property will call api.setBbox on each movend event
112
+ this.isUpdateBboxOnMoveEnd = options.isUpdateBboxOnMoveEnd !== false;
113
+ // Define throttling and debounce render function
114
+ this.throttleRenderTrajectories = throttle(this.renderTrajectoriesInternal, 50, { leading: false, trailing: true });
115
+ this.debounceRenderTrajectories = debounce(this.renderTrajectoriesInternal, 50, { leading: true, trailing: true, maxWait: 5000 });
116
+ // Bind callbacks
117
+ this.onFeatureHover = this.onFeatureHover.bind(this);
118
+ this.onFeatureClick = this.onFeatureClick.bind(this);
119
+ this.renderTrajectoriesInternal =
120
+ this.renderTrajectoriesInternal.bind(this);
121
+ this.onTrajectoryMessage = this.onTrajectoryMessage.bind(this);
122
+ this.onDeleteTrajectoryMessage =
123
+ this.onDeleteTrajectoryMessage.bind(this);
124
+ this.onDocumentVisibilityChange =
125
+ this.onDocumentVisibilityChange.bind(this);
126
+ }
127
+ /**
128
+ * Define layer's properties.
129
+ *
130
+ * @ignore
131
+ */
132
+ defineProperties(options) {
133
+ const { style, speed, pixelRatio, hoverVehicleId, selectedVehicleId, filter, sort, time, live, canvas, styleOptions, } = options;
134
+ let currCanvas = canvas;
135
+ let currSpeed = speed || 1;
136
+ let currTime = time || new Date();
137
+ let currStyle = style || realtimeDefaultStyle;
138
+ super.defineProperties(options);
139
+ Object.defineProperties(this, {
140
+ isTrackerLayer: { value: true },
141
+ canvas: {
142
+ get: () => {
143
+ if (!currCanvas) {
144
+ currCanvas = document.createElement('canvas');
145
+ }
146
+ return currCanvas;
147
+ },
148
+ set: (cnvas) => {
149
+ currCanvas = cnvas;
150
+ },
151
+ },
152
+ /**
153
+ * Style function used to render a vehicle.
154
+ */
155
+ style: {
156
+ get: () => currStyle,
157
+ set: (newStyle) => {
158
+ currStyle = newStyle;
159
+ // @ts-ignore function without parameters is defined in subclasses
160
+ this.renderTrajectories();
161
+ },
162
+ },
163
+ /**
164
+ * Custom options to pass as last parameter of the style function.
165
+ */
166
+ styleOptions: {
167
+ value: Object.assign(Object.assign({}, realtimeConfig), (styleOptions || {})),
168
+ },
169
+ /**
170
+ * Speed of the wheel of time.
171
+ * If live property is true. The speed is ignored.
172
+ */
173
+ speed: {
174
+ get: () => currSpeed,
175
+ set: (newSpeed) => {
176
+ currSpeed = newSpeed;
177
+ this.start();
178
+ },
179
+ },
180
+ /**
181
+ * Function to filter which vehicles to display.
182
+ */
183
+ filter: {
184
+ value: filter,
185
+ writable: true,
186
+ },
187
+ /**
188
+ * Function to sort the vehicles to display.
189
+ */
190
+ sort: {
191
+ value: sort,
192
+ writable: true,
193
+ },
194
+ /**
195
+ * If true. The layer will always use Date.now() on the next tick to render the trajectories.
196
+ * When true, setting the time property has no effect.
197
+ */
198
+ live: {
199
+ value: live === false ? live : true,
200
+ writable: true,
201
+ },
202
+ /**
203
+ * Time used to display the trajectories. Can be a Date or a number in ms representing a Date.
204
+ * If live property is true. The setter does nothing.
205
+ */
206
+ time: {
207
+ get: () => currTime,
208
+ set: (newTime) => {
209
+ currTime = newTime && newTime.getTime ? newTime : new Date(newTime);
210
+ // @ts-ignore function without parameters is defined in subclasses
211
+ this.renderTrajectories();
212
+ },
213
+ },
214
+ /**
215
+ * Keep track of which trajectories are stored.
216
+ */
217
+ trajectories: {
218
+ value: {},
219
+ writable: true,
220
+ },
221
+ /**
222
+ * Id of the hovered vehicle.
223
+ */
224
+ hoverVehicleId: {
225
+ value: hoverVehicleId,
226
+ writable: true,
227
+ },
228
+ /**
229
+ * Id of the selected vehicle.
230
+ */
231
+ selectedVehicleId: {
232
+ value: selectedVehicleId,
233
+ writable: true,
234
+ },
235
+ /**
236
+ * Id of the selected vehicle.
237
+ */
238
+ pixelRatio: {
239
+ value: pixelRatio ||
240
+ (typeof window !== 'undefined' ? window.devicePixelRatio : 1),
241
+ writable: true,
242
+ },
243
+ /**
244
+ * If true, encapsulates the renderTrajectories calls in a requestAnimationFrame.
245
+ */
246
+ useRequestAnimationFrame: {
247
+ value: options.useRequestAnimationFrame || false,
248
+ writable: true,
249
+ },
250
+ /**
251
+ * If true, encapsulates the renderTrajectories calls in a throttle function. Default to true.
252
+ */
253
+ useThrottle: {
254
+ value: options.useThrottle !== false,
255
+ writable: true,
256
+ },
257
+ /**
258
+ * If true, encapsulates the renderTrajectories calls in a debounce function.
259
+ */
260
+ useDebounce: {
261
+ value: options.useDebounce || false,
262
+ writable: true,
263
+ },
264
+ /**
265
+ * Debug properties.
266
+ */
267
+ // Not used anymore, but could be useful for debugging.
268
+ // showVehicleTraj: {
269
+ // value:
270
+ // options.showVehicleTraj !== undefined
271
+ // ? options.showVehicleTraj
272
+ // : true,
273
+ // writable: true,
274
+ // },
275
+ });
276
+ }
277
+ attachToMap(map) {
278
+ super.attachToMap(map);
279
+ // If the layer is visible we start the rendering clock
280
+ if (this.visible) {
281
+ this.start();
282
+ }
283
+ // On change of visibility we start/stop the rendering clock
284
+ this.visibilityRef = this.on('change:visible', (evt) => {
285
+ if (evt.target.visible) {
286
+ this.start();
287
+ }
288
+ else {
289
+ this.stop();
290
+ }
291
+ });
292
+ // To avoid browser hanging when the tab is not visible for a certain amount of time,
293
+ // We stop the rendering and the websocket when hide and start again when show.
294
+ document.addEventListener('visibilitychange', this.onDocumentVisibilityChange);
295
+ }
296
+ detachFromMap() {
297
+ document.removeEventListener('visibilitychange', this.onDocumentVisibilityChange);
298
+ this.stop();
299
+ unByKey(this.visibilityRef);
300
+ if (this.canvas) {
301
+ const context = this.canvas.getContext('2d');
302
+ context === null || context === void 0 ? void 0 : context.clearRect(0, 0, this.canvas.width, this.canvas.height);
303
+ super.detachFromMap();
304
+ }
305
+ }
306
+ start() {
307
+ this.stop();
308
+ // Before starting to update trajectories, we remove trajectories that have
309
+ // a time_intervals in the past, it will
310
+ // avoid phantom train that are at the end of their route because we never
311
+ // received the deleted_vehicle event because we have changed the browser tab.
312
+ this.purgeOutOfDateTrajectories();
313
+ // @ts-ignore function without parameters must be define in subclasses
314
+ this.renderTrajectories();
315
+ this.startUpdateTime();
316
+ this.api.open();
317
+ this.api.subscribeTrajectory(this.mode, this.onTrajectoryMessage, undefined, this.isUpdateBboxOnMoveEnd);
318
+ this.api.subscribeDeletedVehicles(this.mode, this.onDeleteTrajectoryMessage, undefined, this.isUpdateBboxOnMoveEnd);
319
+ if (this.isUpdateBboxOnMoveEnd) {
320
+ // Update the bbox on each move end
321
+ // @ts-ignore function without parameters defined by subclasses
322
+ this.setBbox();
323
+ }
324
+ }
325
+ /**
326
+ * Start the clock.
327
+ * @private
328
+ */
329
+ startUpdateTime() {
330
+ this.stopUpdateTime();
331
+ this.updateTimeDelay = this.getRefreshTimeInMs() || 0;
332
+ this.updateTimeInterval = window.setInterval(() => {
333
+ // When live=true, we update the time with new Date();
334
+ if (this.live) {
335
+ this.time = new Date();
336
+ }
337
+ else if (this.time && this.updateTimeDelay && this.speed) {
338
+ this.time = new Date(this.time.getTime() + this.updateTimeDelay * this.speed);
339
+ }
340
+ }, this.updateTimeDelay);
341
+ }
342
+ stop() {
343
+ this.api.unsubscribeTrajectory(this.onTrajectoryMessage);
344
+ this.api.unsubscribeDeletedVehicles(this.onDeleteTrajectoryMessage);
345
+ this.api.close();
346
+ }
347
+ /**
348
+ * Stop the clock.
349
+ * @private
350
+ */
351
+ stopUpdateTime() {
352
+ if (this.updateTimeInterval) {
353
+ clearInterval(this.updateTimeInterval);
354
+ this.updateTimeInterval = undefined;
355
+ }
356
+ }
357
+ /**
358
+ * Launch renderTrajectories. it avoids duplicating code in renderTrajectories method.
359
+ *
360
+ * @param {object} viewState The view state of the map.
361
+ * @param {number[2]} viewState.center Center coordinate of the map in mercator coordinate.
362
+ * @param {number[4]} viewState.extent Extent of the map in mercator coordinates.
363
+ * @param {number[2]} viewState.size Size ([width, height]) of the canvas to render.
364
+ * @param {number} [viewState.rotation = 0] Rotation of the map to render.
365
+ * @param {number} viewState.resolution Resolution of the map to render.
366
+ * @param {boolean} noInterpolate If true trajectories are not interpolated but
367
+ * drawn at the last known coordinate. Use this for performance optimization
368
+ * during map navigation.
369
+ * @private
370
+ */
371
+ renderTrajectoriesInternal(viewState, noInterpolate = false) {
372
+ var _a;
373
+ if (!this.map || !this.trajectories) {
374
+ return false;
375
+ }
376
+ const time = this.live ? Date.now() : (_a = this.time) === null || _a === void 0 ? void 0 : _a.getTime();
377
+ const trajectories = Object.values(this.trajectories);
378
+ // console.time('sort');
379
+ if (this.sort) {
380
+ // @ts-ignore
381
+ trajectories.sort(this.sort);
382
+ }
383
+ // console.timeEnd('sort');
384
+ if (!this.canvas || !this.style) {
385
+ return true;
386
+ }
387
+ // console.time('render');
388
+ this.renderState = renderTrajectories(this.canvas, trajectories, this.style, Object.assign(Object.assign({}, viewState), { pixelRatio: this.pixelRatio || 1, time }), Object.assign({ filter: this.filter, noInterpolate: (viewState.zoom || 0) < this.minZoomInterpolation
389
+ ? true
390
+ : noInterpolate, hoverVehicleId: this.hoverVehicleId, selectedVehicleId: this.selectedVehicleId }, this.styleOptions));
391
+ // console.timeEnd('render');
392
+ return true;
393
+ }
394
+ /**
395
+ * Render the trajectories requesting an animation frame and cancelling the previous one.
396
+ * This function must be overrided by children to provide the correct parameters.
397
+ *
398
+ * @param {object} viewState The view state of the map.
399
+ * @param {number[2]} viewState.center Center coordinate of the map in mercator coordinate.
400
+ * @param {number[4]} viewState.extent Extent of the map in mercator coordinates.
401
+ * @param {number[2]} viewState.size Size ([width, height]) of the canvas to render.
402
+ * @param {number} [viewState.rotation = 0] Rotation of the map to render.
403
+ * @param {number} viewState.resolution Resolution of the map to render.
404
+ * @param {boolean} noInterpolate If true trajectories are not interpolated but
405
+ * drawn at the last known coordinate. Use this for performance optimization
406
+ * during map navigation.
407
+ * @private
408
+ */
409
+ renderTrajectories(viewState, noInterpolate) {
410
+ if (this.requestId) {
411
+ cancelAnimationFrame(this.requestId);
412
+ this.requestId = undefined;
413
+ }
414
+ if (!viewState) {
415
+ return;
416
+ }
417
+ if (!noInterpolate && this.useRequestAnimationFrame) {
418
+ this.requestId = requestAnimationFrame(() => {
419
+ this.renderTrajectoriesInternal(viewState, noInterpolate);
420
+ });
421
+ }
422
+ else if (!noInterpolate && this.useDebounce) {
423
+ this.debounceRenderTrajectories(viewState, noInterpolate);
424
+ }
425
+ else if (!noInterpolate && this.useThrottle) {
426
+ this.throttleRenderTrajectories(viewState, noInterpolate);
427
+ }
428
+ else {
429
+ this.renderTrajectoriesInternal(viewState, noInterpolate);
430
+ }
431
+ }
432
+ setBbox(extent, zoom) {
433
+ // Clean trajectories before sending the new bbox
434
+ // Purge trajectories:
435
+ // - which are outside the extent
436
+ // - when it's bus and zoom level is too low for them
437
+ if (this.trajectories && extent && zoom) {
438
+ const keys = Object.keys(this.trajectories);
439
+ for (let i = keys.length - 1; i >= 0; i -= 1) {
440
+ this.purgeTrajectory(this.trajectories[keys[i]], extent, zoom);
441
+ }
442
+ }
443
+ if (!extent) {
444
+ return;
445
+ }
446
+ const bbox = [...extent];
447
+ if (this.isUpdateBboxOnMoveEnd && zoom) {
448
+ bbox.push(zoom);
449
+ if (this.tenant) {
450
+ bbox.push(`tenant=${this.tenant}`);
451
+ }
452
+ /* @ignore */
453
+ this.generalizationLevel = this.getGeneralizationLevelByZoom(zoom);
454
+ if (this.generalizationLevel) {
455
+ bbox.push(`gen=${this.generalizationLevel}`);
456
+ }
457
+ /* @ignore */
458
+ this.mots = this.getMotsByZoom(zoom);
459
+ if (this.mots) {
460
+ bbox.push(`mots=${this.mots}`);
461
+ }
462
+ }
463
+ this.api.bbox = bbox;
464
+ }
465
+ setMode(mode) {
466
+ if (this.mode === mode) {
467
+ return;
468
+ }
469
+ this.mode = mode;
470
+ this.api.subscribeTrajectory(this.mode, this.onTrajectoryMessage, undefined, this.isUpdateBboxOnMoveEnd);
471
+ this.api.subscribeDeletedVehicles(this.mode, this.onDeleteTrajectoryMessage, undefined, this.isUpdateBboxOnMoveEnd);
472
+ }
473
+ /**
474
+ * Get the duration before the next update depending on zoom level.
475
+ *
476
+ * @private
477
+ * @param {number} zoom
478
+ */
479
+ getRefreshTimeInMs(zoom = 0) {
480
+ var _a;
481
+ const roundedZoom = zoom !== undefined ? Math.round(zoom) : -1;
482
+ const timeStep = this.getRenderTimeIntervalByZoom(roundedZoom) || 25;
483
+ const nextTick = Math.max(25, timeStep / (this.speed || 1));
484
+ const nextThrottleTick = Math.min(nextTick, 500);
485
+ // TODO: see if this should go elsewhere.
486
+ if (this.useThrottle) {
487
+ this.throttleRenderTrajectories = throttle(this.renderTrajectoriesInternal, nextThrottleTick, { leading: true, trailing: true });
488
+ }
489
+ else if (this.useDebounce) {
490
+ this.debounceRenderTrajectories = debounce(this.renderTrajectoriesInternal, nextThrottleTick, { leading: true, trailing: true, maxWait: 5000 });
491
+ }
492
+ if ((_a = this.api) === null || _a === void 0 ? void 0 : _a.buffer) {
493
+ const [, size] = this.api.buffer;
494
+ this.api.buffer = [nextThrottleTick, size];
495
+ }
496
+ return nextTick;
497
+ }
498
+ /**
499
+ * Get vehicle.
500
+ * @param {function} filterFc A function use to filter results.
501
+ * @return {Array<Object>} Array of vehicle.
502
+ */
503
+ getVehicle(filterFc) {
504
+ return ((this.trajectories &&
505
+ // @ts-ignore
506
+ Object.values(this.trajectories).filter(filterFc)) ||
507
+ []);
508
+ }
509
+ /**
510
+ * Request feature information for a given coordinate.
511
+ *
512
+ * @param {ol/coordinate~Coordinate} coordinate Coordinate.
513
+ * @param {Object} options Options See child classes to see which options are supported.
514
+ * @param {number} [options.resolution=1] The resolution of the map.
515
+ * @param {number} [options.nb=Infinity] The max number of vehicles to return.
516
+ * @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
517
+ */
518
+ getFeatureInfoAtCoordinate(coordinate, options) {
519
+ const { resolution, nb } = options;
520
+ const ext = buffer([...coordinate, ...coordinate], this.hitTolerance * resolution);
521
+ let trajectories = Object.values(this.trajectories || {});
522
+ if (this.sort) {
523
+ // @ts-ignore
524
+ trajectories = trajectories.sort(this.sort);
525
+ }
526
+ const vehicles = [];
527
+ for (let i = 0; i < trajectories.length; i += 1) {
528
+ if (trajectories[i].properties.coordinate &&
529
+ containsCoordinate(ext, trajectories[i].properties.coordinate)) {
530
+ vehicles.push(trajectories[i]);
531
+ }
532
+ if (vehicles.length === nb) {
533
+ break;
534
+ }
535
+ }
536
+ return Promise.resolve({
537
+ layer: this,
538
+ features: vehicles.map((vehicle) => this.format.readFeature(vehicle)),
539
+ coordinate,
540
+ });
541
+ }
542
+ /**
543
+ * Request the stopSequence and the fullTrajectory informations for a vehicle.
544
+ *
545
+ * @param {string} id The vehicle identifier (the train_id property).
546
+ * @return {Promise<{stopSequence: StopSequence, fullTrajectory: FullTrajectory>} A promise that will be resolved with the trajectory informations.
547
+ */
548
+ getTrajectoryInfos(id) {
549
+ // When a vehicle is selected, we request the complete stop sequence and the complete full trajectory.
550
+ // Then we combine them in one response and send them to inherited layers.
551
+ const promises = [
552
+ this.api.getStopSequence(id),
553
+ this.api.getFullTrajectory(id, this.mode, this.generalizationLevel),
554
+ ];
555
+ return Promise.all(promises).then(([stopSequence, fullTrajectory]) => {
556
+ const response = {
557
+ stopSequence,
558
+ fullTrajectory,
559
+ };
560
+ return response;
561
+ });
562
+ }
563
+ /**
564
+ * Remove all trajectories that are in the past.
565
+ */
566
+ purgeOutOfDateTrajectories() {
567
+ Object.entries(this.trajectories || {}).forEach(([key, trajectory]) => {
568
+ var _a;
569
+ const timeIntervals = (_a = trajectory === null || trajectory === void 0 ? void 0 : trajectory.properties) === null || _a === void 0 ? void 0 : _a.time_intervals;
570
+ if (this.time && timeIntervals.length) {
571
+ const lastTimeInterval = timeIntervals[timeIntervals.length - 1][0];
572
+ if (lastTimeInterval < this.time) {
573
+ this.trackerLayer.removeTrajectory(key);
574
+ }
575
+ }
576
+ });
577
+ }
578
+ /**
579
+ * Determine if the trajectory is useless and should be removed from the list or not.
580
+ * By default, this function exclude vehicles:
581
+ * - that have their trajectory outside the current extent and
582
+ * - that aren't in the MOT list.
583
+ *
584
+ * @param {RealtimeTrajectory} trajectory
585
+ * @param {Array<number>} extent
586
+ * @param {number} zoom
587
+ * @return {boolean} if the trajectory must be displayed or not.
588
+ * @ignore
589
+ */
590
+ purgeTrajectory(trajectory, extent, zoom) {
591
+ const { type, bounds } = trajectory.properties;
592
+ if (!intersects(extent, bounds) ||
593
+ (this.mots && !this.mots.includes(type)) ||
594
+ (type !== 'rail' && zoom < 9) // zoom 9 is defined by the backend
595
+ ) {
596
+ this.removeTrajectory(trajectory);
597
+ return true;
598
+ }
599
+ return false;
600
+ }
601
+ /**
602
+ * Add a trajectory.
603
+ * @param {RealtimeTrajectory} trajectory The trajectory to add.
604
+ * @private
605
+ */
606
+ addTrajectory(trajectory) {
607
+ if (this.filter && !this.filter(trajectory)) {
608
+ return;
609
+ }
610
+ if (!this.trajectories) {
611
+ this.trajectories = {};
612
+ }
613
+ this.trajectories[trajectory.properties.train_id] = trajectory;
614
+ // @ts-ignore the parameter are set by subclasses
615
+ this.renderTrajectories();
616
+ }
617
+ removeTrajectory(trajectoryOrId) {
618
+ var _a;
619
+ let id;
620
+ if (typeof trajectoryOrId !== 'string') {
621
+ id = (_a = trajectoryOrId === null || trajectoryOrId === void 0 ? void 0 : trajectoryOrId.properties) === null || _a === void 0 ? void 0 : _a.train_id;
622
+ }
623
+ else {
624
+ id = trajectoryOrId;
625
+ }
626
+ if (this.trajectories) {
627
+ delete this.trajectories[id];
628
+ }
629
+ }
630
+ /**
631
+ * On zoomend we adjust the time interval of the update of vehicles positions.
632
+ *
633
+ * @param evt Event that triggered the function.
634
+ * @private
635
+ */
636
+ onZoomEnd() {
637
+ this.startUpdateTime();
638
+ }
639
+ onDocumentVisibilityChange() {
640
+ if (!this.visible) {
641
+ return;
642
+ }
643
+ if (document.hidden) {
644
+ this.stop();
645
+ // Since we don't receive deleted_vehicles event when docuement
646
+ // is hidden. We have to clean all the trajectories for a fresh
647
+ // start when the document is visible again.
648
+ this.trajectories = {};
649
+ }
650
+ else {
651
+ this.start();
652
+ }
653
+ }
654
+ /**
655
+ * Callback on websocket's trajectory channel events.
656
+ * It adds a trajectory to the list.
657
+ *
658
+ * @private
659
+ */
660
+ onTrajectoryMessage(data) {
661
+ if (!data.content) {
662
+ return;
663
+ }
664
+ const trajectory = data.content;
665
+ const { geometry, properties: { train_id: id, time_since_update: timeSinceUpdate, raw_coordinates: rawCoordinates, }, } = trajectory;
666
+ // ignore old events [SBAHNM-97]
667
+ if (timeSinceUpdate < 0) {
668
+ return;
669
+ }
670
+ // console.time(`onTrajectoryMessage${data.content.properties.train_id}`);
671
+ // @ts-ignore default value for extentand zoom are provided by subclasses
672
+ if (this.purgeTrajectory(trajectory)) {
673
+ return;
674
+ }
675
+ if (this.debug &&
676
+ this.mode === RealtimeModes.TOPOGRAPHIC &&
677
+ rawCoordinates) {
678
+ trajectory.properties.olGeometry = {
679
+ type: 'Point',
680
+ coordinates: fromLonLat(rawCoordinates, this.map.getView().getProjection()),
681
+ };
682
+ }
683
+ else {
684
+ trajectory.properties.olGeometry = this.format.readGeometry(geometry);
685
+ }
686
+ // TODO Make sure the timeOffset is useful. May be we can remove it.
687
+ trajectory.properties.timeOffset = Date.now() - data.timestamp;
688
+ this.addTrajectory(trajectory);
689
+ }
690
+ /**
691
+ * Callback on websocket's deleted_vehicles channel events.
692
+ * It removes the trajectory from the list.
693
+ *
694
+ * @private
695
+ * @override
696
+ */
697
+ onDeleteTrajectoryMessage(data) {
698
+ if (!data.content) {
699
+ return;
700
+ }
701
+ this.removeTrajectory(data.content);
702
+ }
703
+ /**
704
+ * Callback when user moves the mouse/pointer over the map.
705
+ * It sets the layer's hoverVehicleId property with the current hovered vehicle's id.
706
+ *
707
+ * @private
708
+ * @override
709
+ */
710
+ onFeatureHover(features, layer, coordinate) {
711
+ const [feature] = features;
712
+ let id = null;
713
+ if (feature) {
714
+ id = feature.get('train_id');
715
+ }
716
+ if (this.hoverVehicleId !== id) {
717
+ /** @ignore */
718
+ this.hoverVehicleId = id;
719
+ // @ts-ignore
720
+ this.renderTrajectories(true);
721
+ }
722
+ }
723
+ /**
724
+ * Callback when user clicks on the map.
725
+ * It sets the layer's selectedVehicleId property with the current selected vehicle's id.
726
+ *
727
+ * @private
728
+ * @override
729
+ */
730
+ onFeatureClick(features, layer, coordinate) {
731
+ const [feature] = features;
732
+ let id = null;
733
+ if (feature) {
734
+ id = feature.get('train_id');
735
+ }
736
+ if (this.selectedVehicleId !== id) {
737
+ /** @ignore */
738
+ this.selectedVehicleId = id;
739
+ this.selectedVehicle = feature;
740
+ // @ts-ignore parameters are provided by subclasses
741
+ this.renderTrajectories(true);
742
+ }
743
+ }
744
+ };
745
+ }
746
+ export default RealtimeLayerMixin;