mobility-toolbox-js 2.3.9-beta.1 → 2.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +19 -19
- 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 -778
- 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 -64703
- 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 -336
- 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
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import createRealtimeFilters from './createRealtimeFilters';
|
|
2
|
+
|
|
3
|
+
const u1 = {
|
|
4
|
+
properties: {
|
|
5
|
+
route_identifier: '001.000827.004:7',
|
|
6
|
+
operator: 'FoO',
|
|
7
|
+
line: {
|
|
8
|
+
name: 'U1',
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
const ireta = {
|
|
13
|
+
properties: {
|
|
14
|
+
routeIdentifier: '0022.000827.004:7',
|
|
15
|
+
tenant: 'BAR',
|
|
16
|
+
line: {
|
|
17
|
+
name: 'IRETA',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
const arb = {
|
|
22
|
+
properties: {
|
|
23
|
+
route_identifier: '00333.000827.004:7',
|
|
24
|
+
operator: 'qux',
|
|
25
|
+
line: {
|
|
26
|
+
name: 'ARB',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const trajectories = [u1, ireta, arb];
|
|
32
|
+
|
|
33
|
+
describe('#createTrackerFilter()', () => {
|
|
34
|
+
test('returns null', () => {
|
|
35
|
+
const filterFunc = createRealtimeFilters();
|
|
36
|
+
expect(filterFunc).toBe(null);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('using line', () => {
|
|
40
|
+
test('as string', () => {
|
|
41
|
+
const filterFunc = createRealtimeFilters('u1,foo');
|
|
42
|
+
expect(trajectories.filter(filterFunc)).toEqual([u1]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('as array of string', () => {
|
|
46
|
+
const filterFunc = createRealtimeFilters(['u1', 'foo', 'IRETA']);
|
|
47
|
+
expect(trajectories.filter(filterFunc)).toEqual([u1, ireta]);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('using route identifier (snake_case and camelCase (only tralis)', () => {
|
|
52
|
+
test('as string', () => {
|
|
53
|
+
const filterFunc = createRealtimeFilters(null, '1,foo');
|
|
54
|
+
expect(trajectories.filter(filterFunc)).toEqual([u1]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('as array of string', () => {
|
|
58
|
+
const filterFunc = createRealtimeFilters(null, ['22', 'foo', '1']);
|
|
59
|
+
expect(trajectories.filter(filterFunc)).toEqual([u1, ireta]);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('using operator', () => {
|
|
64
|
+
test('as string (using operator deprecated property)', () => {
|
|
65
|
+
const filterFunc = createRealtimeFilters(null, null, 'foo');
|
|
66
|
+
expect(trajectories.filter(filterFunc)).toEqual([u1]);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('as string (using tenant property)', () => {
|
|
70
|
+
const filterFunc = createRealtimeFilters(null, null, 'bar');
|
|
71
|
+
expect(trajectories.filter(filterFunc)).toEqual([ireta]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('as array of string', () => {
|
|
75
|
+
const filterFunc = createRealtimeFilters(null, null, ['bar', 'foo', '1']);
|
|
76
|
+
expect(trajectories.filter(filterFunc)).toEqual([u1, ireta]);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('using regexLine', () => {
|
|
81
|
+
test('as string', () => {
|
|
82
|
+
const filterFunc = createRealtimeFilters(
|
|
83
|
+
null,
|
|
84
|
+
null,
|
|
85
|
+
null,
|
|
86
|
+
'^(S|R$|RE|PE|D|IRE|RB|TER)',
|
|
87
|
+
);
|
|
88
|
+
expect(trajectories.filter(filterFunc)).toEqual([ireta]);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('as array of string', () => {
|
|
92
|
+
const filterFunc = createRealtimeFilters(null, null, null, [
|
|
93
|
+
'^IR',
|
|
94
|
+
'^ARB$',
|
|
95
|
+
'foo',
|
|
96
|
+
]);
|
|
97
|
+
expect(trajectories.filter(filterFunc)).toEqual([ireta, arb]);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { RealtimeTrajectory } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Return a filter functions based on some parameters of a vehicle.
|
|
4
|
+
*
|
|
5
|
+
* @param {string|Array<string>} line - A list of vehicle's name to filter. Names can be separated by a comma. Ex: 'S1,S2,S3'
|
|
6
|
+
* @param {string|Array<string} route - A list of vehicle's route (contained in route_identifier property) to filter. Indentifiers can be separated by a comma. Ex: 'id1,id2,id3'
|
|
7
|
+
* @param {string|Array<string} operator A list of vehicle's operator to filter. Operators can be separated by a comma. Ex: 'SBB,DB'
|
|
8
|
+
* @param {Regexp} regexLine - A regex aplly of vehcile's name.
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
const createRealtimeFilters = (
|
|
12
|
+
line: string | string[],
|
|
13
|
+
route: string | string[],
|
|
14
|
+
operator: string | string[],
|
|
15
|
+
regexLine: string | string[],
|
|
16
|
+
): ((trajectory: RealtimeTrajectory) => boolean) | null => {
|
|
17
|
+
const filterList: ((trajectory: RealtimeTrajectory) => boolean)[] = [];
|
|
18
|
+
|
|
19
|
+
if (!line && !route && !operator && !regexLine) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (regexLine) {
|
|
24
|
+
const regexLineList: string[] =
|
|
25
|
+
typeof regexLine === 'string' ? [regexLine] : regexLine;
|
|
26
|
+
const lineFilter = (item: RealtimeTrajectory) => {
|
|
27
|
+
const name =
|
|
28
|
+
item.properties.name ||
|
|
29
|
+
(item.properties.line && item.properties.line.name) ||
|
|
30
|
+
'';
|
|
31
|
+
if (!name) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return regexLineList.some((regexStr) =>
|
|
35
|
+
new RegExp(regexStr, 'i').test(name),
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
filterList.push(lineFilter);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (line) {
|
|
42
|
+
const lineFiltersList = typeof line === 'string' ? line.split(',') : line;
|
|
43
|
+
const lineList = lineFiltersList.map((l) =>
|
|
44
|
+
l.replace(/\s+/g, '').toUpperCase(),
|
|
45
|
+
);
|
|
46
|
+
const lineFilter = (item: RealtimeTrajectory) => {
|
|
47
|
+
const { line: linee, name } = item.properties;
|
|
48
|
+
const lineName = (name || (linee && linee.name) || '').toUpperCase();
|
|
49
|
+
if (!lineName) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return lineList.includes(lineName);
|
|
53
|
+
};
|
|
54
|
+
filterList.push(lineFilter);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (route) {
|
|
58
|
+
const routes = typeof route === 'string' ? route.split(',') : route;
|
|
59
|
+
const routeList = routes.map((item) => parseInt(item, 10));
|
|
60
|
+
const routeFilter = (item: RealtimeTrajectory) => {
|
|
61
|
+
const routeIdentifier =
|
|
62
|
+
item.properties.route_identifier ||
|
|
63
|
+
item.properties.routeIdentifier ||
|
|
64
|
+
'';
|
|
65
|
+
const routeId = parseInt(routeIdentifier.split('.')[0], 10);
|
|
66
|
+
return routeList.includes(routeId);
|
|
67
|
+
};
|
|
68
|
+
filterList.push(routeFilter);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (operator) {
|
|
72
|
+
const operatorList = typeof operator === 'string' ? [operator] : operator;
|
|
73
|
+
const operatorFilter = (item: RealtimeTrajectory) =>
|
|
74
|
+
operatorList.some((op) => {
|
|
75
|
+
// operaotr is the old property tenant is the new one
|
|
76
|
+
const tenant = item.properties.operator || item.properties.tenant || '';
|
|
77
|
+
return new RegExp(op, 'i').test(tenant);
|
|
78
|
+
});
|
|
79
|
+
filterList.push(operatorFilter);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!filterList.length) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return (item: RealtimeTrajectory) => {
|
|
87
|
+
for (let i = 0; i < filterList.length; i += 1) {
|
|
88
|
+
if (!filterList[i](item)) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export default createRealtimeFilters;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { RealtimeAPIDeparturesById } from '../../api/RealtimeAPI';
|
|
2
|
+
import type { RealtimeDeparture, RealtimeDepartureExtended } from '../../types';
|
|
3
|
+
import type {
|
|
4
|
+
WebSocketAPIMessageCallback,
|
|
5
|
+
WebSocketAPIMessageEventData,
|
|
6
|
+
} from '../api/WebSocketAPI';
|
|
7
|
+
import sortAndFilterDepartures from './sortAndFilterDepartures';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* This function returns a WebSocket api callback, and call the onDeparturesUpdate function with the list of current departures to display.
|
|
11
|
+
* @param {function(departures: RealtimeDeparture[])} onDeparturesUpdate callback when list of departures changes, called after 100 ms
|
|
12
|
+
* @param {boolean} [sortByMinArrivalTime = true] Sort departures by arrival time
|
|
13
|
+
* @param {number} [maxDepartureAge = 30] max departure age of departures in minutes
|
|
14
|
+
* @param {number} [timeout = 100] debounce timeout in ms
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
const debounceDeparturesMessages = (
|
|
18
|
+
onDeparturesUpdate: (departures: RealtimeDepartureExtended[]) => {},
|
|
19
|
+
sortByMinArrivalTime = false,
|
|
20
|
+
maxDepartureAge = 30,
|
|
21
|
+
timeout = 100,
|
|
22
|
+
): WebSocketAPIMessageCallback<RealtimeDeparture> => {
|
|
23
|
+
const departureUpdateTimeout: {
|
|
24
|
+
[key: string]: number;
|
|
25
|
+
} = {};
|
|
26
|
+
|
|
27
|
+
const departureObject: RealtimeAPIDeparturesById = {};
|
|
28
|
+
|
|
29
|
+
return (data: WebSocketAPIMessageEventData<RealtimeDeparture>) => {
|
|
30
|
+
const { source, content: departure } = data;
|
|
31
|
+
if (departureUpdateTimeout[source]) {
|
|
32
|
+
window.clearTimeout(departureUpdateTimeout[source]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!departure) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
departureObject[departure.call_id] = departure;
|
|
40
|
+
|
|
41
|
+
departureUpdateTimeout[source] = window.setTimeout(() => {
|
|
42
|
+
const departures = sortAndFilterDepartures(
|
|
43
|
+
departureObject,
|
|
44
|
+
sortByMinArrivalTime || false,
|
|
45
|
+
maxDepartureAge,
|
|
46
|
+
);
|
|
47
|
+
onDeparturesUpdate(departures);
|
|
48
|
+
}, timeout);
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default debounceDeparturesMessages;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
WebSocketAPIMessageCallback,
|
|
3
|
+
WebSocketAPIMessageEventData,
|
|
4
|
+
} from '../api/WebSocketAPI';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This function returns a WebSocket api callback, and call the onUpdate function with the list of of subscribed objects changes.
|
|
8
|
+
*
|
|
9
|
+
* @param {function(objects: any[])} onUpdate callback when list of subscribed objects changes, called after 100 ms
|
|
10
|
+
* @param {function(object: any)} [getObjectId = true] function returning the id of an object
|
|
11
|
+
* @param {number} [timeout = 100] debounce timeout in ms
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
const debounceWebsocketMessages = (
|
|
15
|
+
onUpdate: (objects: any[]) => void,
|
|
16
|
+
getObjectId?: (object: any) => string,
|
|
17
|
+
timeout = 100,
|
|
18
|
+
): WebSocketAPIMessageCallback<any> => {
|
|
19
|
+
const updateTimeout: {
|
|
20
|
+
[key: string]: number;
|
|
21
|
+
} = {};
|
|
22
|
+
|
|
23
|
+
const objectsById: {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
} = {};
|
|
26
|
+
const objects: any[] = [];
|
|
27
|
+
|
|
28
|
+
return (data: WebSocketAPIMessageEventData<any>) => {
|
|
29
|
+
const { source, content } = data;
|
|
30
|
+
if (updateTimeout[source]) {
|
|
31
|
+
window.clearTimeout(updateTimeout[source]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (getObjectId) {
|
|
35
|
+
objectsById[getObjectId(content)] = content;
|
|
36
|
+
} else {
|
|
37
|
+
objects.push(content);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
updateTimeout[source] = window.setTimeout(() => {
|
|
41
|
+
const objectToReturn = getObjectId ? Object.values(objectsById) : objects;
|
|
42
|
+
onUpdate(objectToReturn);
|
|
43
|
+
}, timeout);
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default debounceWebsocketMessages;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// TODO: I use any to avoid circular dependency with common/layers/layer
|
|
2
|
+
/** @private */
|
|
3
|
+
const getLayersAsFlatArray = (layersOrLayer: any | any[]): any[] => {
|
|
4
|
+
let layers = layersOrLayer;
|
|
5
|
+
if (!Array.isArray(layers)) {
|
|
6
|
+
layers = [layersOrLayer as any];
|
|
7
|
+
}
|
|
8
|
+
let flatLayers: any[] = [];
|
|
9
|
+
layers.forEach((layer: any) => {
|
|
10
|
+
flatLayers.push(layer);
|
|
11
|
+
const { children } = layer;
|
|
12
|
+
flatLayers = flatLayers.concat(getLayersAsFlatArray(children || []));
|
|
13
|
+
});
|
|
14
|
+
return flatLayers;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default getLayersAsFlatArray;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import getMapboxMapCopyrights from './getMapboxMapCopyrights';
|
|
2
|
+
|
|
3
|
+
describe('getMapboxMapCopyrights()', () => {
|
|
4
|
+
test('returns an empty array if map is not defined', () => {
|
|
5
|
+
expect(getMapboxMapCopyrights().length).toBe(0);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
test('returns an empty array if map.style is not defined', () => {
|
|
9
|
+
expect(getMapboxMapCopyrights({}).length).toBe(0);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('returns non depluicated copyrights in an array', () => {
|
|
13
|
+
expect(
|
|
14
|
+
getMapboxMapCopyrights({
|
|
15
|
+
style: {
|
|
16
|
+
sourceCaches: {
|
|
17
|
+
used: {
|
|
18
|
+
used: true,
|
|
19
|
+
getSource() {
|
|
20
|
+
return {
|
|
21
|
+
attribution:
|
|
22
|
+
'<a href="https://www.openmaptiles.org/" target="_blank">© OpenMapTiles</a> <a href="https://www.openstreetmap.org/about/" target="_blank">© OpenStreetMap contributors</a>',
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
'not used': {
|
|
27
|
+
used: false,
|
|
28
|
+
},
|
|
29
|
+
'also used': {
|
|
30
|
+
used: true,
|
|
31
|
+
getSource() {
|
|
32
|
+
return {
|
|
33
|
+
attribution:
|
|
34
|
+
'<a href="https://www.openmaptiles.org/" target="_blank">© OpenMapTiles</a> <a href="https://www.imagico.de/" target="_blank">© imagico</a>',
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
).toEqual([
|
|
42
|
+
'<a href="https://www.openmaptiles.org/" target="_blank">© OpenMapTiles</a>',
|
|
43
|
+
'<a href="https://www.openstreetmap.org/about/" target="_blank">© OpenStreetMap contributors</a>',
|
|
44
|
+
'<a href="https://www.imagico.de/" target="_blank">© imagico</a>',
|
|
45
|
+
]);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import removeDuplicate from './removeDuplicate';
|
|
2
|
+
|
|
3
|
+
export interface Source {
|
|
4
|
+
attribution: string;
|
|
5
|
+
options: {
|
|
6
|
+
attribution: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface SourceCache {
|
|
11
|
+
used: boolean;
|
|
12
|
+
getSource: () => Source;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Return the copyright a Mapbox map.
|
|
17
|
+
* @param {mapboxgl.Map | maplibregl.Map} map A Mapbox map
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
const getMapboxMapCopyrights = (map: mapboxgl.Map | maplibregl.Map) => {
|
|
21
|
+
if (!map) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
const { style } = map;
|
|
26
|
+
if (!style) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
const { sourceCaches } = style;
|
|
30
|
+
let copyrights: string[] = [];
|
|
31
|
+
|
|
32
|
+
Object.values(sourceCaches as SourceCache[]).forEach(
|
|
33
|
+
(sourceCache: SourceCache) => {
|
|
34
|
+
if (sourceCache.used as boolean) {
|
|
35
|
+
const source = sourceCache.getSource();
|
|
36
|
+
|
|
37
|
+
const attribution = // @ts-ignore
|
|
38
|
+
source.attribution || (source.options && source.options.attribution);
|
|
39
|
+
|
|
40
|
+
if (attribution) {
|
|
41
|
+
copyrights = copyrights.concat(
|
|
42
|
+
attribution.replace(/©/g, '©').split(/(<a.*?<\/a>)/),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
return removeDuplicate(copyrights);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default getMapboxMapCopyrights;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle */
|
|
2
|
+
import { RenderFunction } from 'ol/layer/Layer';
|
|
3
|
+
import type { FrameState } from 'ol/Map';
|
|
4
|
+
import { toLonLat } from 'ol/proj';
|
|
5
|
+
import type { MapboxLayer } from '../../ol';
|
|
6
|
+
/**
|
|
7
|
+
* Return the render function fo the olLayer of a MaplibreLayer
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
10
|
+
export default function getMapboxRender(
|
|
11
|
+
mapoxLayer: MapboxLayer,
|
|
12
|
+
): RenderFunction {
|
|
13
|
+
// We cretae emptyDiv only in render finction to work with serverside rendering
|
|
14
|
+
let emptyDiv: HTMLElement;
|
|
15
|
+
return (frameState: FrameState) => {
|
|
16
|
+
const { map, mbMap, renderState, olLayer } = mapoxLayer;
|
|
17
|
+
if (!map || !mbMap) {
|
|
18
|
+
if (!emptyDiv) {
|
|
19
|
+
emptyDiv = document.createElement('div');
|
|
20
|
+
}
|
|
21
|
+
return emptyDiv;
|
|
22
|
+
}
|
|
23
|
+
let changed = false;
|
|
24
|
+
const canvas = mbMap.getCanvas();
|
|
25
|
+
const { viewState } = frameState;
|
|
26
|
+
|
|
27
|
+
const visible = olLayer?.getVisible();
|
|
28
|
+
if (renderState && renderState?.visible !== visible) {
|
|
29
|
+
canvas.style.display = visible ? 'block' : 'none';
|
|
30
|
+
renderState.visible = visible;
|
|
31
|
+
// Needed since mapbox-gl 1.9.0.
|
|
32
|
+
// Without you don't see others ol layers on top.
|
|
33
|
+
canvas.style.position = 'absolute';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const opacity = olLayer?.getOpacity();
|
|
37
|
+
if (canvas && renderState && renderState.opacity !== opacity) {
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
canvas.style.opacity = opacity;
|
|
40
|
+
renderState.opacity = opacity;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// adjust view parameters in mapbox
|
|
44
|
+
const { rotation } = viewState;
|
|
45
|
+
if (renderState && renderState.rotation !== rotation) {
|
|
46
|
+
mbMap.rotateTo((-(rotation || 0) * 180) / Math.PI, {
|
|
47
|
+
animate: false,
|
|
48
|
+
});
|
|
49
|
+
changed = true;
|
|
50
|
+
renderState.rotation = rotation;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (
|
|
54
|
+
renderState &&
|
|
55
|
+
renderState.center &&
|
|
56
|
+
(renderState.zoom !== viewState.zoom ||
|
|
57
|
+
renderState.center[0] !== viewState.center[0] ||
|
|
58
|
+
renderState.center[1] !== viewState.center[1])
|
|
59
|
+
) {
|
|
60
|
+
mbMap.jumpTo({
|
|
61
|
+
center: toLonLat(viewState.center) as [number, number],
|
|
62
|
+
zoom: viewState.zoom - 1,
|
|
63
|
+
});
|
|
64
|
+
changed = true;
|
|
65
|
+
renderState.zoom = viewState.zoom;
|
|
66
|
+
renderState.center = viewState.center;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const size = map.getSize() || [0, 0];
|
|
70
|
+
if (
|
|
71
|
+
renderState &&
|
|
72
|
+
renderState.size &&
|
|
73
|
+
(renderState.size[0] !== size[0] || renderState.size[1] !== size[1])
|
|
74
|
+
) {
|
|
75
|
+
changed = true;
|
|
76
|
+
renderState.size = size;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// cancel the scheduled update & trigger synchronous redraw
|
|
80
|
+
// see https://github.com/mapbox/mapbox-gl-js/issues/7893#issue-408992184
|
|
81
|
+
// NOTE: THIS MIGHT BREAK WHEN UPDATING MAPBOX
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
if (mbMap && mbMap.style && mbMap.isStyleLoaded() && changed) {
|
|
84
|
+
try {
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
if (mbMap._frame) {
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
mbMap._frame.cancel();
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
mbMap._frame = null;
|
|
91
|
+
}
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
mbMap._render();
|
|
94
|
+
} catch (err) {
|
|
95
|
+
// ignore render errors because it's probably related to
|
|
96
|
+
// a render during an update of the style.
|
|
97
|
+
// eslint-disable-next-line no-console
|
|
98
|
+
console.warn(err);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return mbMap.getContainer();
|
|
103
|
+
};
|
|
104
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { toLonLat } from 'ol/proj';
|
|
2
|
+
import { toDegrees } from 'ol/math';
|
|
3
|
+
import type { FrameState } from 'ol/Map';
|
|
4
|
+
import type { RenderFunction } from 'ol/layer/Layer';
|
|
5
|
+
import type { MaplibreLayer } from '../../ol';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Return the render function fo the olLayer of a MaplibreLayer
|
|
9
|
+
* @private
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export default function getMaplibreRender(
|
|
14
|
+
maplibreLayer: MaplibreLayer,
|
|
15
|
+
): RenderFunction {
|
|
16
|
+
let emptyDiv: HTMLElement;
|
|
17
|
+
return (frameState: FrameState) => {
|
|
18
|
+
const { map, mbMap, olLayer } = maplibreLayer;
|
|
19
|
+
if (!map || !mbMap) {
|
|
20
|
+
if (!emptyDiv) {
|
|
21
|
+
emptyDiv = document.createElement('div');
|
|
22
|
+
}
|
|
23
|
+
return emptyDiv;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const canvas = mbMap.getCanvas();
|
|
27
|
+
const { viewState } = frameState;
|
|
28
|
+
|
|
29
|
+
const opacity = olLayer?.getOpacity() || 1;
|
|
30
|
+
canvas.style.opacity = `${opacity}`;
|
|
31
|
+
|
|
32
|
+
// adjust view parameters in mapbox
|
|
33
|
+
mbMap.jumpTo({
|
|
34
|
+
center: toLonLat(viewState.center) as [number, number],
|
|
35
|
+
zoom: viewState.zoom - 1,
|
|
36
|
+
bearing: toDegrees(-viewState.rotation),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (!canvas.isConnected) {
|
|
40
|
+
// The canvas is not connected to the DOM, request a map rendering at the next animation frame
|
|
41
|
+
// to set the canvas size.
|
|
42
|
+
map.render();
|
|
43
|
+
} else if (
|
|
44
|
+
canvas.width !== frameState.size[0] ||
|
|
45
|
+
canvas.height !== frameState.size[1]
|
|
46
|
+
) {
|
|
47
|
+
mbMap.resize();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
mbMap.redraw();
|
|
51
|
+
|
|
52
|
+
return mbMap.getContainer();
|
|
53
|
+
};
|
|
54
|
+
}
|
package/{common/utils/getRealtimeModeSuffix.d.ts → src/common/utils/getRealtimeModeSuffix.ts}
RENAMED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { RealtimeMode } from '../../types';
|
|
2
2
|
import type { RealtimeModesType } from '../../api/RealtimeAPI';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Get the websocket channel suffix, depending on the current mode.
|
|
5
6
|
* @param {String} mode Mode 'topographic' ou 'schematic'.
|
|
6
7
|
* @private
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
+
const getModeSuffix = (mode: RealtimeMode, modes: RealtimeModesType): string =>
|
|
10
|
+
mode === modes.SCHEMATIC ? '_schematic' : '';
|
|
11
|
+
|
|
9
12
|
export default getModeSuffix;
|
|
10
|
-
//# sourceMappingURL=getRealtimeModeSuffix.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Return the styleUrl with apiKey parameters set.
|
|
3
|
+
* @param {string} url a url.
|
|
4
|
+
* @param {Object<String,String>} params a list of key/value pair to add to the url.
|
|
5
|
+
* @private
|
|
6
|
+
*/
|
|
7
|
+
const getUrlWithParams = (url: string, params: Object): URL => {
|
|
8
|
+
// Clean requets parameters, removing undefined and null values.
|
|
9
|
+
const newUrl = new URL(url);
|
|
10
|
+
|
|
11
|
+
const searchParams = params || {};
|
|
12
|
+
Object.entries(searchParams).forEach(([key, value]) => {
|
|
13
|
+
if (value !== undefined && value !== null) {
|
|
14
|
+
newUrl.searchParams.set(key, value);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return newUrl;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default getUrlWithParams;
|