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