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,258 @@
|
|
|
1
|
+
import OlMap from 'ol/Map';
|
|
2
|
+
import View from 'ol/View';
|
|
3
|
+
import gllib from 'maplibre-gl';
|
|
4
|
+
import Layer from './Layer';
|
|
5
|
+
import MaplibreLayer from './MaplibreLayer';
|
|
6
|
+
import MapboxStyleLayer from './MapboxStyleLayer';
|
|
7
|
+
|
|
8
|
+
let source;
|
|
9
|
+
let layer;
|
|
10
|
+
let map;
|
|
11
|
+
let onClick;
|
|
12
|
+
|
|
13
|
+
const styleLayer = {
|
|
14
|
+
id: 'layer',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
describe('MapboxStyleLayer', () => {
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
onClick = jest.fn();
|
|
20
|
+
source = new MaplibreLayer({
|
|
21
|
+
name: 'Layer',
|
|
22
|
+
apiKey: 'foo',
|
|
23
|
+
url: 'https://foo.com/styles',
|
|
24
|
+
});
|
|
25
|
+
layer = new MapboxStyleLayer({
|
|
26
|
+
name: 'mapbox layer',
|
|
27
|
+
visible: true,
|
|
28
|
+
mapboxLayer: source,
|
|
29
|
+
styleLayer,
|
|
30
|
+
onClick,
|
|
31
|
+
});
|
|
32
|
+
map = new OlMap({
|
|
33
|
+
target: document.createElement('div'),
|
|
34
|
+
view: new View({ center: [0, 0] }),
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
afterEach(() => {
|
|
39
|
+
if (layer.map) {
|
|
40
|
+
layer.detachFromMap(map);
|
|
41
|
+
}
|
|
42
|
+
if (source.map) {
|
|
43
|
+
source.detachFromMap(map);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('should be instanced.', () => {
|
|
48
|
+
expect(layer).toBeInstanceOf(MapboxStyleLayer);
|
|
49
|
+
expect(layer.styleLayers[0]).toBe(styleLayer);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('should not initalized mapbox map.', () => {
|
|
53
|
+
layer.attachToMap();
|
|
54
|
+
expect(layer.mbMap).toBe();
|
|
55
|
+
layer.detachFromMap();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('should initalized mapbox map.', () => {
|
|
59
|
+
source.attachToMap(map);
|
|
60
|
+
layer.attachToMap(map);
|
|
61
|
+
expect(layer.mapboxLayer.mbMap).toBeInstanceOf(gllib.Map);
|
|
62
|
+
layer.detachFromMap();
|
|
63
|
+
source.detachFromMap();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('should called terminate on initalization.', () => {
|
|
67
|
+
const spy = jest.spyOn(layer, 'detachFromMap');
|
|
68
|
+
layer.attachToMap();
|
|
69
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
70
|
+
layer.detachFromMap(map);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('should return coordinates, features and a layer instance.', async () => {
|
|
74
|
+
source.attachToMap(map);
|
|
75
|
+
layer.attachToMap(map);
|
|
76
|
+
const data = await layer.getFeatureInfoAtCoordinate([50, 50]);
|
|
77
|
+
expect(data.coordinate).toEqual([50, 50]);
|
|
78
|
+
expect(data.features).toEqual([]);
|
|
79
|
+
expect(data.layer).toBeInstanceOf(MapboxStyleLayer);
|
|
80
|
+
layer.detachFromMap(map);
|
|
81
|
+
source.detachFromMap(map);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('should call onClick callback', async () => {
|
|
85
|
+
const coordinate = [500, 500];
|
|
86
|
+
const features = [];
|
|
87
|
+
const evt = { type: 'singleclick', map, coordinate };
|
|
88
|
+
layer.attachToMap(map);
|
|
89
|
+
expect(onClick).toHaveBeenCalledTimes(0);
|
|
90
|
+
await map.dispatchEvent(evt);
|
|
91
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
92
|
+
expect(onClick.mock.calls[0][0]).toEqual(features);
|
|
93
|
+
expect(onClick.mock.calls[0][1]).toBe(layer);
|
|
94
|
+
expect(onClick.mock.calls[0][2]).toBe(coordinate);
|
|
95
|
+
layer.detachFromMap();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('should call super class terminate function.', () => {
|
|
99
|
+
layer.attachToMap(map);
|
|
100
|
+
const spy = jest.spyOn(Layer.prototype, 'detachFromMap');
|
|
101
|
+
layer.detachFromMap(map);
|
|
102
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
103
|
+
spy.mockRestore();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('should call super class terminate if the mapboxLayer associated has been terminated before.', () => {
|
|
107
|
+
layer.attachToMap(map);
|
|
108
|
+
source.detachFromMap(map);
|
|
109
|
+
const spy = jest.spyOn(Layer.prototype, 'detachFromMap');
|
|
110
|
+
layer.detachFromMap(map);
|
|
111
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
112
|
+
spy.mockRestore();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('should clone', () => {
|
|
116
|
+
const clone = layer.clone({ name: 'clone' });
|
|
117
|
+
expect(clone).not.toBe(layer);
|
|
118
|
+
expect(clone.name).toBe('clone');
|
|
119
|
+
expect(clone).toBeInstanceOf(MapboxStyleLayer);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('should add layer on load', () => {
|
|
123
|
+
const style = { layers: [] };
|
|
124
|
+
layer.mapboxLayer.mbMap = {
|
|
125
|
+
getStyle: () => style,
|
|
126
|
+
getSource: () => ({}),
|
|
127
|
+
getLayer: () => null,
|
|
128
|
+
setLayoutProperty: () => null,
|
|
129
|
+
addLayer: (styleLayerr) => style.layers.push(styleLayerr),
|
|
130
|
+
};
|
|
131
|
+
layer.onLoad();
|
|
132
|
+
expect(style.layers[0]).toBe(styleLayer);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe('should set disabled property to false on load', () => {
|
|
136
|
+
test('when layer uses styleLayer property', () => {
|
|
137
|
+
const styles = { layers: [] };
|
|
138
|
+
layer.mapboxLayer.mbMap = {
|
|
139
|
+
getStyle: () => styles,
|
|
140
|
+
getSource: () => ({}),
|
|
141
|
+
getLayer: () => null,
|
|
142
|
+
setLayoutProperty: () => null,
|
|
143
|
+
addLayer: (styleLayerr) => styles.layers.push(styleLayerr),
|
|
144
|
+
};
|
|
145
|
+
expect(layer).toBeInstanceOf(MapboxStyleLayer);
|
|
146
|
+
layer.onLoad();
|
|
147
|
+
expect(layer.disabled).toBe(false);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe('should set disabled property to true on load', () => {
|
|
152
|
+
test('when layer uses styleLayersFilter property', () => {
|
|
153
|
+
const styles = { layers: [styleLayer] };
|
|
154
|
+
const layer2 = new MapboxStyleLayer({
|
|
155
|
+
name: 'mapbox layer',
|
|
156
|
+
mapboxLayer: source,
|
|
157
|
+
styleLayersFilter: () => false,
|
|
158
|
+
});
|
|
159
|
+
layer2.mapboxLayer.mbMap = {
|
|
160
|
+
getStyle: () => styles,
|
|
161
|
+
getSource: () => ({}),
|
|
162
|
+
getLayer: () => null,
|
|
163
|
+
setLayoutProperty: () => null,
|
|
164
|
+
addLayer: () => ({}),
|
|
165
|
+
};
|
|
166
|
+
layer2.onLoad();
|
|
167
|
+
expect(layer2.disabled).toBe(true);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe('#getFeatureInfoAtCoordinate()', () => {
|
|
172
|
+
beforeEach(() => {
|
|
173
|
+
source.attachToMap(map);
|
|
174
|
+
source.mbMap.isStyleLoaded = jest.fn(() => true);
|
|
175
|
+
source.mbMap.getSource = jest.fn(() => true);
|
|
176
|
+
});
|
|
177
|
+
afterEach(() => {
|
|
178
|
+
source.mbMap.getSource.mockRestore();
|
|
179
|
+
source.mbMap.isStyleLoaded.mockRestore();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('should request features on layers ids from styleLayers property', () => {
|
|
183
|
+
source.mbMap.getStyle = jest.fn(() => ({
|
|
184
|
+
layers: [{ id: 'foo' }, { id: 'layer' }, { id: 'bar' }],
|
|
185
|
+
}));
|
|
186
|
+
layer.attachToMap(map);
|
|
187
|
+
layer.mapboxLayer.getFeatureInfoAtCoordinate = jest.fn(() =>
|
|
188
|
+
Promise.resolve({ features: [] }),
|
|
189
|
+
);
|
|
190
|
+
layer.getFeatureInfoAtCoordinate([0, 0]).then(() => {});
|
|
191
|
+
expect(layer.mapboxLayer.getFeatureInfoAtCoordinate).toHaveBeenCalledWith(
|
|
192
|
+
[0, 0],
|
|
193
|
+
{ layers: ['layer'], validate: false },
|
|
194
|
+
);
|
|
195
|
+
layer.mapboxLayer.getFeatureInfoAtCoordinate.mockRestore();
|
|
196
|
+
source.mbMap.getStyle.mockRestore();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('should request features on layers ids from styleLayersFilter property', () => {
|
|
200
|
+
source.mbMap.getStyle = jest.fn(() => ({
|
|
201
|
+
layers: [{ id: 'foo' }, { id: 'layer' }, { id: 'bar' }, { id: 'foo2' }],
|
|
202
|
+
}));
|
|
203
|
+
const layer2 = new MapboxStyleLayer({
|
|
204
|
+
name: 'mapbox layer',
|
|
205
|
+
visible: true,
|
|
206
|
+
mapboxLayer: source,
|
|
207
|
+
styleLayer,
|
|
208
|
+
styleLayersFilter: ({ id }) => /foo/.test(id),
|
|
209
|
+
});
|
|
210
|
+
layer2.attachToMap(map);
|
|
211
|
+
layer2.mapboxLayer.getFeatureInfoAtCoordinate = jest.fn(() =>
|
|
212
|
+
Promise.resolve({ features: [] }),
|
|
213
|
+
);
|
|
214
|
+
layer2.getFeatureInfoAtCoordinate([0, 0]).then(() => {});
|
|
215
|
+
expect(
|
|
216
|
+
layer2.mapboxLayer.getFeatureInfoAtCoordinate,
|
|
217
|
+
).toHaveBeenCalledWith([0, 0], {
|
|
218
|
+
layers: ['foo', 'foo2'],
|
|
219
|
+
validate: false,
|
|
220
|
+
});
|
|
221
|
+
layer2.mapboxLayer.getFeatureInfoAtCoordinate.mockRestore();
|
|
222
|
+
source.mbMap.getStyle.mockRestore();
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test('should request features on layers ids from queryRenderedLayersFilter property', () => {
|
|
226
|
+
source.mbMap.getStyle = jest.fn(() => ({
|
|
227
|
+
layers: [
|
|
228
|
+
{ id: 'foo' },
|
|
229
|
+
{ id: 'bar2' },
|
|
230
|
+
{ id: 'layer' },
|
|
231
|
+
{ id: 'bar' },
|
|
232
|
+
{ id: 'foo2' },
|
|
233
|
+
],
|
|
234
|
+
}));
|
|
235
|
+
const layer2 = new MapboxStyleLayer({
|
|
236
|
+
name: 'mapbox layer',
|
|
237
|
+
visible: true,
|
|
238
|
+
mapboxLayer: source,
|
|
239
|
+
styleLayer,
|
|
240
|
+
styleLayersFilter: ({ id }) => /foo/.test(id),
|
|
241
|
+
queryRenderedLayersFilter: ({ id }) => /bar/.test(id),
|
|
242
|
+
});
|
|
243
|
+
layer2.attachToMap(map);
|
|
244
|
+
layer2.mapboxLayer.getFeatureInfoAtCoordinate = jest.fn(() =>
|
|
245
|
+
Promise.resolve({ features: [] }),
|
|
246
|
+
);
|
|
247
|
+
layer2.getFeatureInfoAtCoordinate([0, 0]).then(() => {});
|
|
248
|
+
expect(
|
|
249
|
+
layer2.mapboxLayer.getFeatureInfoAtCoordinate,
|
|
250
|
+
).toHaveBeenCalledWith([0, 0], {
|
|
251
|
+
layers: ['bar2', 'bar'],
|
|
252
|
+
validate: false,
|
|
253
|
+
});
|
|
254
|
+
layer2.mapboxLayer.getFeatureInfoAtCoordinate.mockRestore();
|
|
255
|
+
source.mbMap.getStyle.mockRestore();
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
});
|
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
2
|
+
import { Feature, Map } from 'ol';
|
|
3
|
+
import { Coordinate } from 'ol/coordinate';
|
|
4
|
+
import { ObjectEvent } from 'ol/Object';
|
|
5
|
+
import { feature } from 'topojson-client';
|
|
6
|
+
import { AnyMapboxLayer, LayerGetFeatureInfoResponse } from '../../types';
|
|
7
|
+
import Layer, { OlLayerOptions } from './Layer';
|
|
8
|
+
import { FilterFunction } from '../../common/typedefs';
|
|
9
|
+
|
|
10
|
+
export type MapboxStyleLayerOptions = OlLayerOptions & {
|
|
11
|
+
beforeId?: string;
|
|
12
|
+
mapboxLayer?: AnyMapboxLayer;
|
|
13
|
+
styleLayer?: { [key: string]: any };
|
|
14
|
+
styleLayers?: { [key: string]: any }[];
|
|
15
|
+
styleLayersFilter?: FilterFunction;
|
|
16
|
+
filters?: FilterFunction | { [key: string]: any }[];
|
|
17
|
+
queryRenderedLayersFilter?: FilterFunction;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type StyleLayer = {
|
|
21
|
+
id?: string;
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Layer for visualizing a specific set of layer from a MapboxLayer.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* import { MapboxLayer, MapboxStyleLayer } from 'mobility-toolbox-js/ol';
|
|
30
|
+
*
|
|
31
|
+
* const mapboxLayer = new MapboxLayer({
|
|
32
|
+
* url: 'https://maps.geops.io/styles/travic_v2/style.json?key=[yourApiKey]',
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* const layer = new MapboxStyleLayer({
|
|
36
|
+
* mapboxLayer: mapboxLayer,
|
|
37
|
+
* styleLayersFilter: () => {},
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
41
|
+
* @extends {Layer}
|
|
42
|
+
*/
|
|
43
|
+
class MapboxStyleLayer extends Layer {
|
|
44
|
+
beforeId?: string;
|
|
45
|
+
|
|
46
|
+
mapboxLayer?: AnyMapboxLayer;
|
|
47
|
+
|
|
48
|
+
styleLayersFilter?: FilterFunction;
|
|
49
|
+
|
|
50
|
+
queryRenderedLayersFilter?: FilterFunction;
|
|
51
|
+
|
|
52
|
+
selectedFeatures?: Feature[];
|
|
53
|
+
|
|
54
|
+
highlightedFeatures?: Feature[];
|
|
55
|
+
|
|
56
|
+
styleLayer?: StyleLayer;
|
|
57
|
+
|
|
58
|
+
styleLayers: StyleLayer[];
|
|
59
|
+
|
|
60
|
+
addDynamicFilters?: () => void;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Constructor.
|
|
64
|
+
*
|
|
65
|
+
* @param {Object} options
|
|
66
|
+
* @param {MapboxLayer} [options.mapboxLayer] The MapboxLayer to use.
|
|
67
|
+
* @param {Function} [options.styleLayersFilter] Filter function to decide which style layer to display.
|
|
68
|
+
*/
|
|
69
|
+
constructor(options: MapboxStyleLayerOptions) {
|
|
70
|
+
super(options);
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* MapboxLayer provided for the style Layer.
|
|
74
|
+
* @type {MapboxLayer}
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
this.mapboxLayer = options.mapboxLayer;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Define if the layer has data to display in the current mapbox layer.
|
|
81
|
+
*/
|
|
82
|
+
this.disabled = false;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Function to filter features to be displayed.
|
|
86
|
+
* @type {function}
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
89
|
+
this.styleLayersFilter = options.styleLayersFilter;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Mapbox style layer id where to add the style layers.
|
|
93
|
+
* See [mapbox.map.addLayer](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#addlayer) documentation.
|
|
94
|
+
* @type {String}
|
|
95
|
+
* @private
|
|
96
|
+
*/
|
|
97
|
+
this.beforeId = options.beforeId;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Function to query the rendered features.
|
|
101
|
+
* @type {function}
|
|
102
|
+
* @private
|
|
103
|
+
*/
|
|
104
|
+
this.queryRenderedLayersFilter = options.queryRenderedLayersFilter;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Array of features to highlight.
|
|
108
|
+
* @type {Array<ol/Feature~Feature>}
|
|
109
|
+
* @private
|
|
110
|
+
*/
|
|
111
|
+
this.highlightedFeatures = [];
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Array of selected features.
|
|
115
|
+
* @type {Array<ol/Feature~Feature>}
|
|
116
|
+
* @private
|
|
117
|
+
*/
|
|
118
|
+
this.selectedFeatures = [];
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Array of mapbox style layers to add.
|
|
122
|
+
* @type {Array<mapboxgl.styleLayer>}
|
|
123
|
+
* @private
|
|
124
|
+
*/
|
|
125
|
+
this.styleLayers =
|
|
126
|
+
(options.styleLayer ? [options.styleLayer] : options.styleLayers) || [];
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @private
|
|
130
|
+
*/
|
|
131
|
+
this.addStyleLayers = this.addStyleLayers.bind(this);
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @private
|
|
135
|
+
*/
|
|
136
|
+
this.onLoad = this.onLoad.bind(this);
|
|
137
|
+
if (options.filters) {
|
|
138
|
+
/** @private */
|
|
139
|
+
this.addDynamicFilters = () => {
|
|
140
|
+
this.setFilter(
|
|
141
|
+
typeof options.filters === 'function'
|
|
142
|
+
? options.filters(this)
|
|
143
|
+
: options.filters,
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (!this.styleLayersFilter && this.styleLayers) {
|
|
149
|
+
this.styleLayersFilter = (styleLayer: StyleLayer) => {
|
|
150
|
+
return !!this.styleLayers?.find((sl) => styleLayer.id === sl.id);
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Initialize the layer.
|
|
157
|
+
* @param {ol/Map~Map} map the mapbox map.
|
|
158
|
+
* @override
|
|
159
|
+
*/
|
|
160
|
+
attachToMap(map: Map) {
|
|
161
|
+
if (this.mapboxLayer && !this.mapboxLayer.map) {
|
|
162
|
+
this.mapboxLayer?.attachToMap(map);
|
|
163
|
+
}
|
|
164
|
+
super.attachToMap(map);
|
|
165
|
+
|
|
166
|
+
if (!this.map || !this.mapboxLayer) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Apply the initial visibiltity.
|
|
171
|
+
const { mbMap } = this.mapboxLayer;
|
|
172
|
+
if (!mbMap) {
|
|
173
|
+
// If the mbMap is not yet created because the map has no target yet, we
|
|
174
|
+
// relaunch the initialisation when it's the case.
|
|
175
|
+
this.olListenersKeys.push(
|
|
176
|
+
this.map.on('change:target', () => {
|
|
177
|
+
this.attachToMap(map);
|
|
178
|
+
}),
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// mbMap.loaded() and mbMap.isStyleLoaded() are reliable only on the first call of init.
|
|
185
|
+
// On the next call (when a topic change for example), these functions returns false because
|
|
186
|
+
// the style is being modified.
|
|
187
|
+
// That's why we rely on a property instead for the next calls.
|
|
188
|
+
if (this.mapboxLayer.loaded || mbMap.isStyleLoaded() || mbMap.loaded()) {
|
|
189
|
+
this.onLoad();
|
|
190
|
+
} else {
|
|
191
|
+
mbMap.once('load', this.onLoad);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Apply the visibiltity when layer's visibility change.
|
|
195
|
+
this.olListenersKeys.push(
|
|
196
|
+
// @ts-ignore
|
|
197
|
+
this.on('change:visible', (evt) => {
|
|
198
|
+
// Once the map is loaded we can apply visiblity without waiting
|
|
199
|
+
// the style. Mapbox take care of the application of style changes.
|
|
200
|
+
this.applyLayoutVisibility(evt);
|
|
201
|
+
}),
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
this.olListenersKeys.push(
|
|
205
|
+
// @ts-ignore
|
|
206
|
+
this.mapboxLayer.on('load', () => {
|
|
207
|
+
this.onLoad();
|
|
208
|
+
}),
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Terminate the layer.
|
|
214
|
+
* @override
|
|
215
|
+
*/
|
|
216
|
+
detachFromMap() {
|
|
217
|
+
if (this.mapboxLayer?.mbMap) {
|
|
218
|
+
const { mbMap } = this.mapboxLayer;
|
|
219
|
+
mbMap.off('load', this.onLoad);
|
|
220
|
+
this.removeStyleLayers();
|
|
221
|
+
}
|
|
222
|
+
super.detachFromMap();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** @private */
|
|
226
|
+
addStyleLayers() {
|
|
227
|
+
if (!this.mapboxLayer?.mbMap) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const { mbMap } = this.mapboxLayer;
|
|
231
|
+
|
|
232
|
+
this.styleLayers.forEach((styleLayer) => {
|
|
233
|
+
const { id, source } = styleLayer;
|
|
234
|
+
if (mbMap.getSource(source) && id && !mbMap.getLayer(id)) {
|
|
235
|
+
// @ts-ignore
|
|
236
|
+
mbMap.addLayer(styleLayer, this.beforeId);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
this.applyLayoutVisibility();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** @private */
|
|
243
|
+
removeStyleLayers() {
|
|
244
|
+
if (!this.mapboxLayer?.mbMap) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const { mbMap } = this.mapboxLayer;
|
|
248
|
+
|
|
249
|
+
this.styleLayers.forEach((styleLayer) => {
|
|
250
|
+
const { id } = styleLayer;
|
|
251
|
+
if (id && mbMap.getLayer(id)) {
|
|
252
|
+
mbMap.removeLayer(id);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* On Mapbox map load callback function. Add style layers and dynaimc filters.
|
|
259
|
+
* @private
|
|
260
|
+
*/
|
|
261
|
+
onLoad() {
|
|
262
|
+
this.addStyleLayers();
|
|
263
|
+
|
|
264
|
+
if (this.addDynamicFilters) {
|
|
265
|
+
this.addDynamicFilters();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (!this.mapboxLayer?.mbMap) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const { mbMap } = this.mapboxLayer;
|
|
272
|
+
const style = mbMap.getStyle();
|
|
273
|
+
if (style && this.styleLayersFilter) {
|
|
274
|
+
// @ts-ignore
|
|
275
|
+
const styles = style.layers.filter(this.styleLayersFilter);
|
|
276
|
+
this.disabled = !styles.length;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Request feature information for a given coordinate.
|
|
282
|
+
* @param {ol/coordinate~Coordinate} coordinate Coordinate to request the information at.
|
|
283
|
+
* @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
|
|
284
|
+
*/
|
|
285
|
+
getFeatureInfoAtCoordinate(
|
|
286
|
+
coordinate: Coordinate,
|
|
287
|
+
): Promise<LayerGetFeatureInfoResponse> {
|
|
288
|
+
if (!this.mapboxLayer?.mbMap) {
|
|
289
|
+
return Promise.resolve({ coordinate, features: [], layer: this });
|
|
290
|
+
}
|
|
291
|
+
const { mbMap } = this.mapboxLayer;
|
|
292
|
+
|
|
293
|
+
// Ignore the getFeatureInfo until the mapbox map is loaded
|
|
294
|
+
if (!mbMap.isStyleLoaded()) {
|
|
295
|
+
return Promise.resolve({ coordinate, features: [], layer: this });
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// We query features only on style layers used by this layer.
|
|
299
|
+
let layers = this.styleLayers || [];
|
|
300
|
+
|
|
301
|
+
if (this.styleLayersFilter) {
|
|
302
|
+
// @ts-ignore
|
|
303
|
+
layers = mbMap.getStyle().layers.filter(this.styleLayersFilter);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (this.queryRenderedLayersFilter) {
|
|
307
|
+
// @ts-ignore
|
|
308
|
+
layers = mbMap.getStyle().layers.filter(this.queryRenderedLayersFilter);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return this.mapboxLayer.getFeatureInfoAtCoordinate(coordinate, {
|
|
312
|
+
layers: layers.map((layer) => layer && layer.id),
|
|
313
|
+
validate: false,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Set filter that determines which features should be rendered in a style layer.
|
|
319
|
+
* @param {mapboxgl.filter} filter Determines which features should be rendered in a style layer.
|
|
320
|
+
*/
|
|
321
|
+
setFilter(filter: { [key: string]: any }) {
|
|
322
|
+
if (!this.mapboxLayer?.mbMap) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const { mbMap } = this.mapboxLayer;
|
|
326
|
+
|
|
327
|
+
this.styleLayers.forEach(({ id }) => {
|
|
328
|
+
if (id && filter && mbMap.getLayer(id)) {
|
|
329
|
+
// @ts-ignore
|
|
330
|
+
mbMap.setFilter(id, filter);
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Set if features are hovered or not.
|
|
337
|
+
* @param {Array<ol/Feature~Feature>} features
|
|
338
|
+
* @param {boolean} state Is the feature hovered
|
|
339
|
+
* @private
|
|
340
|
+
*/
|
|
341
|
+
setHoverState(features: Feature[], state: boolean) {
|
|
342
|
+
if (!this.mapboxLayer?.mbMap) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
const { mbMap } = this.mapboxLayer;
|
|
346
|
+
|
|
347
|
+
if (!features || !mbMap) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
features.forEach((feature: Feature) => {
|
|
352
|
+
const { source, sourceLayer } = feature.get('mapboxFeature') || {};
|
|
353
|
+
if ((!source && !sourceLayer) || !feature.getId()) {
|
|
354
|
+
if (!feature.getId()) {
|
|
355
|
+
// eslint-disable-next-line no-console
|
|
356
|
+
console.warn(
|
|
357
|
+
"No feature's id found. To use the feature state functionnality, tiles must be generated with --generate-ids. See https://github.com/mapbox/tippecanoe#adding-calculated-attributes.",
|
|
358
|
+
feature.getId(),
|
|
359
|
+
feature.getProperties(),
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
mbMap.setFeatureState(
|
|
366
|
+
{
|
|
367
|
+
id: feature.getId(),
|
|
368
|
+
source,
|
|
369
|
+
sourceLayer,
|
|
370
|
+
},
|
|
371
|
+
{ hover: state },
|
|
372
|
+
);
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Select a list of features.
|
|
378
|
+
* @param {Array<ol/Feature~Feature>} [features=[]] Features to select.
|
|
379
|
+
* @private
|
|
380
|
+
*/
|
|
381
|
+
select(features: Feature[] = []) {
|
|
382
|
+
this.setHoverState(this.selectedFeatures || [], false);
|
|
383
|
+
this.selectedFeatures = features;
|
|
384
|
+
this.setHoverState(this.selectedFeatures || [], true);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Highlight a list of features.
|
|
389
|
+
* @param {Array<ol/Feature~Feature>} [features=[]] Features to highlight.
|
|
390
|
+
* @private
|
|
391
|
+
*/
|
|
392
|
+
highlight(features: Feature[] = []) {
|
|
393
|
+
// Filter out selected features
|
|
394
|
+
const filtered: Feature[] =
|
|
395
|
+
this.highlightedFeatures?.filter(
|
|
396
|
+
(feature) =>
|
|
397
|
+
!(this.selectedFeatures || [])
|
|
398
|
+
.map((feat: Feature) => feat.getId())
|
|
399
|
+
.includes(feature.getId()),
|
|
400
|
+
) || [];
|
|
401
|
+
|
|
402
|
+
// Remove previous highlight
|
|
403
|
+
this.setHoverState(filtered, false);
|
|
404
|
+
this.highlightedFeatures = features;
|
|
405
|
+
|
|
406
|
+
// Add highlight
|
|
407
|
+
this.setHoverState(this.highlightedFeatures, true);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Apply visibility to style layers that fits the styleLayersFilter function.
|
|
412
|
+
* @param {Event} evt Layer's event that has called the function.
|
|
413
|
+
* @private
|
|
414
|
+
*/
|
|
415
|
+
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
416
|
+
applyLayoutVisibility(evt?: ObjectEvent) {
|
|
417
|
+
const { visible } = this;
|
|
418
|
+
const filterFunc = this.styleLayersFilter;
|
|
419
|
+
|
|
420
|
+
if (!this.mapboxLayer?.mbMap) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const { mbMap } = this.mapboxLayer;
|
|
425
|
+
const style = mbMap.getStyle();
|
|
426
|
+
|
|
427
|
+
if (!style) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (filterFunc) {
|
|
432
|
+
const visibilityValue = visible ? 'visible' : 'none';
|
|
433
|
+
const layers = style.layers || [];
|
|
434
|
+
for (let i = 0; i < layers.length; i += 1) {
|
|
435
|
+
const styleLayer = layers[i];
|
|
436
|
+
if (filterFunc(styleLayer)) {
|
|
437
|
+
if (mbMap.getLayer(styleLayer.id)) {
|
|
438
|
+
mbMap.setLayoutProperty(
|
|
439
|
+
styleLayer.id,
|
|
440
|
+
'visibility',
|
|
441
|
+
visibilityValue,
|
|
442
|
+
);
|
|
443
|
+
if (this.get('minZoom') || this.get('maxZoom')) {
|
|
444
|
+
mbMap.setLayerZoomRange(
|
|
445
|
+
styleLayer.id,
|
|
446
|
+
this.get('minZoom') ? this.get('minZoom') - 1 : 0, // mapbox zoom = ol zoom - 1
|
|
447
|
+
this.get('maxZoom') ? this.get('maxZoom') - 1 : 24,
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Create a copy of the MapboxStyleLayer.
|
|
458
|
+
* @param {Object} newOptions Options to override.
|
|
459
|
+
* @return {MapboxStyleLayer} A MapboxStyleLayer.
|
|
460
|
+
*/
|
|
461
|
+
clone(newOptions: MapboxStyleLayerOptions) {
|
|
462
|
+
return new MapboxStyleLayer({ ...this.options, ...newOptions });
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export default MapboxStyleLayer;
|