mobility-toolbox-js 2.3.9-beta.1 → 2.3.10

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/.esdoc.js +18 -0
  2. package/.eslintignore +1 -0
  3. package/.eslintrc.js +25 -0
  4. package/.fixpackrc +20 -0
  5. package/.github/workflows/build.yml +16 -0
  6. package/.github/workflows/conventional-pr-title.yml +16 -0
  7. package/.github/workflows/cypress.yml +101 -0
  8. package/.github/workflows/test.yml +17 -0
  9. package/.husky/commit-msg +4 -0
  10. package/.husky/post-checkout +4 -0
  11. package/.husky/post-merge +4 -0
  12. package/.husky/post-rebase +4 -0
  13. package/.husky/pre-commit +4 -0
  14. package/.lintstagedrc.js +10 -0
  15. package/.nvmrc +1 -0
  16. package/.prettierrc.js +5 -0
  17. package/.stylelintrc.js +4 -0
  18. package/CHANGELOG.md +132 -0
  19. package/LICENSE +21 -0
  20. package/MIGRATION-V2.md +248 -0
  21. package/README.md +42 -0
  22. package/__mocks__/mapbox-gl.js +81 -0
  23. package/__mocks__/maplibre-gl.js +81 -0
  24. package/babel.config.js +9 -0
  25. package/commitlint.config.js +1 -0
  26. package/cypress/e2e/examples/api.cy.js +7 -0
  27. package/cypress/e2e/examples/examples.cy.js +7 -0
  28. package/cypress/e2e/examples/navigation.cy.js +29 -0
  29. package/cypress/fixtures/example.json +5 -0
  30. package/cypress/plugins/index.js +21 -0
  31. package/cypress/support/commands.js +25 -0
  32. package/cypress/support/e2e.js +20 -0
  33. package/cypress.config.ts +15 -0
  34. package/data/fetchRoute.json +292 -0
  35. package/data/fetchTrajectories.json +18 -0
  36. package/data/fetchTrajectoryById.json +3 -0
  37. package/data/fetchTrajectoryStations.json +18 -0
  38. package/data/stopsSearch.json +15 -0
  39. package/dependabot.yml +15 -0
  40. package/doc/.eslintrc.json +1 -0
  41. package/doc/README.md +34 -0
  42. package/doc/next.config.js +16 -0
  43. package/doc/package.json +41 -0
  44. package/doc/pages/404.js +5 -0
  45. package/doc/pages/_app.js +61 -0
  46. package/doc/pages/_document.js +64 -0
  47. package/doc/pages/doc/[...slug].js +23 -0
  48. package/doc/pages/doc.js +23 -0
  49. package/doc/pages/example/[example].js +52 -0
  50. package/doc/pages/examples.js +34 -0
  51. package/doc/pages/index.js +25 -0
  52. package/doc/public/README.md +15 -0
  53. package/doc/public/favicon.ico +0 -0
  54. package/doc/public/static/assets/Lato-Black.ttf +0 -0
  55. package/doc/public/static/assets/Lato-BlackItalic.ttf +0 -0
  56. package/doc/public/static/assets/Lato-Bold.ttf +0 -0
  57. package/doc/public/static/assets/Lato-BoldItalic.ttf +0 -0
  58. package/doc/public/static/assets/Lato-Italic.ttf +0 -0
  59. package/doc/public/static/assets/Lato-Light.ttf +0 -0
  60. package/doc/public/static/assets/Lato-LightItalic.ttf +0 -0
  61. package/doc/public/static/assets/Lato-Regular.ttf +0 -0
  62. package/doc/public/static/assets/Lato-Thin.ttf +0 -0
  63. package/doc/public/static/assets/Lato-ThinItalic.ttf +0 -0
  64. package/doc/public/static/assets/OFL.txt +93 -0
  65. package/doc/public/static/examples/assets/tralis-live-map/index.js +11 -0
  66. package/doc/public/static/examples/assets/tralis-live-map/s1kreis.svg +105 -0
  67. package/doc/public/static/examples/assets/tralis-live-map/s20kreis.svg +101 -0
  68. package/doc/public/static/examples/assets/tralis-live-map/s2kreis.svg +95 -0
  69. package/doc/public/static/examples/assets/tralis-live-map/s3kreis.svg +95 -0
  70. package/doc/public/static/examples/assets/tralis-live-map/s4kreis.svg +95 -0
  71. package/doc/public/static/examples/assets/tralis-live-map/s6kreis.svg +95 -0
  72. package/doc/public/static/examples/assets/tralis-live-map/s7kreis.svg +95 -0
  73. package/doc/public/static/examples/assets/tralis-live-map/s8kreis.svg +93 -0
  74. package/doc/public/static/examples/assets/tralis-live-map/unknown.svg +107 -0
  75. package/doc/public/static/examples/layers.html +11 -0
  76. package/doc/public/static/examples/layers.js +97 -0
  77. package/doc/public/static/examples/mb-copyright.html +26 -0
  78. package/doc/public/static/examples/mb-copyright.js +37 -0
  79. package/doc/public/static/examples/mb-tracker.html +1 -0
  80. package/doc/public/static/examples/mb-tracker.js +40 -0
  81. package/doc/public/static/examples/mb-tracker.md +1 -0
  82. package/doc/public/static/examples/mb-tralis.html +1 -0
  83. package/doc/public/static/examples/mb-tralis.js +34 -0
  84. package/doc/public/static/examples/ol-copyright.html +26 -0
  85. package/doc/public/static/examples/ol-copyright.js +43 -0
  86. package/doc/public/static/examples/ol-mapbox-layer.html +1 -0
  87. package/doc/public/static/examples/ol-mapbox-layer.js +28 -0
  88. package/doc/public/static/examples/ol-mapbox-style-layer.html +12 -0
  89. package/doc/public/static/examples/ol-mapbox-style-layer.js +48 -0
  90. package/doc/public/static/examples/ol-query.html +32 -0
  91. package/doc/public/static/examples/ol-query.js +83 -0
  92. package/doc/public/static/examples/ol-routing.html +26 -0
  93. package/doc/public/static/examples/ol-routing.js +65 -0
  94. package/doc/public/static/examples/ol-routing.md +1 -0
  95. package/doc/public/static/examples/ol-stop-finder.html +15 -0
  96. package/doc/public/static/examples/ol-stop-finder.js +35 -0
  97. package/doc/public/static/examples/ol-stop-finder.md +1 -0
  98. package/doc/public/static/examples/ol-tracker.html +1 -0
  99. package/doc/public/static/examples/ol-tracker.js +41 -0
  100. package/doc/public/static/examples/ol-tracker.md +1 -0
  101. package/doc/public/static/examples/ol-tralis.html +5 -0
  102. package/doc/public/static/examples/ol-tralis.js +62 -0
  103. package/doc/public/static/examples/tralis-live-map.html +1 -0
  104. package/doc/public/static/examples/tralis-live-map.js +67 -0
  105. package/doc/public/static/examples/tralis-live-map.md +3 -0
  106. package/doc/public/static/img/live_tracker_mb.jpg +0 -0
  107. package/doc/public/static/img/live_tracker_munich.jpg +0 -0
  108. package/doc/public/static/img/live_tracker_ol.jpg +0 -0
  109. package/doc/public/static/img/mapbox.jpg +0 -0
  110. package/doc/public/static/img/mapbox_style.jpg +0 -0
  111. package/doc/public/static/img/ol-copyright.png +0 -0
  112. package/doc/public/static/img/query_objects.jpg +0 -0
  113. package/doc/public/static/img/routing.jpg +0 -0
  114. package/doc/public/static/img/simple_map.jpg +0 -0
  115. package/doc/public/static/img/stops.jpg +0 -0
  116. package/doc/public/vercel.svg +4 -0
  117. package/doc/src/components/CodeSandboxButton.js +102 -0
  118. package/doc/src/components/Documentation.js +42 -0
  119. package/doc/src/components/Esdoc/Anchor.js +57 -0
  120. package/doc/src/components/Esdoc/ClassDoc.js +272 -0
  121. package/doc/src/components/Esdoc/DeprecatedHTML.js +16 -0
  122. package/doc/src/components/Esdoc/DetailDocs.js +279 -0
  123. package/doc/src/components/Esdoc/DetailHTML.js +33 -0
  124. package/doc/src/components/Esdoc/DirectSubclassHTML.js +30 -0
  125. package/doc/src/components/Esdoc/DocBuilderUtils.js +697 -0
  126. package/doc/src/components/Esdoc/DocLinkHTML.js +63 -0
  127. package/doc/src/components/Esdoc/DocsLinkHTML.js +38 -0
  128. package/doc/src/components/Esdoc/Esdoc.js +63 -0
  129. package/doc/src/components/Esdoc/EsdocContent.js +56 -0
  130. package/doc/src/components/Esdoc/EsdocNavigation.js +13 -0
  131. package/doc/src/components/Esdoc/EsdocSearch.js +78 -0
  132. package/doc/src/components/Esdoc/ExperimentalHTML.js +17 -0
  133. package/doc/src/components/Esdoc/ExtendsChainHTML.js +32 -0
  134. package/doc/src/components/Esdoc/FileDocLinkHTML.js +62 -0
  135. package/doc/src/components/Esdoc/IdentifiersDoc.js +113 -0
  136. package/doc/src/components/Esdoc/IndirectSubclassHTML.js +30 -0
  137. package/doc/src/components/Esdoc/InheritedSummaryDoc.js +70 -0
  138. package/doc/src/components/Esdoc/InheritedSummaryHTML.js +38 -0
  139. package/doc/src/components/Esdoc/MixinClassesHTML.js +29 -0
  140. package/doc/src/components/Esdoc/NavDoc.js +112 -0
  141. package/doc/src/components/Esdoc/OverrideMethod.js +44 -0
  142. package/doc/src/components/Esdoc/OverrideMethodDescription.js +35 -0
  143. package/doc/src/components/Esdoc/Properties.js +89 -0
  144. package/doc/src/components/Esdoc/README.md +45 -0
  145. package/doc/src/components/Esdoc/SignatureHTML.js +123 -0
  146. package/doc/src/components/Esdoc/SingleDoc.js +31 -0
  147. package/doc/src/components/Esdoc/SummaryDoc.js +160 -0
  148. package/doc/src/components/Esdoc/SummaryHTML.js +96 -0
  149. package/doc/src/components/Esdoc/TypeDocLinkHTML.js +251 -0
  150. package/doc/src/components/Esdoc/index.js +7 -0
  151. package/doc/src/components/Esdoc/taffydb.js +2070 -0
  152. package/doc/src/components/Example.js +200 -0
  153. package/doc/src/components/ExampleCard.js +126 -0
  154. package/doc/src/components/Examples.js +78 -0
  155. package/doc/src/components/Home.js +121 -0
  156. package/doc/src/components/TrackerExample.js +39 -0
  157. package/doc/src/examples.js +117 -0
  158. package/doc/styles/App.scss +53 -0
  159. package/doc/styles/identifiers.css +38 -0
  160. package/doc/styles/search.css +76 -0
  161. package/doc/styles/style.css +603 -0
  162. package/esdoc/README.md +27 -0
  163. package/esdoc/plugins/MyPlugin.js +69 -0
  164. package/esdoc/plugins/dynamic-property-plugin/Plugin.js +50 -0
  165. package/esdoc/plugins/externals-plugin/Plugin.js +45 -0
  166. package/esdoc/plugins/externals-plugin/externals.js +93 -0
  167. package/esdoc/plugins/optional-chaining-plugin/Plugin.js +8 -0
  168. package/global-setup.js +3 -0
  169. package/jest.config.js +24 -0
  170. package/package.json +19 -19
  171. package/pull_request_template.md +17 -0
  172. package/scripts/read-pkg-json.js +22 -0
  173. package/src/api/RealtimeAPI.test.js +144 -0
  174. package/src/api/RealtimeAPI.ts +712 -0
  175. package/src/api/RoutingAPI.test.js +41 -0
  176. package/src/api/RoutingAPI.ts +47 -0
  177. package/src/api/StopsAPI.test.js +34 -0
  178. package/src/api/StopsAPI.ts +45 -0
  179. package/{api → src/api}/typedefs.js +11 -1
  180. package/src/common/api/HttpAPI.test.js +68 -0
  181. package/src/common/api/HttpAPI.ts +77 -0
  182. package/src/common/api/WebSocketAPI.test.js +421 -0
  183. package/src/common/api/WebSocketAPI.ts +515 -0
  184. package/src/common/controls/ControlCommon.test.js +106 -0
  185. package/src/common/controls/ControlCommon.ts +194 -0
  186. package/src/common/controls/CopyrightControlCommon.ts +41 -0
  187. package/src/common/controls/StopFinderControlCommon.ts +192 -0
  188. package/src/common/layers/LayerCommon.test.js +158 -0
  189. package/src/common/layers/LayerCommon.ts +321 -0
  190. package/src/common/mixins/RealtimeLayerMixin.ts +1168 -0
  191. package/src/common/mixins/UserInteractionsLayerMixin.test.js +227 -0
  192. package/src/common/mixins/UserInteractionsLayerMixin.ts +352 -0
  193. package/src/common/styles/realtimeDefaultStyle.ts +436 -0
  194. package/src/common/styles/realtimeDelayStyle.ts +27 -0
  195. package/src/common/styles/realtimeHeadingStyle.ts +138 -0
  196. package/src/common/styles/realtimeSimpleStyle.ts +25 -0
  197. package/{common → src/common}/typedefs.js +1 -1
  198. package/src/common/utils/compareDepartures.ts +46 -0
  199. package/src/common/utils/createCanvas.ts +33 -0
  200. package/src/common/utils/createRealtimeFilters.test.js +100 -0
  201. package/src/common/utils/createRealtimeFilters.ts +96 -0
  202. package/src/common/utils/debounceDeparturesMessages.ts +52 -0
  203. package/src/common/utils/debounceWebsocketMessages.ts +47 -0
  204. package/src/common/utils/getLayersAsFlatArray.ts +17 -0
  205. package/src/common/utils/getMapboxMapCopyrights.test.js +47 -0
  206. package/src/common/utils/getMapboxMapCopyrights.ts +52 -0
  207. package/src/common/utils/getMapboxRender.ts +104 -0
  208. package/src/common/utils/getMaplibreRender.ts +54 -0
  209. package/{common/utils/getRealtimeModeSuffix.d.ts → src/common/utils/getRealtimeModeSuffix.ts} +4 -2
  210. package/src/common/utils/getUrlWithParams.ts +21 -0
  211. package/src/common/utils/getVehiclePosition.ts +92 -0
  212. package/{common → src/common}/utils/index.js +1 -2
  213. package/src/common/utils/realtimeConfig.test.js +57 -0
  214. package/src/common/utils/realtimeConfig.ts +228 -0
  215. package/src/common/utils/removeDuplicate.test.js +22 -0
  216. package/src/common/utils/removeDuplicate.ts +22 -0
  217. package/src/common/utils/renderTrajectories.ts +194 -0
  218. package/src/common/utils/sortAndFilterDepartures.ts +78 -0
  219. package/src/common/utils/sortByDelay.ts +29 -0
  220. package/src/common/utils/timeUtils.test.js +16 -0
  221. package/src/common/utils/timeUtils.ts +45 -0
  222. package/{iife.js → src/iife.js} +3 -1
  223. package/src/index.js +10 -0
  224. package/{mapbox/controls/CopyrightControl.js → src/mapbox/controls/CopyrightControl.ts} +26 -21
  225. package/src/mapbox/layers/Layer.test.js +217 -0
  226. package/src/mapbox/layers/Layer.ts +144 -0
  227. package/src/mapbox/layers/RealtimeLayer.test.js +13 -0
  228. package/src/mapbox/layers/RealtimeLayer.ts +350 -0
  229. package/src/mapbox/utils/getMercatorResolution.ts +21 -0
  230. package/src/mapbox/utils/getSourceCoordinates.ts +34 -0
  231. package/src/ol/README.md +0 -0
  232. package/src/ol/controls/CopyrightControl.test.js +211 -0
  233. package/src/ol/controls/CopyrightControl.ts +82 -0
  234. package/src/ol/controls/RoutingControl.test.js +205 -0
  235. package/src/ol/controls/RoutingControl.ts +869 -0
  236. package/src/ol/controls/StopFinderControl.test.js +59 -0
  237. package/{ol/controls/StopFinderControl.js → src/ol/controls/StopFinderControl.ts} +10 -7
  238. package/src/ol/controls/snapshots/RoutingControlRouteGen10.json +58 -0
  239. package/src/ol/controls/snapshots/RoutingControlRouteGen100.json +292 -0
  240. package/src/ol/controls/snapshots/RoutingControlRouteGen30.json +69 -0
  241. package/src/ol/controls/snapshots/RoutingControlRouteGen5.json +58 -0
  242. package/src/ol/controls/snapshots/RoutingControlRouteOSM.json +759 -0
  243. package/src/ol/controls/snapshots/RoutingControlStation1.json +60 -0
  244. package/src/ol/controls/snapshots/RoutingControlStation2.json +49 -0
  245. package/src/ol/layers/Layer.test.js +212 -0
  246. package/src/ol/layers/Layer.ts +252 -0
  247. package/src/ol/layers/MapGlLayer.ts +294 -0
  248. package/src/ol/layers/MapboxLayer.test.js +190 -0
  249. package/src/ol/layers/MapboxLayer.ts +136 -0
  250. package/src/ol/layers/MapboxStyleLayer.test.js +258 -0
  251. package/src/ol/layers/MapboxStyleLayer.ts +466 -0
  252. package/{ol/layers/MaplibreLayer.d.ts → src/ol/layers/MaplibreLayer.ts} +21 -10
  253. package/src/ol/layers/RealtimeLayer.test.js +84 -0
  254. package/src/ol/layers/RealtimeLayer.ts +465 -0
  255. package/src/ol/layers/RoutingLayer.test.js +48 -0
  256. package/src/ol/layers/RoutingLayer.ts +113 -0
  257. package/src/ol/layers/VectorLayer.test.js +87 -0
  258. package/src/ol/layers/VectorLayer.ts +48 -0
  259. package/src/ol/layers/WMSLayer.test.js +65 -0
  260. package/src/ol/layers/WMSLayer.ts +114 -0
  261. package/src/ol/styles/fullTrajectoryDelayStyle.ts +37 -0
  262. package/src/ol/styles/fullTrajectoryStyle.ts +56 -0
  263. package/{setupTests.js → src/setupTests.js} +12 -7
  264. package/tsconfig.json +23 -0
  265. package/api/RealtimeAPI.d.ts +0 -290
  266. package/api/RealtimeAPI.d.ts.map +0 -1
  267. package/api/RealtimeAPI.js +0 -483
  268. package/api/RoutingAPI.d.ts +0 -37
  269. package/api/RoutingAPI.d.ts.map +0 -1
  270. package/api/RoutingAPI.js +0 -35
  271. package/api/StopsAPI.d.ts +0 -38
  272. package/api/StopsAPI.d.ts.map +0 -1
  273. package/api/StopsAPI.js +0 -36
  274. package/api/index.d.ts +0 -4
  275. package/api/index.d.ts.map +0 -1
  276. package/api/typedefs.d.ts +0 -179
  277. package/api/typedefs.d.ts.map +0 -1
  278. package/common/api/HttpAPI.d.ts +0 -31
  279. package/common/api/HttpAPI.d.ts.map +0 -1
  280. package/common/api/HttpAPI.js +0 -57
  281. package/common/api/WebSocketAPI.d.ts +0 -153
  282. package/common/api/WebSocketAPI.d.ts.map +0 -1
  283. package/common/api/WebSocketAPI.js +0 -341
  284. package/common/controls/ControlCommon.d.ts +0 -76
  285. package/common/controls/ControlCommon.d.ts.map +0 -1
  286. package/common/controls/ControlCommon.js +0 -150
  287. package/common/controls/CopyrightControlCommon.d.ts +0 -13
  288. package/common/controls/CopyrightControlCommon.d.ts.map +0 -1
  289. package/common/controls/CopyrightControlCommon.js +0 -34
  290. package/common/controls/StopFinderControlCommon.d.ts +0 -55
  291. package/common/controls/StopFinderControlCommon.d.ts.map +0 -1
  292. package/common/controls/StopFinderControlCommon.js +0 -144
  293. package/common/index.d.ts +0 -3
  294. package/common/index.d.ts.map +0 -1
  295. package/common/layers/LayerCommon.d.ts +0 -94
  296. package/common/layers/LayerCommon.d.ts.map +0 -1
  297. package/common/layers/LayerCommon.js +0 -244
  298. package/common/mixins/RealtimeLayerMixin.d.ts +0 -288
  299. package/common/mixins/RealtimeLayerMixin.d.ts.map +0 -1
  300. package/common/mixins/RealtimeLayerMixin.js +0 -778
  301. package/common/mixins/UserInteractionsLayerMixin.d.ts +0 -60
  302. package/common/mixins/UserInteractionsLayerMixin.d.ts.map +0 -1
  303. package/common/mixins/UserInteractionsLayerMixin.js +0 -241
  304. package/common/styles/index.d.ts +0 -5
  305. package/common/styles/index.d.ts.map +0 -1
  306. package/common/styles/realtimeDefaultStyle.d.ts +0 -36
  307. package/common/styles/realtimeDefaultStyle.d.ts.map +0 -1
  308. package/common/styles/realtimeDefaultStyle.js +0 -276
  309. package/common/styles/realtimeDelayStyle.d.ts +0 -12
  310. package/common/styles/realtimeDelayStyle.d.ts.map +0 -1
  311. package/common/styles/realtimeDelayStyle.js +0 -13
  312. package/common/styles/realtimeHeadingStyle.d.ts +0 -12
  313. package/common/styles/realtimeHeadingStyle.d.ts.map +0 -1
  314. package/common/styles/realtimeHeadingStyle.js +0 -87
  315. package/common/styles/realtimeSimpleStyle.d.ts +0 -4
  316. package/common/styles/realtimeSimpleStyle.d.ts.map +0 -1
  317. package/common/styles/realtimeSimpleStyle.js +0 -23
  318. package/common/typedefs.d.ts +0 -183
  319. package/common/typedefs.d.ts.map +0 -1
  320. package/common/utils/compareDepartures.d.ts +0 -11
  321. package/common/utils/compareDepartures.d.ts.map +0 -1
  322. package/common/utils/compareDepartures.js +0 -35
  323. package/common/utils/createCanvas.d.ts +0 -11
  324. package/common/utils/createCanvas.d.ts.map +0 -1
  325. package/common/utils/createCanvas.js +0 -28
  326. package/common/utils/createRealtimeFilters.d.ts +0 -13
  327. package/common/utils/createRealtimeFilters.d.ts.map +0 -1
  328. package/common/utils/createRealtimeFilters.js +0 -74
  329. package/common/utils/debounceDeparturesMessages.d.ts +0 -13
  330. package/common/utils/debounceDeparturesMessages.d.ts.map +0 -1
  331. package/common/utils/debounceDeparturesMessages.js +0 -28
  332. package/common/utils/debounceWebsocketMessages.d.ts +0 -12
  333. package/common/utils/debounceWebsocketMessages.d.ts.map +0 -1
  334. package/common/utils/debounceWebsocketMessages.js +0 -30
  335. package/common/utils/getLayersAsFlatArray.d.ts +0 -4
  336. package/common/utils/getLayersAsFlatArray.d.ts.map +0 -1
  337. package/common/utils/getLayersAsFlatArray.js +0 -16
  338. package/common/utils/getMapboxMapCopyrights.d.ts +0 -18
  339. package/common/utils/getMapboxMapCopyrights.d.ts.map +0 -1
  340. package/common/utils/getMapboxMapCopyrights.js +0 -30
  341. package/common/utils/getMapboxRender.d.ts +0 -8
  342. package/common/utils/getMapboxRender.d.ts.map +0 -1
  343. package/common/utils/getMapboxRender.js +0 -88
  344. package/common/utils/getMaplibreRender.d.ts +0 -9
  345. package/common/utils/getMaplibreRender.d.ts.map +0 -1
  346. package/common/utils/getMaplibreRender.js +0 -40
  347. package/common/utils/getRealtimeModeSuffix.d.ts.map +0 -1
  348. package/common/utils/getRealtimeModeSuffix.js +0 -7
  349. package/common/utils/getUrlWithParams.d.ts +0 -9
  350. package/common/utils/getUrlWithParams.d.ts.map +0 -1
  351. package/common/utils/getUrlWithParams.js +0 -18
  352. package/common/utils/getVehiclePosition.d.ts +0 -16
  353. package/common/utils/getVehiclePosition.d.ts.map +0 -1
  354. package/common/utils/getVehiclePosition.js +0 -72
  355. package/common/utils/index.d.ts +0 -18
  356. package/common/utils/index.d.ts.map +0 -1
  357. package/common/utils/realtimeConfig.d.ts +0 -53
  358. package/common/utils/realtimeConfig.d.ts.map +0 -1
  359. package/common/utils/realtimeConfig.js +0 -202
  360. package/common/utils/removeDuplicate.d.ts +0 -10
  361. package/common/utils/removeDuplicate.d.ts.map +0 -1
  362. package/common/utils/removeDuplicate.js +0 -15
  363. package/common/utils/renderTrajectories.d.ts +0 -17
  364. package/common/utils/renderTrajectories.d.ts.map +0 -1
  365. package/common/utils/renderTrajectories.js +0 -110
  366. package/common/utils/sortAndFilterDepartures.d.ts +0 -16
  367. package/common/utils/sortAndFilterDepartures.d.ts.map +0 -1
  368. package/common/utils/sortAndFilterDepartures.js +0 -58
  369. package/common/utils/sortByDelay.d.ts +0 -4
  370. package/common/utils/sortByDelay.d.ts.map +0 -1
  371. package/common/utils/sortByDelay.js +0 -21
  372. package/common/utils/timeUtils.d.ts +0 -24
  373. package/common/utils/timeUtils.d.ts.map +0 -1
  374. package/common/utils/timeUtils.js +0 -39
  375. package/iife.d.ts +0 -3
  376. package/iife.d.ts.map +0 -1
  377. package/index.d.ts +0 -10
  378. package/index.d.ts.map +0 -1
  379. package/index.js +0 -10
  380. package/mapbox/controls/CopyrightControl.d.ts +0 -29
  381. package/mapbox/controls/CopyrightControl.d.ts.map +0 -1
  382. package/mapbox/controls/index.d.ts +0 -2
  383. package/mapbox/controls/index.d.ts.map +0 -1
  384. package/mapbox/index.d.ts +0 -6
  385. package/mapbox/index.d.ts.map +0 -1
  386. package/mapbox/layers/Layer.d.ts +0 -59
  387. package/mapbox/layers/Layer.d.ts.map +0 -1
  388. package/mapbox/layers/Layer.js +0 -101
  389. package/mapbox/layers/RealtimeLayer.d.ts +0 -180
  390. package/mapbox/layers/RealtimeLayer.d.ts.map +0 -1
  391. package/mapbox/layers/RealtimeLayer.js +0 -270
  392. package/mapbox/layers/index.d.ts +0 -3
  393. package/mapbox/layers/index.d.ts.map +0 -1
  394. package/mapbox/utils/getMercatorResolution.d.ts +0 -9
  395. package/mapbox/utils/getMercatorResolution.d.ts.map +0 -1
  396. package/mapbox/utils/getMercatorResolution.js +0 -18
  397. package/mapbox/utils/getSourceCoordinates.d.ts +0 -9
  398. package/mapbox/utils/getSourceCoordinates.d.ts.map +0 -1
  399. package/mapbox/utils/getSourceCoordinates.js +0 -27
  400. package/mapbox/utils/index.d.ts +0 -3
  401. package/mapbox/utils/index.d.ts.map +0 -1
  402. package/mbt.js +0 -64703
  403. package/mbt.js.map +0 -7
  404. package/mbt.min.js +0 -1090
  405. package/mbt.min.js.map +0 -7
  406. package/ol/controls/CopyrightControl.d.ts +0 -31
  407. package/ol/controls/CopyrightControl.d.ts.map +0 -1
  408. package/ol/controls/CopyrightControl.js +0 -68
  409. package/ol/controls/RoutingControl.d.ts +0 -193
  410. package/ol/controls/RoutingControl.d.ts.map +0 -1
  411. package/ol/controls/RoutingControl.js +0 -631
  412. package/ol/controls/StopFinderControl.d.ts +0 -30
  413. package/ol/controls/StopFinderControl.d.ts.map +0 -1
  414. package/ol/controls/index.d.ts +0 -4
  415. package/ol/controls/index.d.ts.map +0 -1
  416. package/ol/index.d.ts +0 -6
  417. package/ol/index.d.ts.map +0 -1
  418. package/ol/layers/Layer.d.ts +0 -86
  419. package/ol/layers/Layer.d.ts.map +0 -1
  420. package/ol/layers/Layer.js +0 -174
  421. package/ol/layers/MapGlLayer.d.ts +0 -67
  422. package/ol/layers/MapGlLayer.d.ts.map +0 -1
  423. package/ol/layers/MapGlLayer.js +0 -218
  424. package/ol/layers/MapboxLayer.d.ts +0 -50
  425. package/ol/layers/MapboxLayer.d.ts.map +0 -1
  426. package/ol/layers/MapboxLayer.js +0 -109
  427. package/ol/layers/MapboxStyleLayer.d.ts +0 -130
  428. package/ol/layers/MapboxStyleLayer.d.ts.map +0 -1
  429. package/ol/layers/MapboxStyleLayer.js +0 -378
  430. package/ol/layers/MaplibreLayer.d.ts.map +0 -1
  431. package/ol/layers/MaplibreLayer.js +0 -34
  432. package/ol/layers/RealtimeLayer.d.ts +0 -202
  433. package/ol/layers/RealtimeLayer.d.ts.map +0 -1
  434. package/ol/layers/RealtimeLayer.js +0 -336
  435. package/ol/layers/RoutingLayer.d.ts +0 -35
  436. package/ol/layers/RoutingLayer.d.ts.map +0 -1
  437. package/ol/layers/RoutingLayer.js +0 -85
  438. package/ol/layers/VectorLayer.d.ts +0 -25
  439. package/ol/layers/VectorLayer.d.ts.map +0 -1
  440. package/ol/layers/VectorLayer.js +0 -38
  441. package/ol/layers/WMSLayer.d.ts +0 -42
  442. package/ol/layers/WMSLayer.d.ts.map +0 -1
  443. package/ol/layers/WMSLayer.js +0 -88
  444. package/ol/layers/index.d.ts +0 -9
  445. package/ol/layers/index.d.ts.map +0 -1
  446. package/ol/styles/fullTrajectoryDelayStyle.d.ts +0 -4
  447. package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +0 -1
  448. package/ol/styles/fullTrajectoryDelayStyle.js +0 -33
  449. package/ol/styles/fullTrajectoryStyle.d.ts +0 -5
  450. package/ol/styles/fullTrajectoryStyle.d.ts.map +0 -1
  451. package/ol/styles/fullTrajectoryStyle.js +0 -44
  452. package/ol/styles/index.d.ts +0 -3
  453. package/ol/styles/index.d.ts.map +0 -1
  454. package/setupTests.d.ts +0 -2
  455. package/setupTests.d.ts.map +0 -1
  456. /package/{api → src/api}/index.js +0 -0
  457. /package/{common → src/common}/index.js +0 -0
  458. /package/{common → src/common}/styles/index.js +0 -0
  459. /package/{mapbox → src/mapbox}/controls/index.js +0 -0
  460. /package/{mapbox → src/mapbox}/index.js +0 -0
  461. /package/{mapbox → src/mapbox}/layers/index.js +0 -0
  462. /package/{mapbox → src/mapbox}/utils/index.js +0 -0
  463. /package/{ol → src/ol}/controls/index.js +0 -0
  464. /package/{ol → src/ol}/index.js +0 -0
  465. /package/{ol → src/ol}/layers/index.js +0 -0
  466. /package/{ol → src/ol}/styles/index.js +0 -0
  467. /package/{types → src/types}/common.d.ts +0 -0
  468. /package/{types → src/types}/index.d.ts +0 -0
  469. /package/{types → src/types}/realtime.d.ts +0 -0
  470. /package/{types → src/types}/routing.d.ts +0 -0
  471. /package/{types → src/types}/stops.d.ts +0 -0
@@ -1,631 +0,0 @@
1
- import { Feature } from 'ol';
2
- import { LineString, Point } from 'ol/geom';
3
- import { Modify } from 'ol/interaction';
4
- import { unByKey } from 'ol/Observable';
5
- import { click } from 'ol/events/condition';
6
- import { GeoJSON } from 'ol/format';
7
- import { buffer } from 'ol/extent';
8
- import { fromLonLat, toLonLat } from 'ol/proj';
9
- import BaseEvent from 'ol/events/Event';
10
- import { RoutingAPI } from '../../api';
11
- import ControlCommon from '../../common/controls/ControlCommon';
12
- import RoutingLayer from '../layers/RoutingLayer';
13
- // Examples for a single hop:
14
- // basel sbb a station named "basel sbb"
15
- // ZUE, station "Zürich HB" by its common abbreviation
16
- // Zürich Hauptbahnhof or HBF Zürich are all valid synonyms für "Zürich HB"
17
- // @47.37811,8.53935 a station at position 47.37811, 8.53935
18
- // @47.37811,8.53935$4 track 4 in a station at position 47.37811, 8.53935
19
- // zürich hb@47.37811,8.53935$8 track 8 in station "Zürich HB" at position 47.37811, 8.53935
20
- /** @private */
21
- const REGEX_VIA_POINT = /^([^@$!\n]*)(@?([\d.]+),([\d.]+))?(\$?([a-zA-Z0-9]{0,2}))$/;
22
- // Examples for a single hop:
23
- //
24
- // 47.37811,8.53935 a position 47.37811, 8.53935
25
- /** @private */
26
- const REGEX_VIA_POINT_COORD = /^([\d.]+),([\d.]+)$/;
27
- // Examples for a single hop:
28
- //
29
- // !8596126 a station with id 8596126
30
- // !8596126$4 a station with id 8596126
31
- /** @private */
32
- const REGEX_VIA_POINT_STATION_ID = /^!([^$]*)(\$?([a-zA-Z0-9]{0,2}))$/;
33
- /** @private */
34
- const STOP_FETCH_ABORT_CONTROLLER_KEY = 'stop-fetch';
35
- /** @private */
36
- const getFlatCoordinatesFromSegments = (segmentArray) => {
37
- const coords = [];
38
- segmentArray.forEach((seg) => {
39
- var _a;
40
- // @ts-ignore
41
- const coordArr = (_a = seg.getGeometry()) === null || _a === void 0 ? void 0 : _a.getCoordinates();
42
- if (coordArr === null || coordArr === void 0 ? void 0 : coordArr.length) {
43
- coords.push(...coordArr);
44
- }
45
- });
46
- return coords;
47
- };
48
- /**
49
- * Display a route of a specified mean of transport.
50
- *
51
- * @example
52
- * import { Map } from 'ol';
53
- * import { RoutingControl } from 'mobility-toolbox-js/ol';
54
- *
55
- * const map = new Map({
56
- * target: 'map'
57
- * });
58
- *
59
- * const control = new RoutingControl();
60
- *
61
- * control.attachToMap(map)
62
- *
63
- * @classproperty {string} apiKey - Key used for RoutingApi requests.
64
- * @classproperty {string} stopsApiKey - Key used for Stop lookup requests (defaults to apiKey).
65
- * @classproperty {string} stopsApiUrl - Url used for Stop lookup requests (defaults to https://api.geops.io/stops/v1/lookup/).
66
- * @classproperty {Array.<Array<graph="osm", minZoom=0, maxZoom=99>>} graphs - Array of routing graphs and min/max zoom levels. If you use the control in combination with the [geOps Maps API](https://developer.geops.io/apis/maps/), you may want to use the optimal level of generalizations: "[['gen4', 0, 8], ['gen3', 8, 9], ['gen2', 9, 11], ['gen1', 11, 13], ['osm', 13, 99]]"
67
- * @classproperty {string} mot - Mean of transport to be used for routing.
68
- * @classproperty {object} routingApiParams - object of additional parameters to pass to the routing api request.
69
- * @classproperty {object} snapToClosestStation - If true, the routing will snap the coordinate to the closest station. Default to false.
70
- * @classproperty {boolean} useRawViaPoints - Experimental property. Wen true, it allows the user to add via points using different kind of string. See "via" parameter defined by the [geOps Routing API](https://developer.geops.io/apis/routing/). Default to false, only array of coordinates and station's id are supported as via points.
71
- * @classproperty {RoutingLayer|Layer} routingLayer - Layer for adding route features.
72
- * @classproperty {function} onRouteError - Callback on error.
73
- * @classproperty {boolean} loading - True if the control is requesting the backend.
74
- * @see <a href="/example/ol-routing">Openlayers routing example</a>
75
- *
76
- * @extends {Control}
77
- * @implements {RoutingInterface}
78
- */
79
- class RoutingControl extends ControlCommon {
80
- constructor(options = {}) {
81
- super(options);
82
- this.viaPoints = [];
83
- this.loading = false;
84
- this.graphs = [];
85
- this.modify = true;
86
- this.useRawViaPoints = false;
87
- this.snapToClosestStation = false;
88
- this.cacheStationData = {};
89
- this.abortControllers = {};
90
- this.segments = [];
91
- this.format = new GeoJSON({ featureProjection: 'EPSG:3857' });
92
- this.initialRouteDrag = {};
93
- Object.defineProperties(this, {
94
- mot: {
95
- get: () => this.get('mot'),
96
- set: (newMot) => {
97
- if (newMot) {
98
- this.set('mot', newMot);
99
- if (this.viaPoints) {
100
- this.drawRoute();
101
- }
102
- }
103
- },
104
- },
105
- loading: {
106
- get: () => this.get('loading'),
107
- set: (newLoading) => {
108
- this.set('loading', newLoading);
109
- },
110
- },
111
- modify: {
112
- get: () => this.get('modify'),
113
- set: (modify) => {
114
- this.set('modify', modify);
115
- },
116
- },
117
- });
118
- /** True if the control is requesting the backend. */
119
- this.loading = false;
120
- /** @private */
121
- this.graphs = options.graphs || [['osm', 0, 99]];
122
- /** @private */
123
- this.mot = options.mot || 'bus';
124
- /** @private */
125
- this.modify = options.modify !== false;
126
- /** @private */
127
- this.routingApiParams = options.routingApiParams;
128
- /** @private */
129
- this.useRawViaPoints = options.useRawViaPoints || false;
130
- /** @private */
131
- this.snapToClosestStation = options.snapToClosestStation || false;
132
- /** @private */
133
- this.apiKey = options.apiKey;
134
- /** @private */
135
- this.stopsApiKey = options.stopsApiKey || this.apiKey;
136
- /** @private */
137
- this.stopsApiUrl = options.stopsApiUrl || 'https://api.geops.io/stops/v1/';
138
- /** @private */
139
- this.api = new RoutingAPI(Object.assign({}, options));
140
- /** @private */
141
- this.routingLayer =
142
- options.routingLayer ||
143
- new RoutingLayer({
144
- name: 'routing-layer',
145
- style: options.style,
146
- });
147
- /** @private */
148
- this.onRouteError =
149
- options.onRouteError ||
150
- ((error) => {
151
- this.dispatchEvent(new BaseEvent('change:route'));
152
- this.reset();
153
- // eslint-disable-next-line no-console
154
- console.error(error);
155
- });
156
- /** @private */
157
- this.onMapClick = this.onMapClick.bind(this);
158
- /** @private */
159
- this.onModifyEnd = this.onModifyEnd.bind(this);
160
- /** @private */
161
- this.onModifyStart = this.onModifyStart.bind(this);
162
- /** @private */
163
- this.createModifyInteraction();
164
- }
165
- /**
166
- * Calculate at which resolutions corresponds each generalizations.
167
- *
168
- * @private
169
- */
170
- static getGraphsResolutions(graphs, map) {
171
- const view = map.getView();
172
- return graphs.map(([, minZoom, maxZoom]) => [
173
- view.getResolutionForZoom(minZoom),
174
- view.getResolutionForZoom(maxZoom || minZoom + 1),
175
- ]);
176
- }
177
- /**
178
- * Adds/Replaces a viaPoint to the viaPoints array and redraws route:
179
- * Adds a viaPoint at end of array by default.
180
- * If an index is passed a viaPoint is added at the specified index.
181
- * If an index is passed and overwrite x is > 0, x viaPoints at the specified
182
- * index are replaced with a single new viaPoint.
183
- * @param {number[]|string} coordinates Array of coordinates
184
- * @param {number} [index=-1] Integer representing the index of the added viaPoint. If not specified, the viaPoint is added at the end of the array.
185
- * @param {number} [overwrite=0] Marks the number of viaPoints that are removed at the specified index on add.
186
- */
187
- addViaPoint(coordinatesOrString, index = -1, overwrite = 0) {
188
- /* Add/Insert/Overwrite viapoint and redraw route */
189
- this.viaPoints.splice(index === -1 ? this.viaPoints.length : index, overwrite, coordinatesOrString);
190
- this.drawRoute();
191
- this.dispatchEvent(new BaseEvent('change:route'));
192
- }
193
- /**
194
- * Removes a viaPoint at the passed array index and redraws route
195
- * By default the last viaPoint is removed.
196
- * @param {number} index Integer representing the index of the viaPoint to delete.
197
- */
198
- removeViaPoint(index = (this.viaPoints || []).length - 1) {
199
- /* Remove viapoint and redraw route */
200
- if (this.viaPoints.length && this.viaPoints[index]) {
201
- this.viaPoints.splice(index, 1);
202
- }
203
- this.drawRoute();
204
- this.dispatchEvent(new BaseEvent('change:route'));
205
- }
206
- /**
207
- * Replaces the current viaPoints with a new coordinate array.
208
- * @param {Array<Array<number>>} coordinateArray Array of nested coordinates
209
- */
210
- setViaPoints(coordinateArray) {
211
- this.viaPoints = [...coordinateArray];
212
- this.drawRoute();
213
- this.dispatchEvent(new BaseEvent('change:route'));
214
- }
215
- /**
216
- * Removes all viaPoints, clears the source and triggers a change event
217
- */
218
- reset() {
219
- var _a, _b, _c;
220
- // Clear viaPoints and source
221
- this.abortRequests();
222
- this.viaPoints = [];
223
- (_c = (_b = (_a = this.routingLayer) === null || _a === void 0 ? void 0 : _a.olLayer) === null || _b === void 0 ? void 0 : _b.getSource()) === null || _c === void 0 ? void 0 : _c.clear();
224
- this.dispatchEvent(new BaseEvent('change:route'));
225
- }
226
- /**
227
- * Aborts viapoint and route requests
228
- * @private
229
- */
230
- abortRequests() {
231
- var _a;
232
- // Abort Routing API requests
233
- this.graphs.forEach((graph) => {
234
- const graphName = graph[0];
235
- if (this.abortControllers[graphName]) {
236
- this.abortControllers[graphName].abort();
237
- }
238
- this.abortControllers[graphName] = new AbortController();
239
- });
240
- // Abort Stops API requests
241
- (_a = this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]) === null || _a === void 0 ? void 0 : _a.abort();
242
- this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY] =
243
- new AbortController();
244
- this.loading = false;
245
- }
246
- /**
247
- * Draws route on map using an array of coordinates:
248
- * If a single coordinate is passed a single point feature is added to map.
249
- * If two or more coordinates are passed a request to the RoutingAPI fetches
250
- * the route using the passed coordinates and the current mot.
251
- * @private
252
- */
253
- drawRoute() {
254
- var _a, _b, _c, _d, _e, _f;
255
- /* Calls RoutingAPI to draw a route using the viaPoints array */
256
- this.abortRequests();
257
- (_c = (_b = (_a = this.routingLayer) === null || _a === void 0 ? void 0 : _a.olLayer) === null || _b === void 0 ? void 0 : _b.getSource()) === null || _c === void 0 ? void 0 : _c.clear();
258
- if (!this.viaPoints.length) {
259
- return null;
260
- }
261
- if (this.viaPoints.length === 1) {
262
- // Add point for first node
263
- return this.drawViaPoint(this.viaPoints[0], 0, this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]);
264
- }
265
- const formattedViaPoints = this.viaPoints.map((viaPoint) => {
266
- var _a;
267
- if (Array.isArray(viaPoint)) {
268
- const projection = (_a = this.map) === null || _a === void 0 ? void 0 : _a.getView().getProjection();
269
- // viaPoint is a coordinate
270
- // Coordinates need to be reversed as required by the backend RoutingAPI
271
- const [lon, lat] = toLonLat(viaPoint, projection);
272
- return this.snapToClosestStation ? [`@${lat}`, lon] : [lat, lon];
273
- }
274
- // viaPoint is a string to use as it is
275
- return this.useRawViaPoints ? viaPoint : `!${viaPoint}`;
276
- });
277
- this.loading = true;
278
- // Clear source
279
- (_f = (_e = (_d = this.routingLayer) === null || _d === void 0 ? void 0 : _d.olLayer) === null || _e === void 0 ? void 0 : _e.getSource()) === null || _f === void 0 ? void 0 : _f.clear();
280
- // Create point features for the viaPoints
281
- this.viaPoints.forEach((viaPoint, idx) => this.drawViaPoint(viaPoint, idx, this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]));
282
- return Promise.all(this.graphs.map(([graph], index) => {
283
- const { signal } = this.abortControllers[graph];
284
- if (!this.api) {
285
- return Promise.resolve([]);
286
- }
287
- return this.api
288
- .route(Object.assign({ graph, via: `${formattedViaPoints.join('|')}`, mot: this.mot,
289
- // @ts-ignore missing property in swagger
290
- 'resolve-hops': false, elevation: false, 'coord-radius': 100.0, 'coord-punish': 1000.0 }, (this.routingApiParams || {})), { signal })
291
- .then((featureCollection) => {
292
- var _a, _b, _c, _d;
293
- this.segments = this.format.readFeatures(featureCollection);
294
- if (this.mot === 'foot') {
295
- // Extract unique values from viaPoint target value
296
- const uniqueVias = this.segments.reduce((resultVias, currentFeat) => {
297
- const segTrg = currentFeat.get('trg');
298
- return resultVias.find((via) => via[0] === segTrg[0] && via[1] === segTrg[1])
299
- ? resultVias
300
- : [...resultVias, segTrg];
301
- }, []);
302
- // Create LineString features from segments with same unique value
303
- this.segments = uniqueVias.map((via) => {
304
- const viaSegments = this.segments.filter((seg) => {
305
- const segTrg = seg.get('trg');
306
- return segTrg[0] === via[0] && segTrg[1] === via[1];
307
- });
308
- const coords = getFlatCoordinatesFromSegments(viaSegments);
309
- return new Feature({
310
- geometry: new LineString(coords),
311
- });
312
- });
313
- }
314
- // Create the new route. This route will be modifiable by the Modifiy interaction.
315
- const coords = getFlatCoordinatesFromSegments(this.segments);
316
- const routeFeature = new Feature({
317
- geometry: new LineString(coords),
318
- });
319
- routeFeature.set('graph', graph);
320
- routeFeature.set('mot', this.mot);
321
- if (this.graphsResolutions &&
322
- ((_a = this.graphsResolutions[index]) === null || _a === void 0 ? void 0 : _a.length) >= 2) {
323
- routeFeature.set('minResolution', this.graphsResolutions[index][0]);
324
- routeFeature.set('maxResolution', this.graphsResolutions[index][1]);
325
- }
326
- (_d = (_c = (_b = this.routingLayer) === null || _b === void 0 ? void 0 : _b.olLayer) === null || _c === void 0 ? void 0 : _c.getSource()) === null || _d === void 0 ? void 0 : _d.addFeature(routeFeature);
327
- this.loading = false;
328
- })
329
- .catch((error) => {
330
- if (error.name === 'AbortError') {
331
- // Ignore abort error
332
- return;
333
- }
334
- this.segments = [];
335
- // Dispatch error event and execute error function
336
- this.dispatchEvent(new BaseEvent('error'));
337
- this.onRouteError(error, this);
338
- this.loading = false;
339
- });
340
- }));
341
- }
342
- /**
343
- * Draw a via point. This function can parse all the possibilitiies
344
- *
345
- * @private
346
- */
347
- drawViaPoint(viaPoint, idx, abortController) {
348
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
349
- const pointFeature = new Feature();
350
- pointFeature.set('viaPointIdx', idx);
351
- // The via point is a coordinate using the current map's projection
352
- if (Array.isArray(viaPoint)) {
353
- pointFeature.setGeometry(new Point(viaPoint));
354
- (_c = (_b = (_a = this.routingLayer) === null || _a === void 0 ? void 0 : _a.olLayer) === null || _b === void 0 ? void 0 : _b.getSource()) === null || _c === void 0 ? void 0 : _c.addFeature(pointFeature);
355
- return Promise.resolve(pointFeature);
356
- }
357
- // Possibility to parse:
358
- //
359
- // !8596126 a station with id 8596126
360
- // !8596126$4 a station with id 8596126
361
- if (!this.useRawViaPoints || REGEX_VIA_POINT_STATION_ID.test(viaPoint)) {
362
- let stationId;
363
- let track;
364
- if (this.useRawViaPoints) {
365
- [, stationId, , track] =
366
- REGEX_VIA_POINT_STATION_ID.exec(viaPoint) || [];
367
- }
368
- else {
369
- [stationId, track] = viaPoint.split('$');
370
- }
371
- return fetch(`${this.stopsApiUrl}lookup/${stationId}?key=${this.stopsApiKey}`, { signal: abortController.signal })
372
- .then((res) => res.json())
373
- .then((stationData) => {
374
- var _a, _b, _c;
375
- const { coordinates } = stationData.features[0].geometry;
376
- this.cacheStationData[viaPoint] = fromLonLat(coordinates);
377
- pointFeature.set('viaPointTrack', track);
378
- pointFeature.setGeometry(new Point(fromLonLat(coordinates)));
379
- (_c = (_b = (_a = this.routingLayer) === null || _a === void 0 ? void 0 : _a.olLayer) === null || _b === void 0 ? void 0 : _b.getSource()) === null || _c === void 0 ? void 0 : _c.addFeature(pointFeature);
380
- return pointFeature;
381
- })
382
- .catch((error) => {
383
- if (error.name === 'AbortError') {
384
- // Ignore abort error
385
- return;
386
- }
387
- // Dispatch error event and execute error function
388
- this.dispatchEvent(new BaseEvent('error'));
389
- this.onRouteError(error, this);
390
- this.loading = false;
391
- });
392
- }
393
- // Only when this.useRawViaPoints is true.
394
- // Possibility to parse:
395
- //
396
- // 47.37811,8.53935 a position 47.37811, 8.53935
397
- if (this.useRawViaPoints && REGEX_VIA_POINT_COORD.test(viaPoint)) {
398
- const [lat, lon] = REGEX_VIA_POINT_COORD.exec(viaPoint) || [];
399
- if (lon && lat) {
400
- const floatLon = parseFloat(lon);
401
- const floatLat = parseFloat(lat);
402
- const coordinates = fromLonLat([floatLon, floatLat], (_d = this.map) === null || _d === void 0 ? void 0 : _d.getView().getProjection());
403
- pointFeature.setGeometry(new Point(coordinates));
404
- (_g = (_f = (_e = this.routingLayer) === null || _e === void 0 ? void 0 : _e.olLayer) === null || _f === void 0 ? void 0 : _f.getSource()) === null || _g === void 0 ? void 0 : _g.addFeature(pointFeature);
405
- return Promise.resolve(pointFeature);
406
- }
407
- }
408
- // Only when this.useRawViaPoints is true.
409
- // It will parse the via point to find some name, id, track coordinates.
410
- //
411
- // Possibility to parse:
412
- //
413
- // @47.37811,8.53935 a station at position 47.37811, 8.53935
414
- // @47.37811,8.53935$4 track 4 in a station at position 47.37811, 8.53935
415
- // zürich hb@47.37811,8.53935$8 track 8 in station "Zürich HB" at position 47.37811, 8.53935
416
- const [, stationName, , lat, lon, , track] = REGEX_VIA_POINT.exec(viaPoint) || [];
417
- if (lon && lat) {
418
- const coordinates = fromLonLat([parseFloat(lon), parseFloat(lat)], (_h = this.map) === null || _h === void 0 ? void 0 : _h.getView().getProjection());
419
- pointFeature.set('viaPointTrack', track);
420
- pointFeature.setGeometry(new Point(coordinates));
421
- (_l = (_k = (_j = this.routingLayer) === null || _j === void 0 ? void 0 : _j.olLayer) === null || _k === void 0 ? void 0 : _k.getSource()) === null || _l === void 0 ? void 0 : _l.addFeature(pointFeature);
422
- return Promise.resolve(pointFeature);
423
- }
424
- if (stationName) {
425
- return fetch(`${this.stopsApiUrl}?key=${this.stopsApiKey}&q=${stationName}&limit=1`, { signal: abortController.signal })
426
- .then((res) => res.json())
427
- .then((stationData) => {
428
- var _a, _b, _c;
429
- const { coordinates } = stationData.features[0].geometry;
430
- this.cacheStationData[viaPoint] = fromLonLat(coordinates);
431
- pointFeature.set('viaPointTrack', track);
432
- pointFeature.setGeometry(new Point(fromLonLat(coordinates)));
433
- (_c = (_b = (_a = this.routingLayer) === null || _a === void 0 ? void 0 : _a.olLayer) === null || _b === void 0 ? void 0 : _b.getSource()) === null || _c === void 0 ? void 0 : _c.addFeature(pointFeature);
434
- return pointFeature;
435
- })
436
- .catch((error) => {
437
- // Dispatch error event and execute error function
438
- this.dispatchEvent(new BaseEvent('error'));
439
- this.onRouteError(error, this);
440
- this.loading = false;
441
- return null;
442
- });
443
- }
444
- return Promise.resolve(null);
445
- }
446
- /**
447
- * Used on click on map while control is active:
448
- * By default adds a viaPoint to the end of array.
449
- * If an existing viaPoint is clicked removes the clicked viaPoint.
450
- * @private
451
- */
452
- onMapClick(evt) {
453
- const feats = evt.target.getFeaturesAtPixel(evt.pixel);
454
- const viaPoint = feats.find((feat) => {
455
- var _a;
456
- return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === 'Point' &&
457
- feat.get('viaPointIdx') !== undefined;
458
- });
459
- if (viaPoint) {
460
- // Remove existing viaPoint on click and abort viaPoint add
461
- this.removeViaPoint(viaPoint.get('viaPointIdx'));
462
- return;
463
- }
464
- this.addViaPoint(evt.coordinate);
465
- }
466
- /**
467
- * Used on start of the modify interaction. Stores relevant data
468
- * in this.initialRouteDrag object
469
- * @private
470
- */
471
- onModifyStart(evt) {
472
- var _a;
473
- // When modify start, we search the index of the segment that is modifying.
474
- let segmentIndex = -1;
475
- const route = evt.features
476
- .getArray()
477
- .find((feat) => { var _a; return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === 'LineString'; });
478
- // Find the segment index that is being modified
479
- if (route && route.getGeometry() && evt.mapBrowserEvent.coordinate) {
480
- // We use a buff extent to fix floating issues , see https://github.com/openlayers/openlayers/issues/7130#issuecomment-535856422
481
- const closestExtent = buffer(new Point(
482
- // @ts-ignore
483
- (_a = route.getGeometry()) === null || _a === void 0 ? void 0 : _a.getClosestPoint(evt.mapBrowserEvent.coordinate)).getExtent(), 0.001);
484
- segmentIndex = this.segments.findIndex((segment) => { var _a; return (_a = segment.getGeometry()) === null || _a === void 0 ? void 0 : _a.intersectsExtent(closestExtent); });
485
- }
486
- // Find the viaPoint that is being modified
487
- const viaPoint = (evt.features
488
- .getArray()
489
- .filter((feat) => { var _a; return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === 'Point'; }) ||
490
- [])[0];
491
- // Write object with modify info
492
- /** @private */
493
- this.initialRouteDrag = {
494
- viaPoint,
495
- oldRoute: route && route.clone(),
496
- segmentIndex,
497
- };
498
- }
499
- /**
500
- * Used on end of the modify interaction. Resolves feature modification:
501
- * Line drag creates new viaPoint at the final coordinate of drag.
502
- * Point drag replaces old viaPoint.
503
- * @private
504
- */
505
- onModifyEnd(evt) {
506
- const coord = evt.mapBrowserEvent.coordinate;
507
- const { oldRoute, viaPoint, segmentIndex } = this.initialRouteDrag || {};
508
- // If viaPoint is being relocated overwrite the old viaPoint
509
- if (viaPoint) {
510
- return this.addViaPoint(coord, viaPoint.get('viaPointIdx'), 1);
511
- }
512
- // In case there is no route overwrite first coordinate
513
- if (!oldRoute) {
514
- return this.addViaPoint(coord, 0, 1);
515
- }
516
- // We can't add a via point because we haven't found which segment has been modified.
517
- if (segmentIndex === -1) {
518
- return Promise.reject(new Error('No segment found'));
519
- }
520
- // Insert new viaPoint at the modified segment index + 1
521
- return this.addViaPoint(coord, (segmentIndex || 0) + 1);
522
- }
523
- /**
524
- * Define a default element.
525
- *
526
- * @private
527
- */
528
- createDefaultElement() {
529
- /** @private */
530
- this.element = document.createElement('button');
531
- this.element.id = 'ol-toggle-routing';
532
- this.element.innerHTML = 'Toggle Route Control';
533
- this.element.onclick = () => this.active ? this.deactivate() : this.activate();
534
- Object.assign(this.element.style, {
535
- position: 'absolute',
536
- right: '10px',
537
- top: '10px',
538
- });
539
- }
540
- /**
541
- * Create the interaction used to modify vertexes of features.
542
- * @private
543
- */
544
- createModifyInteraction() {
545
- var _a, _b, _c;
546
- /**
547
- * @type {ol.interaction.Modify}
548
- * @private
549
- */
550
- // Define and add modify interaction
551
- this.modifyInteraction = new Modify({
552
- source: ((_b = (_a = this.routingLayer) === null || _a === void 0 ? void 0 : _a.olLayer) === null || _b === void 0 ? void 0 : _b.getSource()) || undefined,
553
- pixelTolerance: 4,
554
- hitDetection: (_c = this.routingLayer) === null || _c === void 0 ? void 0 : _c.olLayer,
555
- deleteCondition: (e) => {
556
- const feats = e.target.getFeaturesAtPixel(e.pixel, {
557
- hitTolerance: 5,
558
- });
559
- const viaPoint = feats.find((feat) => { var _a; return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === 'Point' && feat.get('index'); });
560
- if (click(e) && viaPoint) {
561
- // Remove node & viaPoint if an existing viaPoint was clicked
562
- this.removeViaPoint(viaPoint.get('index'));
563
- return true;
564
- }
565
- return false;
566
- },
567
- });
568
- this.modifyInteraction.on('modifystart', this.onModifyStart);
569
- this.modifyInteraction.on('modifyend', this.onModifyEnd);
570
- this.modifyInteraction.setActive(false);
571
- }
572
- /**
573
- * Add click listener to map.
574
- * @private
575
- */
576
- addListeners() {
577
- var _a;
578
- if (!this.modify) {
579
- return;
580
- }
581
- this.removeListeners();
582
- /** @private */
583
- this.onMapClickKey = (_a = this.map) === null || _a === void 0 ? void 0 : _a.on('singleclick', this.onMapClick);
584
- }
585
- /**
586
- * Remove click listener from map.
587
- * @private
588
- */
589
- removeListeners() {
590
- if (this.onMapClickKey) {
591
- unByKey(this.onMapClickKey);
592
- }
593
- }
594
- activate() {
595
- var _a, _b;
596
- super.activate();
597
- if (this.map) {
598
- /** @private */
599
- this.format = new GeoJSON({
600
- featureProjection: this.map.getView().getProjection(),
601
- });
602
- /** @private */
603
- this.graphsResolutions = RoutingControl.getGraphsResolutions(this.graphs, this.map);
604
- // Clean the modifyInteraction if present
605
- if (this.modifyInteraction) {
606
- this.map.removeInteraction(this.modifyInteraction);
607
- }
608
- // Add modify interaction, RoutingLayer and listeners
609
- (_a = this.routingLayer) === null || _a === void 0 ? void 0 : _a.attachToMap(this.map);
610
- if (this.modifyInteraction) {
611
- this.map.addInteraction(this.modifyInteraction);
612
- }
613
- (_b = this.modifyInteraction) === null || _b === void 0 ? void 0 : _b.setActive(this.modify);
614
- this.addListeners();
615
- }
616
- }
617
- deactivate() {
618
- var _a;
619
- if (this.map) {
620
- // Remove modify interaction, RoutingLayer, listeners and viaPoints
621
- (_a = this.routingLayer) === null || _a === void 0 ? void 0 : _a.detachFromMap();
622
- if (this.modifyInteraction) {
623
- this.map.removeInteraction(this.modifyInteraction);
624
- }
625
- this.removeListeners();
626
- this.reset();
627
- }
628
- }
629
- render() { }
630
- }
631
- export default RoutingControl;
@@ -1,30 +0,0 @@
1
- import { Feature } from 'geojson';
2
- import StopFinderControlCommon from '../../common/controls/StopFinderControlCommon';
3
- /**
4
- * Search stations.
5
- *
6
- * @example
7
- * import { Map } from 'ol';
8
- * import { StopFinderControl } from 'mobility-toolbox-js/ol';
9
- *
10
- * const map = new Map({
11
- * target: 'map',
12
- * });
13
- *
14
- * const control = new StopFinderControl({
15
- * apiKey: [yourApiKey]
16
- * });
17
- *
18
- * control.attachToMap(map);
19
- *
20
- *
21
- * @see <a href="/example/ol-search">Openlayers search example</a>
22
- */
23
- declare class StopFinderControl extends StopFinderControlCommon {
24
- /**
25
- * @private
26
- */
27
- onSuggestionClick(suggestion: Feature): void;
28
- }
29
- export default StopFinderControl;
30
- //# sourceMappingURL=StopFinderControl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StopFinderControl.d.ts","sourceRoot":"","sources":["../../../src/ol/controls/StopFinderControl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,MAAM,SAAS,CAAC;AAEzC,OAAO,uBAAuB,MAAM,+CAA+C,CAAC;AAEpF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,cAAM,iBAAkB,SAAQ,uBAAuB;IACrD;;OAEG;IACH,iBAAiB,CAAC,UAAU,EAAE,OAAO;CAItC;AAED,eAAe,iBAAiB,CAAC"}
@@ -1,4 +0,0 @@
1
- export { default as CopyrightControl } from "./CopyrightControl";
2
- export { default as RoutingControl } from "./RoutingControl";
3
- export { default as StopFinderControl } from "./StopFinderControl";
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ol/controls/index.js"],"names":[],"mappings":""}
package/ol/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export * from "../api";
2
- export * from "../common";
3
- export * from "./controls";
4
- export * from "./layers";
5
- export * from "./styles";
6
- //# sourceMappingURL=index.d.ts.map