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

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