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
@@ -1,1168 +0,0 @@
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 { EventsKey } from 'ol/events';
13
- import { ObjectEvent } from 'ol/Object';
14
- import { Coordinate } from 'ol/coordinate';
15
- import { Feature } from 'ol';
16
- import realtimeDefaultStyle from '../styles/realtimeDefaultStyle';
17
- import { RealtimeAPI, RealtimeModes } from '../../api';
18
- import renderTrajectories from '../utils/renderTrajectories';
19
- import * as realtimeConfig from '../utils/realtimeConfig';
20
- import {
21
- AnyCanvas,
22
- AnyLayerClass,
23
- AnyMap,
24
- AnyRealtimeLayer,
25
- LayerGetFeatureInfoOptions,
26
- RealtimeGeneralizationLevel,
27
- RealtimeMode,
28
- RealtimeMot,
29
- RealtimeRenderState,
30
- RealtimeStyleFunction,
31
- RealtimeStyleOptions,
32
- RealtimeTenant,
33
- RealtimeTrainId,
34
- ViewState,
35
- AnyLayer,
36
- LayerGetFeatureInfoResponse,
37
- } from '../../types';
38
- import { RealtimeTrajectory } from '../../api/typedefs';
39
- import { WebSocketAPIMessageEventData } from '../api/WebSocketAPI';
40
- import LayerCommon from '../layers/LayerCommon';
41
- import type { OlLayerOptions } from '../../ol/layers/Layer';
42
- import { FilterFunction, SortFunction } from '../typedefs';
43
-
44
- export type RealtimeLayerMixinOptions = OlLayerOptions & {
45
- debug?: boolean;
46
- mode?: RealtimeMode;
47
- api?: RealtimeAPI;
48
- tenant?: RealtimeTenant;
49
- minZoomInterpolation?: number;
50
- isUpdateBboxOnMoveEnd?: boolean;
51
- motsByZoom?: RealtimeMot[][];
52
- generalizationLevelByZoom?: RealtimeGeneralizationLevel[];
53
- renderTimeIntervalByZoom?: number[];
54
- style?: RealtimeStyleFunction;
55
- speed?: number;
56
- pixelRatio?: number;
57
- hoverVehicleId?: RealtimeTrainId;
58
- selectedVehicleId?: RealtimeTrainId;
59
- filter?: FilterFunction;
60
- sort?: SortFunction;
61
- time?: number;
62
- live?: boolean;
63
- canvas?: HTMLCanvasElement;
64
- styleOptions?: RealtimeStyleOptions;
65
- useRequestAnimationFrame?: boolean;
66
- useDebounce?: boolean;
67
- useThrottle?: boolean;
68
- getMotsByZoom?: (zoom: number, motsByZoom: RealtimeMot[][]) => RealtimeMot[];
69
- getGeneralizationLevelByZoom?: (
70
- zoom: number,
71
- generalizationLevelByZoom: RealtimeGeneralizationLevel[],
72
- ) => RealtimeGeneralizationLevel;
73
- getRenderTimeIntervalByZoom?: (
74
- zoom: number,
75
- renderTimeIntervalByZoom: number[],
76
- ) => number;
77
- onStart?: (realtimeLayer: AnyRealtimeLayer) => void;
78
- onStop?: (realtimeLayer: AnyRealtimeLayer) => void;
79
-
80
- // From RealtimeAPIOptions
81
- url?: string;
82
- apiKey?: string;
83
- prefix?: string;
84
- bbox?: (number | string)[];
85
- buffer?: number[];
86
- pingIntervalMs?: number;
87
- bboxParameters?: {
88
- [index: string]:
89
- | string
90
- | number
91
- | boolean
92
- | string[]
93
- | boolean[]
94
- | number[];
95
- };
96
- };
97
-
98
- /**
99
- * RealtimeLayerInterface.
100
- */
101
- export class RealtimeLayerInterface {
102
- /**
103
- * Start the clock.
104
- */
105
- start() {}
106
-
107
- /**
108
- * Stop the clock.
109
- */
110
- stop() {}
111
-
112
- /**
113
- * Set the Realtime api's bbox.
114
- *
115
- * @param {Array<number>} extent Extent to request, [minX, minY, maxX, maxY].
116
- * @param {number} zoom Zoom level to request. Must be an integer.
117
- */
118
- setBbox(extent: [number, number, number, number], zoom: number) {}
119
-
120
- /**
121
- * Render the trajectories
122
- */
123
- renderTrajectories() {}
124
-
125
- /**
126
- * Request the stopSequence and the fullTrajectory informations for a vehicle.
127
- *
128
- * @param {string} id The vehicle identifier (the train_id property).
129
- * @param {RealtimeMode} mode The mode to request. If not defined, the layer´s mode propetrty will be used.
130
- * @return {Promise<{stopSequence: StopSequence, fullTrajectory: FullTrajectory>} A promise that will be resolved with the trajectory informations.
131
- */
132
- getTrajectoryInfos(id: string, mode: RealtimeMode) {}
133
- }
134
-
135
- /**
136
- * Mixin for RealtimeLayerInterface.
137
- *
138
- * @param {Class} Base A class to extend with {RealtimeLayerInterface} functionnalities.
139
- * @return {Class} A class that implements {RealtimeLayerInterface} class and extends Base;
140
- * @private
141
- */
142
- function RealtimeLayerMixin<T extends AnyLayerClass>(Base: T) {
143
- // @ts-ignore
144
- return class Mixin extends Base {
145
- debug: boolean;
146
-
147
- trajectories?: { [key: RealtimeTrainId]: RealtimeTrajectory };
148
-
149
- canvas?: AnyCanvas;
150
-
151
- mode: RealtimeMode;
152
-
153
- api: RealtimeAPI;
154
-
155
- tenant: RealtimeTenant;
156
-
157
- bboxParameters?: {
158
- [index: string]:
159
- | string
160
- | number
161
- | boolean
162
- | string[]
163
- | boolean[]
164
- | number[];
165
- };
166
-
167
- time?: Date;
168
-
169
- live?: boolean;
170
-
171
- speed?: number;
172
-
173
- filter?: FilterFunction;
174
-
175
- sort?: SortFunction;
176
-
177
- style?: RealtimeStyleFunction;
178
-
179
- styleOptions?: RealtimeStyleOptions;
180
-
181
- pixelRatio?: number;
182
-
183
- minZoomInterpolation: number;
184
-
185
- isUpdateBboxOnMoveEnd: boolean;
186
-
187
- hoverVehicleId?: RealtimeTrainId;
188
-
189
- selectedVehicleId?: RealtimeTrainId;
190
-
191
- renderState?: RealtimeRenderState;
192
-
193
- useRequestAnimationFrame?: boolean;
194
-
195
- useDebounce?: boolean;
196
-
197
- useThrottle?: boolean;
198
-
199
- mots?: RealtimeMot[];
200
-
201
- motsByZoom: RealtimeMot[][];
202
-
203
- generalizationLevel?: RealtimeGeneralizationLevel;
204
-
205
- generalizationLevelByZoom: RealtimeGeneralizationLevel[];
206
-
207
- renderTimeIntervalByZoom: number[];
208
-
209
- format: GeoJSON;
210
-
211
- requestId?: number;
212
-
213
- updateTimeInterval?: number;
214
-
215
- updateTimeDelay?: number;
216
-
217
- visibilityRef!: EventsKey;
218
-
219
- selectedVehicle: RealtimeTrajectory;
220
-
221
- getMotsByZoom: (zoom: number) => RealtimeMot[];
222
-
223
- getGeneralizationLevelByZoom: (zoom: number) => RealtimeGeneralizationLevel;
224
-
225
- getRenderTimeIntervalByZoom: (zoom: number) => number;
226
-
227
- throttleRenderTrajectories: (
228
- viewState: ViewState,
229
- noInterpolate?: boolean,
230
- ) => void;
231
-
232
- debounceRenderTrajectories: (
233
- viewState: ViewState,
234
- noInterpolate?: boolean,
235
- ) => void;
236
-
237
- onStart?: (realtimeLayer: AnyLayer) => void;
238
-
239
- onStop?: (realtimeLayer: AnyLayer) => void;
240
-
241
- constructor(options: RealtimeLayerMixinOptions) {
242
- super({
243
- hitTolerance: 10,
244
- ...options,
245
- });
246
-
247
- this.debug = options.debug || false;
248
- this.mode = options.mode || (RealtimeModes.TOPOGRAPHIC as RealtimeMode);
249
- this.api = options.api || new RealtimeAPI(options);
250
- this.tenant = options.tenant || ''; // sbb,sbh or sbm
251
- this.minZoomInterpolation = options.minZoomInterpolation || 8; // Min zoom level from which trains positions are not interpolated.
252
- this.format = new GeoJSON();
253
- this.onStart = options.onStart;
254
- this.onStop = options.onStop;
255
-
256
- // Server will block non train before zoom 9
257
- this.motsByZoom = options.motsByZoom || [
258
- realtimeConfig.MOTS_ONLY_RAIL,
259
- realtimeConfig.MOTS_ONLY_RAIL,
260
- realtimeConfig.MOTS_ONLY_RAIL,
261
- realtimeConfig.MOTS_ONLY_RAIL,
262
- realtimeConfig.MOTS_ONLY_RAIL,
263
- realtimeConfig.MOTS_ONLY_RAIL,
264
- realtimeConfig.MOTS_ONLY_RAIL,
265
- realtimeConfig.MOTS_ONLY_RAIL,
266
- realtimeConfig.MOTS_ONLY_RAIL,
267
- realtimeConfig.MOTS_WITHOUT_CABLE,
268
- realtimeConfig.MOTS_WITHOUT_CABLE,
269
- ];
270
-
271
- this.getMotsByZoom = (zoom) => {
272
- if (options.getMotsByZoom) {
273
- return options.getMotsByZoom(zoom, this.motsByZoom);
274
- }
275
- return this.motsByZoom[zoom];
276
- };
277
-
278
- // Generalization levels by zoom
279
- this.generalizationLevelByZoom = options.generalizationLevelByZoom || [];
280
- this.getGeneralizationLevelByZoom = (zoom) => {
281
- if (options.getGeneralizationLevelByZoom) {
282
- return options.getGeneralizationLevelByZoom(
283
- zoom,
284
- this.generalizationLevelByZoom,
285
- );
286
- }
287
- return this.generalizationLevelByZoom[zoom];
288
- };
289
-
290
- // Render time interval by zoom
291
- this.renderTimeIntervalByZoom = options.renderTimeIntervalByZoom || [
292
- 100000, 50000, 40000, 30000, 20000, 15000, 10000, 5000, 2000, 1000, 400,
293
- 300, 250, 180, 90, 60, 50, 50, 50, 50, 50,
294
- ];
295
-
296
- this.getRenderTimeIntervalByZoom = (zoom) => {
297
- if (options.getRenderTimeIntervalByZoom) {
298
- return options.getRenderTimeIntervalByZoom(
299
- zoom,
300
- this.renderTimeIntervalByZoom,
301
- );
302
- }
303
- return this.renderTimeIntervalByZoom[zoom];
304
- };
305
-
306
- // This property will call api.setBbox on each movend event
307
- this.isUpdateBboxOnMoveEnd = options.isUpdateBboxOnMoveEnd !== false;
308
-
309
- // Define throttling and debounce render function
310
- this.throttleRenderTrajectories = throttle(
311
- this.renderTrajectoriesInternal,
312
- 50,
313
- { leading: false, trailing: true },
314
- );
315
-
316
- this.debounceRenderTrajectories = debounce(
317
- this.renderTrajectoriesInternal,
318
- 50,
319
- { leading: true, trailing: true, maxWait: 5000 },
320
- );
321
-
322
- // Bind callbacks
323
- this.onFeatureHover = this.onFeatureHover.bind(this);
324
- this.onFeatureClick = this.onFeatureClick.bind(this);
325
- this.renderTrajectoriesInternal =
326
- this.renderTrajectoriesInternal.bind(this);
327
- this.onTrajectoryMessage = this.onTrajectoryMessage.bind(this);
328
- this.onDeleteTrajectoryMessage =
329
- this.onDeleteTrajectoryMessage.bind(this);
330
- this.onDocumentVisibilityChange =
331
- this.onDocumentVisibilityChange.bind(this);
332
- }
333
-
334
- /**
335
- * Define layer's properties.
336
- *
337
- * @private
338
- */
339
- defineProperties(options: RealtimeLayerMixinOptions) {
340
- const {
341
- style,
342
- speed,
343
- pixelRatio,
344
- hoverVehicleId,
345
- selectedVehicleId,
346
- filter,
347
- sort,
348
- time,
349
- live,
350
- canvas,
351
- styleOptions,
352
- mode,
353
- bboxParameters,
354
- } = options;
355
-
356
- let currCanvas = canvas;
357
- let currSpeed = speed || 1;
358
- let currTime = time || new Date();
359
- let currMode = mode || (RealtimeModes.TOPOGRAPHIC as RealtimeMode);
360
- let currStyle = style || realtimeDefaultStyle;
361
-
362
- super.defineProperties(options);
363
-
364
- Object.defineProperties(this, {
365
- isTrackerLayer: { value: true },
366
-
367
- canvas: {
368
- get: () => {
369
- if (!currCanvas) {
370
- currCanvas = document.createElement('canvas');
371
- }
372
- return currCanvas;
373
- },
374
- set: (cnvas: HTMLCanvasElement) => {
375
- currCanvas = cnvas;
376
- },
377
- },
378
-
379
- /**
380
- * Style function used to render a vehicle.
381
- */
382
- mode: {
383
- get: () => currMode,
384
- set: (newMode: RealtimeMode) => {
385
- if (newMode === currMode) {
386
- return;
387
- }
388
- currMode = newMode;
389
- if (this.api?.wsApi?.open) {
390
- this.stop();
391
- this.start();
392
- }
393
- },
394
- },
395
-
396
- /**
397
- * Style function used to render a vehicle.
398
- */
399
- style: {
400
- get: () => currStyle,
401
- set: (newStyle: RealtimeStyleFunction) => {
402
- currStyle = newStyle;
403
- // @ts-ignore function without parameters is defined in subclasses
404
- this.renderTrajectories();
405
- },
406
- },
407
-
408
- /**
409
- * Custom options to pass as last parameter of the style function.
410
- */
411
- styleOptions: {
412
- value: { ...realtimeConfig, ...(styleOptions || {}) },
413
- },
414
-
415
- /**
416
- * Speed of the wheel of time.
417
- * If live property is true. The speed is ignored.
418
- */
419
- speed: {
420
- get: () => currSpeed,
421
- set: (newSpeed) => {
422
- currSpeed = newSpeed;
423
- this.start();
424
- },
425
- },
426
-
427
- /**
428
- * Custom parameters to send on each BBOX request.
429
- */
430
- bboxParameters: {
431
- value: bboxParameters,
432
- writable: true,
433
- },
434
-
435
- /**
436
- * Function to filter which vehicles to display.
437
- */
438
- filter: {
439
- value: filter,
440
- writable: true,
441
- },
442
-
443
- /**
444
- * Function to sort the vehicles to display.
445
- */
446
- sort: {
447
- value: sort,
448
- writable: true,
449
- },
450
-
451
- /**
452
- * If true. The layer will always use Date.now() on the next tick to render the trajectories.
453
- * When true, setting the time property has no effect.
454
- */
455
- live: {
456
- value: live === false ? live : true,
457
- writable: true,
458
- },
459
-
460
- /**
461
- * Time used to display the trajectories. Can be a Date or a number in ms representing a Date.
462
- * If live property is true. The setter does nothing.
463
- */
464
- time: {
465
- get: () => currTime,
466
- set: (newTime) => {
467
- currTime = newTime && newTime.getTime ? newTime : new Date(newTime);
468
- // @ts-ignore function without parameters is defined in subclasses
469
- this.renderTrajectories();
470
- },
471
- },
472
-
473
- /**
474
- * Keep track of which trajectories are stored.
475
- */
476
- trajectories: {
477
- value: {},
478
- writable: true,
479
- },
480
-
481
- /**
482
- * Id of the hovered vehicle.
483
- */
484
- hoverVehicleId: {
485
- value: hoverVehicleId,
486
- writable: true,
487
- },
488
-
489
- /**
490
- * Id of the selected vehicle.
491
- */
492
- selectedVehicleId: {
493
- value: selectedVehicleId,
494
- writable: true,
495
- },
496
-
497
- /**
498
- * Id of the selected vehicle.
499
- */
500
- pixelRatio: {
501
- value:
502
- pixelRatio ||
503
- (typeof window !== 'undefined' ? window.devicePixelRatio : 1),
504
- writable: true,
505
- },
506
-
507
- /**
508
- * If true, encapsulates the renderTrajectories calls in a requestAnimationFrame.
509
- */
510
- useRequestAnimationFrame: {
511
- value: options.useRequestAnimationFrame || false,
512
- writable: true,
513
- },
514
-
515
- /**
516
- * If true, encapsulates the renderTrajectories calls in a throttle function. Default to true.
517
- */
518
- useThrottle: {
519
- value: options.useThrottle !== false,
520
- writable: true,
521
- },
522
-
523
- /**
524
- * If true, encapsulates the renderTrajectories calls in a debounce function.
525
- */
526
- useDebounce: {
527
- value: options.useDebounce || false,
528
- writable: true,
529
- },
530
-
531
- /**
532
- * Debug properties.
533
- */
534
- // Not used anymore, but could be useful for debugging.
535
- // showVehicleTraj: {
536
- // value:
537
- // options.showVehicleTraj !== undefined
538
- // ? options.showVehicleTraj
539
- // : true,
540
- // writable: true,
541
- // },
542
- });
543
- }
544
-
545
- attachToMap(map: AnyMap) {
546
- super.attachToMap(map);
547
-
548
- // If the layer is visible we start the rendering clock
549
- if (this.visible) {
550
- this.start();
551
- }
552
-
553
- // On change of visibility we start/stop the rendering clock
554
- this.visibilityRef = this.on('change:visible', (evt: ObjectEvent) => {
555
- if ((evt.target as unknown as LayerCommon).visible) {
556
- this.start();
557
- } else {
558
- this.stop();
559
- }
560
- });
561
-
562
- // To avoid browser hanging when the tab is not visible for a certain amount of time,
563
- // We stop the rendering and the websocket when hide and start again when show.
564
- document.addEventListener(
565
- 'visibilitychange',
566
- this.onDocumentVisibilityChange,
567
- );
568
- }
569
-
570
- detachFromMap() {
571
- document.removeEventListener(
572
- 'visibilitychange',
573
- this.onDocumentVisibilityChange,
574
- );
575
-
576
- this.stop();
577
- unByKey(this.visibilityRef);
578
- if (this.canvas) {
579
- const context = this.canvas.getContext('2d');
580
- if (context) {
581
- context.clearRect(0, 0, this.canvas.width, this.canvas.height);
582
- }
583
- super.detachFromMap();
584
- }
585
- }
586
-
587
- start() {
588
- this.stop();
589
-
590
- // Before starting to update trajectories, we remove trajectories that have
591
- // a time_intervals in the past, it will
592
- // avoid phantom train that are at the end of their route because we never
593
- // received the deleted_vehicle event because we have changed the browser tab.
594
- this.purgeOutOfDateTrajectories();
595
-
596
- // @ts-ignore function without parameters must be define in subclasses
597
- this.renderTrajectories();
598
- this.startUpdateTime();
599
-
600
- this.api.open();
601
- this.api.subscribeTrajectory(
602
- this.mode,
603
- this.onTrajectoryMessage,
604
- undefined,
605
- this.isUpdateBboxOnMoveEnd,
606
- );
607
- this.api.subscribeDeletedVehicles(
608
- this.mode,
609
- this.onDeleteTrajectoryMessage,
610
- undefined,
611
- this.isUpdateBboxOnMoveEnd,
612
- );
613
-
614
- if (this.isUpdateBboxOnMoveEnd) {
615
- // Update the bbox on each move end
616
- // @ts-ignore function without parameters defined by subclasses
617
- this.setBbox();
618
- }
619
-
620
- if (this.onStart) {
621
- this.onStart(this);
622
- }
623
- }
624
-
625
- /**
626
- * Start the clock.
627
- * @private
628
- */
629
- startUpdateTime() {
630
- this.stopUpdateTime();
631
- this.updateTimeDelay = this.getRefreshTimeInMs() || 0;
632
- this.updateTimeInterval = window.setInterval(() => {
633
- // When live=true, we update the time with new Date();
634
- if (this.live) {
635
- this.time = new Date();
636
- } else if (this.time && this.updateTimeDelay && this.speed) {
637
- this.time = new Date(
638
- this.time.getTime() + this.updateTimeDelay * this.speed,
639
- );
640
- }
641
- }, this.updateTimeDelay);
642
- }
643
-
644
- stop() {
645
- this.api.unsubscribeTrajectory(this.onTrajectoryMessage);
646
- this.api.unsubscribeDeletedVehicles(this.onDeleteTrajectoryMessage);
647
- this.api.close();
648
- if (this.onStop) {
649
- this.onStop(this);
650
- }
651
- }
652
-
653
- /**
654
- * Stop the clock.
655
- * @private
656
- */
657
- stopUpdateTime() {
658
- if (this.updateTimeInterval) {
659
- clearInterval(this.updateTimeInterval);
660
- this.updateTimeInterval = undefined;
661
- }
662
- }
663
-
664
- /**
665
- * Launch renderTrajectories. it avoids duplicating code in renderTrajectories method.
666
- *
667
- * @param {object} viewState The view state of the map.
668
- * @param {number[2]} viewState.center Center coordinate of the map in mercator coordinate.
669
- * @param {number[4]} viewState.extent Extent of the map in mercator coordinates.
670
- * @param {number[2]} viewState.size Size ([width, height]) of the canvas to render.
671
- * @param {number} [viewState.rotation = 0] Rotation of the map to render.
672
- * @param {number} viewState.resolution Resolution of the map to render.
673
- * @param {boolean} noInterpolate If true trajectories are not interpolated but
674
- * drawn at the last known coordinate. Use this for performance optimization
675
- * during map navigation.
676
- * @private
677
- */
678
- renderTrajectoriesInternal(
679
- viewState: ViewState,
680
- noInterpolate: boolean = false,
681
- ) {
682
- if (!this.map || !this.trajectories) {
683
- return false;
684
- }
685
- const time = this.live ? Date.now() : this.time?.getTime();
686
-
687
- const trajectories = Object.values(this.trajectories);
688
-
689
- // console.time('sort');
690
- if (this.sort) {
691
- // @ts-ignore
692
- trajectories.sort(this.sort);
693
- }
694
- // console.timeEnd('sort');
695
-
696
- if (!this.canvas || !this.style) {
697
- return true;
698
- }
699
-
700
- // console.time('render');
701
- this.renderState = renderTrajectories(
702
- this.canvas,
703
- trajectories,
704
- this.style,
705
- {
706
- ...viewState,
707
- pixelRatio: this.pixelRatio || 1,
708
- time,
709
- },
710
- {
711
- filter: this.filter,
712
- noInterpolate:
713
- (viewState.zoom || 0) < this.minZoomInterpolation
714
- ? true
715
- : noInterpolate,
716
- hoverVehicleId: this.hoverVehicleId,
717
- selectedVehicleId: this.selectedVehicleId,
718
- ...this.styleOptions,
719
- },
720
- );
721
-
722
- // console.timeEnd('render');
723
- return true;
724
- }
725
-
726
- /**
727
- * Render the trajectories requesting an animation frame and cancelling the previous one.
728
- * This function must be overrided by children to provide the correct parameters.
729
- *
730
- * @param {object} viewState The view state of the map.
731
- * @param {number[2]} viewState.center Center coordinate of the map in mercator coordinate.
732
- * @param {number[4]} viewState.extent Extent of the map in mercator coordinates.
733
- * @param {number[2]} viewState.size Size ([width, height]) of the canvas to render.
734
- * @param {number} [viewState.rotation = 0] Rotation of the map to render.
735
- * @param {number} viewState.resolution Resolution of the map to render.
736
- * @param {boolean} noInterpolate If true trajectories are not interpolated but
737
- * drawn at the last known coordinate. Use this for performance optimization
738
- * during map navigation.
739
- * @private
740
- */
741
- renderTrajectories(
742
- viewState: ViewState | undefined,
743
- noInterpolate: boolean | undefined,
744
- ) {
745
- if (this.requestId) {
746
- cancelAnimationFrame(this.requestId);
747
- this.requestId = undefined;
748
- }
749
-
750
- if (!viewState) {
751
- return;
752
- }
753
-
754
- if (!noInterpolate && this.useRequestAnimationFrame) {
755
- this.requestId = requestAnimationFrame(() => {
756
- this.renderTrajectoriesInternal(viewState, noInterpolate);
757
- });
758
- } else if (!noInterpolate && this.useDebounce) {
759
- this.debounceRenderTrajectories(viewState, noInterpolate);
760
- } else if (!noInterpolate && this.useThrottle) {
761
- this.throttleRenderTrajectories(viewState, noInterpolate);
762
- } else {
763
- this.renderTrajectoriesInternal(viewState, noInterpolate);
764
- }
765
- }
766
-
767
- setBbox(extent: [number, number, number, number], zoom: number) {
768
- // Clean trajectories before sending the new bbox
769
- // Purge trajectories:
770
- // - which are outside the extent
771
- // - when it's bus and zoom level is too low for them
772
- if (this.trajectories && extent && zoom) {
773
- const keys = Object.keys(this.trajectories);
774
- for (let i = keys.length - 1; i >= 0; i -= 1) {
775
- this.purgeTrajectory(this.trajectories[keys[i]], extent, zoom);
776
- }
777
- }
778
-
779
- // The backend only supports non float value
780
- const zoomFloor = Math.floor(zoom);
781
-
782
- if (!extent || Number.isNaN(zoomFloor)) {
783
- return;
784
- }
785
-
786
- // The extent does not need to be precise under meter, so we round floor/ceil the values.
787
- const [minX, minY, maxX, maxY] = extent;
788
-
789
- const bbox: (number | string)[] = [
790
- Math.floor(minX),
791
- Math.floor(minY),
792
- Math.ceil(maxX),
793
- Math.ceil(maxY),
794
- zoomFloor,
795
- ];
796
-
797
- /* @private */
798
- const generalizationLevel = this.getGeneralizationLevelByZoom(zoomFloor);
799
- if (this.generalizationLevel) {
800
- bbox.push(`gen=${generalizationLevel}`);
801
- }
802
-
803
- /* @private */
804
- this.mots = this.getMotsByZoom(zoomFloor);
805
- if (this.mots) {
806
- bbox.push(`mots=${this.mots}`);
807
- }
808
-
809
- if (this.tenant) {
810
- bbox.push(`tenant=${this.tenant}`);
811
- }
812
-
813
- if (this.mode !== 'topographic') {
814
- bbox.push(`channel_prefix=${this.mode}`);
815
- }
816
-
817
- if (this.bboxParameters) {
818
- Object.entries(this.bboxParameters).forEach(([key, value]) => {
819
- bbox.push(`${key}=${value}`);
820
- });
821
- }
822
-
823
- // Extent and zoom level are mandatory.
824
- this.api.bbox = bbox;
825
- }
826
-
827
- /**
828
- * Get the duration before the next update depending on zoom level.
829
- *
830
- * @private
831
- * @param {number} zoom
832
- */
833
- getRefreshTimeInMs(zoom: number | undefined = 0): number {
834
- const roundedZoom = zoom !== undefined ? Math.round(zoom) : -1;
835
- const timeStep = this.getRenderTimeIntervalByZoom(roundedZoom) || 25;
836
- const nextTick = Math.max(25, timeStep / (this.speed || 1));
837
- const nextThrottleTick = Math.min(nextTick, 500);
838
- // TODO: see if this should go elsewhere.
839
- if (this.useThrottle) {
840
- this.throttleRenderTrajectories = throttle(
841
- this.renderTrajectoriesInternal,
842
- nextThrottleTick,
843
- { leading: true, trailing: true },
844
- );
845
- } else if (this.useDebounce) {
846
- this.debounceRenderTrajectories = debounce(
847
- this.renderTrajectoriesInternal,
848
- nextThrottleTick,
849
- { leading: true, trailing: true, maxWait: 5000 },
850
- );
851
- }
852
- if (this.api?.buffer) {
853
- const [, size] = this.api.buffer;
854
- this.api.buffer = [nextThrottleTick, size];
855
- }
856
- return nextTick;
857
- }
858
-
859
- /**
860
- * Get vehicle.
861
- * @param {function} filterFc A function use to filter results.
862
- * @return {Array<Object>} Array of vehicle.
863
- */
864
- getVehicle(filterFc: FilterFunction) {
865
- return (
866
- (this.trajectories &&
867
- // @ts-ignore
868
- Object.values(this.trajectories).filter(filterFc)) ||
869
- []
870
- );
871
- }
872
-
873
- /**
874
- * Request feature information for a given coordinate.
875
- *
876
- * @param {ol/coordinate~Coordinate} coordinate Coordinate.
877
- * @param {Object} options Options See child classes to see which options are supported.
878
- * @param {number} [options.resolution=1] The resolution of the map.
879
- * @param {number} [options.nb=Infinity] The max number of vehicles to return.
880
- * @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
881
- */
882
- getFeatureInfoAtCoordinate(
883
- coordinate: Coordinate,
884
- options: LayerGetFeatureInfoOptions,
885
- ) {
886
- const { resolution, nb } = options;
887
- const ext = buffer(
888
- [...coordinate, ...coordinate],
889
- this.hitTolerance * resolution,
890
- );
891
- let trajectories = Object.values(this.trajectories || {});
892
-
893
- if (this.sort) {
894
- // @ts-ignore
895
- trajectories = trajectories.sort(this.sort);
896
- }
897
-
898
- const vehicles = [];
899
- for (let i = 0; i < trajectories.length; i += 1) {
900
- if (
901
- trajectories[i].properties.coordinate &&
902
- containsCoordinate(ext, trajectories[i].properties.coordinate)
903
- ) {
904
- vehicles.push(trajectories[i]);
905
- }
906
- if (vehicles.length === nb) {
907
- break;
908
- }
909
- }
910
-
911
- return Promise.resolve({
912
- layer: this,
913
- features: vehicles.map((vehicle) => this.format.readFeature(vehicle)),
914
- coordinate,
915
- } as LayerGetFeatureInfoResponse);
916
- }
917
-
918
- /**
919
- * Request the stopSequence and the fullTrajectory informations for a vehicle.
920
- *
921
- * @param {string} id The vehicle identifier (the train_id property).
922
- * @return {Promise<{stopSequence: StopSequence, fullTrajectory: FullTrajectory>} A promise that will be resolved with the trajectory informations.
923
- */
924
- getTrajectoryInfos(id: RealtimeTrainId) {
925
- // When a vehicle is selected, we request the complete stop sequence and the complete full trajectory.
926
- // Then we combine them in one response and send them to inherited layers.
927
- const promises = [
928
- this.api.getStopSequence(id),
929
- this.api.getFullTrajectory(
930
- id,
931
- this.mode,
932
- this.getGeneralizationLevelByZoom(
933
- Math.floor(this.map?.getView()?.getZoom() || 0),
934
- ),
935
- ),
936
- ];
937
-
938
- return Promise.all(promises).then(([stopSequence, fullTrajectory]) => {
939
- const response = {
940
- stopSequence,
941
- fullTrajectory,
942
- };
943
- return response;
944
- });
945
- }
946
-
947
- /**
948
- * Remove all trajectories that are in the past.
949
- */
950
- purgeOutOfDateTrajectories() {
951
- Object.entries(this.trajectories || {}).forEach(([key, trajectory]) => {
952
- const timeIntervals = trajectory?.properties?.time_intervals;
953
- if (this.time && timeIntervals.length) {
954
- const lastTimeInterval = timeIntervals[timeIntervals.length - 1][0];
955
- if (lastTimeInterval < this.time) {
956
- this.removeTrajectory(key);
957
- }
958
- }
959
- });
960
- }
961
-
962
- /**
963
- * Determine if the trajectory is useless and should be removed from the list or not.
964
- * By default, this function exclude vehicles:
965
- * - that have their trajectory outside the current extent and
966
- * - that aren't in the MOT list.
967
- *
968
- * @param {RealtimeTrajectory} trajectory
969
- * @param {Array<number>} extent
970
- * @param {number} zoom
971
- * @return {boolean} if the trajectory must be displayed or not.
972
- * @private
973
- */
974
- purgeTrajectory(
975
- trajectory: RealtimeTrajectory,
976
- extent: [number, number, number, number],
977
- zoom: number,
978
- ) {
979
- const { type, bounds } = trajectory.properties;
980
-
981
- if (
982
- (this.isUpdateBboxOnMoveEnd && !intersects(extent, bounds)) ||
983
- (this.mots && !this.mots.includes(type))
984
- ) {
985
- this.removeTrajectory(trajectory);
986
- return true;
987
- }
988
- return false;
989
- }
990
-
991
- /**
992
- * Add a trajectory.
993
- * @param {RealtimeTrajectory} trajectory The trajectory to add.
994
- * @private
995
- */
996
- addTrajectory(trajectory: RealtimeTrajectory) {
997
- if (!this.trajectories) {
998
- this.trajectories = {};
999
- }
1000
- this.trajectories[trajectory.properties.train_id] = trajectory;
1001
- // @ts-ignore the parameter are set by subclasses
1002
- this.renderTrajectories();
1003
- }
1004
-
1005
- removeTrajectory(trajectoryOrId: RealtimeTrajectory | RealtimeTrainId) {
1006
- let id: string;
1007
- if (typeof trajectoryOrId !== 'string') {
1008
- id = trajectoryOrId?.properties?.train_id;
1009
- } else {
1010
- id = trajectoryOrId;
1011
- }
1012
- if (this.trajectories) {
1013
- delete this.trajectories[id];
1014
- }
1015
- }
1016
-
1017
- /**
1018
- * On zoomend we adjust the time interval of the update of vehicles positions.
1019
- *
1020
- * @param evt Event that triggered the function.
1021
- * @private
1022
- */
1023
- onZoomEnd() {
1024
- this.startUpdateTime();
1025
- }
1026
-
1027
- onDocumentVisibilityChange() {
1028
- if (!this.visible) {
1029
- return;
1030
- }
1031
- if (document.hidden) {
1032
- this.stop();
1033
-
1034
- // Since we don't receive deleted_vehicles event when docuement
1035
- // is hidden. We have to clean all the trajectories for a fresh
1036
- // start when the document is visible again.
1037
- this.trajectories = {};
1038
- } else {
1039
- this.start();
1040
- }
1041
- }
1042
-
1043
- /**
1044
- * Callback on websocket's trajectory channel events.
1045
- * It adds a trajectory to the list.
1046
- *
1047
- * @private
1048
- */
1049
- onTrajectoryMessage(
1050
- data: WebSocketAPIMessageEventData<RealtimeTrajectory>,
1051
- ) {
1052
- if (!data.content) {
1053
- return;
1054
- }
1055
- const trajectory = data.content;
1056
-
1057
- const {
1058
- geometry,
1059
- properties: {
1060
- train_id: id,
1061
- time_since_update: timeSinceUpdate,
1062
- raw_coordinates: rawCoordinates,
1063
- },
1064
- } = trajectory;
1065
-
1066
- // ignore old events [SBAHNM-97]
1067
- if (timeSinceUpdate < 0) {
1068
- return;
1069
- }
1070
-
1071
- // console.time(`onTrajectoryMessage${data.content.properties.train_id}`);
1072
- // @ts-ignore default value for extentand zoom are provided by subclasses
1073
- if (this.purgeTrajectory(trajectory)) {
1074
- return;
1075
- }
1076
-
1077
- if (
1078
- this.debug &&
1079
- this.mode === RealtimeModes.TOPOGRAPHIC &&
1080
- rawCoordinates
1081
- ) {
1082
- trajectory.properties.olGeometry = this.format.readGeometry({
1083
- type: 'Point',
1084
- coordinates: fromLonLat(
1085
- rawCoordinates,
1086
- this.map.getView().getProjection(),
1087
- ),
1088
- });
1089
- } else {
1090
- trajectory.properties.olGeometry = this.format.readGeometry(geometry);
1091
- }
1092
-
1093
- // TODO Make sure the timeOffset is useful. May be we can remove it.
1094
- trajectory.properties.timeOffset = Date.now() - data.timestamp;
1095
- this.addTrajectory(trajectory);
1096
- }
1097
-
1098
- /**
1099
- * Callback on websocket's deleted_vehicles channel events.
1100
- * It removes the trajectory from the list.
1101
- *
1102
- * @private
1103
- * @override
1104
- */
1105
- onDeleteTrajectoryMessage(
1106
- data: WebSocketAPIMessageEventData<RealtimeTrainId>,
1107
- ) {
1108
- if (!data.content) {
1109
- return;
1110
- }
1111
- this.removeTrajectory(data.content);
1112
- }
1113
-
1114
- /**
1115
- * Callback when user moves the mouse/pointer over the map.
1116
- * It sets the layer's hoverVehicleId property with the current hovered vehicle's id.
1117
- *
1118
- * @private
1119
- * @override
1120
- */
1121
- onFeatureHover(
1122
- features: Feature[],
1123
- layer: AnyRealtimeLayer,
1124
- coordinate: Coordinate,
1125
- ) {
1126
- const [feature] = features;
1127
- let id = null;
1128
- if (feature) {
1129
- id = feature.get('train_id');
1130
- }
1131
- if (this.hoverVehicleId !== id) {
1132
- /** @private */
1133
- this.hoverVehicleId = id;
1134
- // @ts-ignore
1135
- this.renderTrajectories(true);
1136
- }
1137
- }
1138
-
1139
- /**
1140
- * Callback when user clicks on the map.
1141
- * It sets the layer's selectedVehicleId property with the current selected vehicle's id.
1142
- *
1143
- * @private
1144
- * @override
1145
- */
1146
- onFeatureClick(
1147
- features: Feature[],
1148
- layer: AnyRealtimeLayer,
1149
- coordinate: Coordinate,
1150
- ) {
1151
- const [feature] = features;
1152
- let id = null;
1153
- if (feature) {
1154
- id = feature.get('train_id');
1155
- }
1156
- if (this.selectedVehicleId !== id) {
1157
- /** @private */
1158
- this.selectedVehicleId = id;
1159
- this.selectedVehicle = feature;
1160
-
1161
- // @ts-ignore parameters are provided by subclasses
1162
- this.renderTrajectories(true);
1163
- }
1164
- }
1165
- };
1166
- }
1167
-
1168
- export default RealtimeLayerMixin;