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