mobility-toolbox-js 2.0.0-beta.8 → 2.0.1-beta.13
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/api/RoutingAPI.js +15 -0
- package/api/RoutingAPI.test.js +25 -0
- package/api/StopsAPI.js +12 -0
- package/api/StopsAPI.test.js +22 -0
- package/api/TralisAPI.js +359 -0
- package/api/TralisAPI.test.js +67 -0
- package/{src/api/tralis → api}/TralisAPIUtils.js +2 -32
- package/api/index.js +3 -0
- package/{index.html → api/typedefs.js} +0 -0
- package/common/Tracker.js +93 -0
- package/common/api/HttpAPI.js +30 -0
- package/common/api/HttpAPI.test.js +50 -0
- package/common/api/WebSocketAPI.js +175 -0
- package/{src/api/tralis/WebSocketConnector.test.js → common/api/WebSocketAPI.test.js} +100 -145
- package/common/controls/Control.js +81 -0
- package/{src/common → common}/controls/Control.test.js +32 -43
- package/common/index.js +4 -0
- package/common/layers/Layer.js +213 -0
- package/{src/common → common}/layers/Layer.test.js +185 -244
- package/common/mixins/CopyrightMixin.js +24 -0
- package/common/mixins/SearchMixin.js +110 -0
- package/common/mixins/TralisLayerMixin.js +479 -0
- package/common/styles/index.js +4 -0
- package/{src/common → common}/styles/trackerDefaultStyle.js +39 -175
- package/common/styles/trackerDelayStyle.js +8 -0
- package/{src/common → common}/styles/trackerSimpleStyle.js +4 -8
- package/{src/common → common}/trackerConfig.js +61 -99
- package/common/trackerConfig.test.js +23 -0
- package/{src/doc/examples/ol-mapbox-layer.md → common/typedefs.js} +0 -0
- package/common/utils/createTrackerFilters.js +56 -0
- package/common/utils/createTrackerFilters.test.js +79 -0
- package/{src/common → common}/utils/getMapboxMapCopyrights.js +3 -16
- package/common/utils/getMapboxMapCopyrights.test.js +40 -0
- package/{src/common → common}/utils/getMapboxStyleUrl.js +3 -13
- package/{src/common → common}/utils/getVehiclePosition.js +3 -33
- package/common/utils/index.js +5 -0
- package/common/utils/removeDuplicate.js +8 -0
- package/common/utils/removeDuplicate.test.js +19 -0
- package/{src/common → common}/utils/sortByDelay.js +2 -7
- package/common/utils/timeUtils.js +20 -0
- package/common/utils/timeUtils.test.js +10 -0
- package/index.js +8 -0
- package/mapbox/controls/CopyrightControl.js +29 -0
- package/mapbox/controls/index.js +1 -0
- package/mapbox/index.js +4 -0
- package/mapbox/layers/Layer.js +57 -0
- package/mapbox/layers/Layer.test.js +182 -0
- package/mapbox/layers/TralisLayer.js +182 -0
- package/{src/mapbox → mapbox}/layers/TralisLayer.test.js +12 -14
- package/mapbox/layers/index.js +2 -0
- package/{src/mapbox → mapbox}/utils.js +7 -21
- package/mbt.js +50444 -0
- package/mbt.js.map +7 -0
- package/mbt.min.js +1005 -0
- package/mbt.min.js.map +7 -0
- package/ol/controls/CopyrightControl.js +42 -0
- package/ol/controls/CopyrightControl.test.js +165 -0
- package/ol/controls/RoutingControl.js +387 -0
- package/ol/controls/RoutingControl.test.js +151 -0
- package/ol/controls/StopFinderControl.js +10 -0
- package/ol/controls/StopFinderControl.test.js +48 -0
- package/ol/controls/index.js +3 -0
- package/ol/index.js +5 -0
- package/ol/layers/Layer.js +88 -0
- package/ol/layers/Layer.test.js +174 -0
- package/ol/layers/MapboxLayer.js +203 -0
- package/{src/ol → ol}/layers/MapboxLayer.test.js +58 -84
- package/ol/layers/MapboxStyleLayer.js +187 -0
- package/{src/ol → ol}/layers/MapboxStyleLayer.test.js +97 -128
- package/ol/layers/MaplibreLayer.js +139 -0
- package/ol/layers/RoutingLayer.js +61 -0
- package/{src/ol → ol}/layers/RoutingLayer.test.js +15 -24
- package/ol/layers/TralisLayer.js +185 -0
- package/ol/layers/TralisLayer.test.js +79 -0
- package/ol/layers/VectorLayer.js +22 -0
- package/{src/ol → ol}/layers/VectorLayer.test.js +34 -45
- package/ol/layers/WMSLayer.js +38 -0
- package/ol/layers/WMSLayer.test.js +76 -0
- package/ol/layers/index.js +8 -0
- package/{src/ol → ol}/styles/fullTrajectoryDelayStyle.js +11 -15
- package/ol/styles/fullTrajectoryStyle.js +43 -0
- package/ol/styles/index.js +2 -0
- package/package.json +34 -74
- package/.babelrc +0 -6
- package/.esdoc.json +0 -17
- package/.eslintignore +0 -1
- package/.github/workflows/conventional-pr-title.yml +0 -21
- package/.github/workflows/cypress.yml +0 -29
- package/.github/workflows/nodejs.yml +0 -28
- package/.husky/commit-msg +0 -4
- package/.husky/post-checkout +0 -4
- package/.husky/post-merge +0 -4
- package/.husky/post-rebase +0 -4
- package/.husky/pre-commit +0 -4
- package/.neutrinorc.js +0 -176
- package/.nvmrc +0 -1
- package/CHANGELOG.md +0 -10
- package/LICENSE +0 -21
- package/__mocks__/mapbox-gl.js +0 -81
- package/__mocks__/maplibre-gl.js +0 -81
- package/commitlint.config.js +0 -1
- package/cypress/fixtures/example.json +0 -5
- package/cypress/integration/examples/api.spec.js +0 -7
- package/cypress/integration/examples/examples.spec.js +0 -7
- package/cypress/integration/examples/navigation.spec.js +0 -29
- package/cypress/plugins/index.js +0 -21
- package/cypress/support/commands.js +0 -25
- package/cypress/support/index.js +0 -20
- package/cypress.json +0 -4
- package/data/fetchRoute.json +0 -292
- package/data/fetchTrajectories.json +0 -18
- package/data/fetchTrajectoryById.json +0 -3
- package/data/fetchTrajectoryStations.json +0 -18
- package/data/stopsSearch.json +0 -15
- package/documentation.yml +0 -4
- package/esdoc/README.md +0 -27
- package/esdoc/plugins/MyPlugin.js +0 -69
- package/esdoc/plugins/dynamic-property-plugin/Plugin.js +0 -50
- package/esdoc/plugins/externals-plugin/Plugin.js +0 -45
- package/esdoc/plugins/externals-plugin/externals.js +0 -96
- package/global-setup.js +0 -3
- package/indexweb.html +0 -49
- package/jest.config.js +0 -5
- package/pull_request_template.md +0 -17
- package/renovate.json +0 -4
- package/scripts/read-pkg-json.js +0 -22
- package/src/api/index.js +0 -3
- package/src/api/routing/RoutingAPI.js +0 -44
- package/src/api/routing/RoutingAPI.test.js +0 -41
- package/src/api/stops/StopsAPI.js +0 -41
- package/src/api/stops/StopsAPI.test.js +0 -34
- package/src/api/tralis/TralisAPI.js +0 -731
- package/src/api/tralis/TralisAPI.test.js +0 -75
- package/src/api/tralis/WebSocketConnector.js +0 -338
- package/src/api/tralis/typedefs.js +0 -81
- package/src/assets/Lato-Black.ttf +0 -0
- package/src/assets/Lato-BlackItalic.ttf +0 -0
- package/src/assets/Lato-Bold.ttf +0 -0
- package/src/assets/Lato-BoldItalic.ttf +0 -0
- package/src/assets/Lato-Italic.ttf +0 -0
- package/src/assets/Lato-Light.ttf +0 -0
- package/src/assets/Lato-LightItalic.ttf +0 -0
- package/src/assets/Lato-Regular.ttf +0 -0
- package/src/assets/Lato-Thin.ttf +0 -0
- package/src/assets/Lato-ThinItalic.ttf +0 -0
- package/src/assets/OFL.txt +0 -93
- package/src/common/Tracker.js +0 -197
- package/src/common/api/api.js +0 -64
- package/src/common/api/api.test.js +0 -68
- package/src/common/controls/Control.js +0 -146
- package/src/common/index.js +0 -5
- package/src/common/layers/Layer.js +0 -404
- package/src/common/mixins/CopyrightMixin.js +0 -48
- package/src/common/mixins/SearchMixin.js +0 -176
- package/src/common/mixins/TralisLayerMixin.js +0 -930
- package/src/common/styles/index.js +0 -4
- package/src/common/styles/trackerDelayStyle.js +0 -17
- package/src/common/trackerConfig.test.js +0 -25
- package/src/common/typedefs.js +0 -23
- package/src/common/utils/createTrackerFilters.js +0 -87
- package/src/common/utils/createTrackerFilters.test.js +0 -95
- package/src/common/utils/getMapboxMapCopyrights.test.js +0 -47
- package/src/common/utils/index.js +0 -5
- package/src/common/utils/removeDuplicate.js +0 -22
- package/src/common/utils/removeDuplicate.test.js +0 -22
- package/src/common/utils/timeUtils.js +0 -44
- package/src/common/utils/timeUtils.test.js +0 -16
- package/src/doc/App.js +0 -116
- package/src/doc/App.scss +0 -51
- package/src/doc/_redirects +0 -2
- package/src/doc/components/CodeSandboxButton.js +0 -103
- package/src/doc/components/Documentation.js +0 -40
- package/src/doc/components/Esdoc/Anchor.js +0 -57
- package/src/doc/components/Esdoc/ClassDoc.js +0 -272
- package/src/doc/components/Esdoc/DeprecatedHTML.js +0 -16
- package/src/doc/components/Esdoc/DetailDocs.js +0 -281
- package/src/doc/components/Esdoc/DetailHTML.js +0 -33
- package/src/doc/components/Esdoc/DirectSubclassHTML.js +0 -30
- package/src/doc/components/Esdoc/DocBuilderUtils.js +0 -694
- package/src/doc/components/Esdoc/DocLinkHTML.js +0 -62
- package/src/doc/components/Esdoc/DocsLinkHTML.js +0 -38
- package/src/doc/components/Esdoc/Esdoc.js +0 -63
- package/src/doc/components/Esdoc/EsdocContent.js +0 -51
- package/src/doc/components/Esdoc/EsdocNavigation.js +0 -13
- package/src/doc/components/Esdoc/EsdocSearch.js +0 -81
- package/src/doc/components/Esdoc/ExperimentalHTML.js +0 -17
- package/src/doc/components/Esdoc/ExtendsChainHTML.js +0 -32
- package/src/doc/components/Esdoc/FileDocLinkHTML.js +0 -60
- package/src/doc/components/Esdoc/IdentifiersDoc.js +0 -113
- package/src/doc/components/Esdoc/IndirectSubclassHTML.js +0 -30
- package/src/doc/components/Esdoc/InheritedSummaryDoc.js +0 -70
- package/src/doc/components/Esdoc/InheritedSummaryHTML.js +0 -38
- package/src/doc/components/Esdoc/MixinClassesHTML.js +0 -29
- package/src/doc/components/Esdoc/NavDoc.js +0 -112
- package/src/doc/components/Esdoc/OverrideMethod.js +0 -44
- package/src/doc/components/Esdoc/OverrideMethodDescription.js +0 -35
- package/src/doc/components/Esdoc/Properties.js +0 -89
- package/src/doc/components/Esdoc/README.md +0 -45
- package/src/doc/components/Esdoc/SignatureHTML.js +0 -123
- package/src/doc/components/Esdoc/SingleDoc.js +0 -31
- package/src/doc/components/Esdoc/SummaryDoc.js +0 -160
- package/src/doc/components/Esdoc/SummaryHTML.js +0 -96
- package/src/doc/components/Esdoc/TypeDocLinkHTML.js +0 -249
- package/src/doc/components/Esdoc/css/identifiers.css +0 -38
- package/src/doc/components/Esdoc/css/search.css +0 -76
- package/src/doc/components/Esdoc/css/style.css +0 -603
- package/src/doc/components/Esdoc/index.js +0 -7
- package/src/doc/components/Example.js +0 -153
- package/src/doc/components/Examples.js +0 -183
- package/src/doc/components/Home.js +0 -106
- package/src/doc/components/TrackerExample.js +0 -38
- package/src/doc/examples/assets/tralis-live-map/index.js +0 -11
- package/src/doc/examples/assets/tralis-live-map/s1kreis.svg +0 -105
- package/src/doc/examples/assets/tralis-live-map/s20kreis.svg +0 -101
- package/src/doc/examples/assets/tralis-live-map/s2kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s3kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s4kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s6kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s7kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s8kreis.svg +0 -93
- package/src/doc/examples/assets/tralis-live-map/unknown.svg +0 -107
- package/src/doc/examples/mb-copyright.html +0 -26
- package/src/doc/examples/mb-copyright.js +0 -37
- package/src/doc/examples/mb-tracker.html +0 -1
- package/src/doc/examples/mb-tracker.js +0 -39
- package/src/doc/examples/mb-tracker.md +0 -1
- package/src/doc/examples/mb-tralis.html +0 -1
- package/src/doc/examples/mb-tralis.js +0 -34
- package/src/doc/examples/ol-copyright.html +0 -26
- package/src/doc/examples/ol-copyright.js +0 -43
- package/src/doc/examples/ol-mapbox-layer.html +0 -1
- package/src/doc/examples/ol-mapbox-layer.js +0 -28
- package/src/doc/examples/ol-mapbox-style-layer.html +0 -12
- package/src/doc/examples/ol-mapbox-style-layer.js +0 -44
- package/src/doc/examples/ol-query.html +0 -32
- package/src/doc/examples/ol-query.js +0 -83
- package/src/doc/examples/ol-routing.html +0 -26
- package/src/doc/examples/ol-routing.js +0 -59
- package/src/doc/examples/ol-routing.md +0 -1
- package/src/doc/examples/ol-stop-finder.html +0 -15
- package/src/doc/examples/ol-stop-finder.js +0 -31
- package/src/doc/examples/ol-stop-finder.md +0 -1
- package/src/doc/examples/ol-tracker.html +0 -1
- package/src/doc/examples/ol-tracker.js +0 -44
- package/src/doc/examples/ol-tracker.md +0 -1
- package/src/doc/examples/ol-tralis.html +0 -5
- package/src/doc/examples/ol-tralis.js +0 -57
- package/src/doc/examples/tralis-live-map.html +0 -1
- package/src/doc/examples/tralis-live-map.js +0 -51
- package/src/doc/examples/tralis-live-map.md +0 -3
- package/src/doc/examples.js +0 -107
- package/src/doc/img/examples/live_tracker_mb.jpg +0 -0
- package/src/doc/img/examples/live_tracker_munich.jpg +0 -0
- package/src/doc/img/examples/live_tracker_ol.jpg +0 -0
- package/src/doc/img/examples/mapbox.jpg +0 -0
- package/src/doc/img/examples/mapbox_style.jpg +0 -0
- package/src/doc/img/examples/ol-copyright.png +0 -0
- package/src/doc/img/examples/query_objects.jpg +0 -0
- package/src/doc/img/examples/routing.jpg +0 -0
- package/src/doc/img/examples/simple_map.jpg +0 -0
- package/src/doc/img/examples/stops.jpg +0 -0
- package/src/doc/img/favico.ico +0 -0
- package/src/doc/index.js +0 -21
- package/src/iife.js +0 -7
- package/src/index.js +0 -10
- package/src/mapbox/controls/CopyrightControl.js +0 -58
- package/src/mapbox/controls/index.js +0 -2
- package/src/mapbox/index.js +0 -4
- package/src/mapbox/layers/Layer.js +0 -118
- package/src/mapbox/layers/Layer.test.js +0 -202
- package/src/mapbox/layers/TralisLayer.js +0 -329
- package/src/mapbox/layers/index.js +0 -2
- package/src/ol/README.md +0 -0
- package/src/ol/controls/CopyrightControl.js +0 -80
- package/src/ol/controls/CopyrightControl.test.js +0 -211
- package/src/ol/controls/RoutingControl.js +0 -752
- package/src/ol/controls/RoutingControl.test.js +0 -216
- package/src/ol/controls/StopFinderControl.js +0 -38
- package/src/ol/controls/StopFinderControl.test.js +0 -59
- package/src/ol/controls/index.js +0 -3
- package/src/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
- package/src/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
- package/src/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
- package/src/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
- package/src/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
- package/src/ol/controls/snapshots/RoutingControlStation1.json +0 -60
- package/src/ol/controls/snapshots/RoutingControlStation2.json +0 -49
- package/src/ol/index.js +0 -5
- package/src/ol/layers/Layer.js +0 -193
- package/src/ol/layers/Layer.test.js +0 -197
- package/src/ol/layers/MapboxLayer.js +0 -378
- package/src/ol/layers/MapboxStyleLayer.js +0 -417
- package/src/ol/layers/MaplibreLayer.js +0 -280
- package/src/ol/layers/RoutingLayer.js +0 -91
- package/src/ol/layers/TralisLayer.js +0 -359
- package/src/ol/layers/TralisLayer.test.js +0 -97
- package/src/ol/layers/VectorLayer.js +0 -43
- package/src/ol/layers/WMSLayer.js +0 -80
- package/src/ol/layers/WMSLayer.test.js +0 -84
- package/src/ol/layers/index.js +0 -8
- package/src/ol/styles/fullTrajectoryStyle.js +0 -51
- package/src/ol/styles/index.js +0 -2
- package/src/setupTests.js +0 -15
- package/webpack.config.js +0 -6
|
@@ -1,417 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-param-reassign */
|
|
2
|
-
import Layer from './Layer';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Layer for visualizing a specific set of layer from a MapboxLayer.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* import { MapboxLayer, MapboxStyleLayer } from 'mobility-toolbox-js/ol';
|
|
9
|
-
*
|
|
10
|
-
* const mapboxLayer = new MapboxLayer({
|
|
11
|
-
* url: 'https://maps.geops.io/styles/travic_v2/style.json?key=[yourApiKey]',
|
|
12
|
-
* });
|
|
13
|
-
*
|
|
14
|
-
* const layer = new MapboxStyleLayer({
|
|
15
|
-
* mapboxLayer: mapboxLayer,
|
|
16
|
-
* styleLayersFilter: () => {},
|
|
17
|
-
* });
|
|
18
|
-
*
|
|
19
|
-
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
20
|
-
* @extends {Layer}
|
|
21
|
-
*/
|
|
22
|
-
class MapboxStyleLayer extends Layer {
|
|
23
|
-
/**
|
|
24
|
-
* Constructor.
|
|
25
|
-
*
|
|
26
|
-
* @param {Object} options
|
|
27
|
-
* @param {MapboxLayer} [options.mapboxLayer] The MapboxLayer to use.
|
|
28
|
-
* @param {Function} [options.styleLayersFilter] Filter function to decide which style layer to display.
|
|
29
|
-
*/
|
|
30
|
-
constructor(options = {}) {
|
|
31
|
-
super(options);
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* MapboxLayer provided for the style Layer.
|
|
35
|
-
* @type {MapboxLayer}
|
|
36
|
-
* @private
|
|
37
|
-
*/
|
|
38
|
-
this.mapboxLayer = options.mapboxLayer;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Define if the layer has data to display in the current mapbox layer.
|
|
42
|
-
*/
|
|
43
|
-
this.disabled = false;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Function to filter features to be displayed.
|
|
47
|
-
* @type {function}
|
|
48
|
-
* @private
|
|
49
|
-
*/
|
|
50
|
-
this.styleLayersFilter = options.styleLayersFilter;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Mapbox style layer id where to add the style layers.
|
|
54
|
-
* See [mapbox.map.addLayer](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#addlayer) documentation.
|
|
55
|
-
* @type {String}
|
|
56
|
-
* @private
|
|
57
|
-
*/
|
|
58
|
-
this.beforeId = options.beforeId;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Function to filter features for getFeatureInfoAtCoordinate method.
|
|
62
|
-
* @type {function}
|
|
63
|
-
* @private
|
|
64
|
-
*/
|
|
65
|
-
this.featureInfoFilter = options.featureInfoFilter || ((obj) => obj);
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Function to query the rendered features.
|
|
69
|
-
* @type {function}
|
|
70
|
-
* @private
|
|
71
|
-
*/
|
|
72
|
-
this.queryRenderedLayersFilter = options.queryRenderedLayersFilter;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Array of features to highlight.
|
|
76
|
-
* @type {Array<ol/Feature~Feature>}
|
|
77
|
-
* @private
|
|
78
|
-
*/
|
|
79
|
-
this.highlightedFeatures = [];
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Array of selected features.
|
|
83
|
-
* @type {Array<ol/Feature~Feature>}
|
|
84
|
-
* @private
|
|
85
|
-
*/
|
|
86
|
-
this.selectedFeatures = [];
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Array of mapbox style layers to add.
|
|
90
|
-
* @type {Array<mapboxgl.styleLayer>}
|
|
91
|
-
* @private
|
|
92
|
-
*/
|
|
93
|
-
this.styleLayers =
|
|
94
|
-
(options.styleLayer ? [options.styleLayer] : options.styleLayers) || [];
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* @private
|
|
98
|
-
*/
|
|
99
|
-
this.addStyleLayers = this.addStyleLayers.bind(this);
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @private
|
|
103
|
-
*/
|
|
104
|
-
this.onLoad = this.onLoad.bind(this);
|
|
105
|
-
if (options.filters) {
|
|
106
|
-
/** @private */
|
|
107
|
-
this.addDynamicFilters = () => {
|
|
108
|
-
this.setFilter(
|
|
109
|
-
typeof options.filters === 'function'
|
|
110
|
-
? options.filters(this)
|
|
111
|
-
: options.filters,
|
|
112
|
-
);
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (!this.styleLayersFilter && this.styleLayers) {
|
|
117
|
-
const ids = this.styleLayers.map((s) => s.id);
|
|
118
|
-
this.styleLayersFilter = (styleLayer) => ids.includes(styleLayer.id);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Initialize the layer.
|
|
124
|
-
* @param {mapboxgl.Map} map the mapbox map.
|
|
125
|
-
* @override
|
|
126
|
-
*/
|
|
127
|
-
init(map) {
|
|
128
|
-
if (!this.mapboxLayer.map) {
|
|
129
|
-
this.mapboxLayer.init(map);
|
|
130
|
-
}
|
|
131
|
-
super.init(map);
|
|
132
|
-
|
|
133
|
-
if (!this.map) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Apply the initial visibiltity.
|
|
138
|
-
const { mbMap } = this.mapboxLayer;
|
|
139
|
-
if (!mbMap) {
|
|
140
|
-
// If the mbMap is not yet created because the map has no target yet, we
|
|
141
|
-
// relaunch the initialisation when it's the case.
|
|
142
|
-
this.olListenersKeys.push(
|
|
143
|
-
this.map.on('change:target', () => {
|
|
144
|
-
this.init(map);
|
|
145
|
-
}),
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// mbMap.loaded() and mbMap.isStyleLoaded() are reliable only on the first call of init.
|
|
152
|
-
// On the next call (when a topic change for example), these functions returns false because
|
|
153
|
-
// the style is being modified.
|
|
154
|
-
// That's why we rely on a property instead for the next calls.
|
|
155
|
-
if (this.mapboxLayer.loaded || mbMap.isStyleLoaded() || mbMap.loaded()) {
|
|
156
|
-
this.onLoad();
|
|
157
|
-
} else {
|
|
158
|
-
mbMap.once('load', this.onLoad);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Apply the visibiltity when layer's visibility change.
|
|
162
|
-
this.olListenersKeys.push(
|
|
163
|
-
this.on('change:visible', (evt) => {
|
|
164
|
-
// Once the map is loaded we can apply vsiiblity without waiting
|
|
165
|
-
// the style. Mapbox take care of the application of style changes.
|
|
166
|
-
this.applyLayoutVisibility(evt);
|
|
167
|
-
}),
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
this.olListenersKeys.push(
|
|
171
|
-
this.mapboxLayer.on('load', () => {
|
|
172
|
-
this.onLoad();
|
|
173
|
-
}),
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Terminate the layer.
|
|
179
|
-
* @param {mapboxgl.Map} map the mapbox map.
|
|
180
|
-
* @override
|
|
181
|
-
*/
|
|
182
|
-
terminate(map) {
|
|
183
|
-
const { mbMap } = this.mapboxLayer;
|
|
184
|
-
if (mbMap) {
|
|
185
|
-
mbMap.off('load', this.onLoad);
|
|
186
|
-
this.removeStyleLayers();
|
|
187
|
-
}
|
|
188
|
-
super.terminate(map);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/** @ignore */
|
|
192
|
-
addStyleLayers() {
|
|
193
|
-
const { mbMap } = this.mapboxLayer;
|
|
194
|
-
|
|
195
|
-
if (!mbMap) {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
this.styleLayers.forEach((styleLayer) => {
|
|
200
|
-
const { id, source } = styleLayer;
|
|
201
|
-
if (mbMap.getSource(source) && !mbMap.getLayer(id)) {
|
|
202
|
-
mbMap.addLayer(styleLayer, this.beforeId);
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
this.applyLayoutVisibility();
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/** @ignore */
|
|
209
|
-
removeStyleLayers() {
|
|
210
|
-
const { mbMap } = this.mapboxLayer;
|
|
211
|
-
|
|
212
|
-
if (!mbMap) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
this.styleLayers.forEach((styleLayer) => {
|
|
217
|
-
if (mbMap.getLayer(styleLayer.id)) {
|
|
218
|
-
mbMap.removeLayer(styleLayer.id);
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* On Mapbox map load callback function. Add style layers and dynaimc filters.
|
|
225
|
-
* @ignore
|
|
226
|
-
*/
|
|
227
|
-
onLoad() {
|
|
228
|
-
this.addStyleLayers();
|
|
229
|
-
|
|
230
|
-
if (this.addDynamicFilters) {
|
|
231
|
-
this.addDynamicFilters();
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const { mbMap } = this.mapboxLayer;
|
|
235
|
-
const style = mbMap.getStyle();
|
|
236
|
-
if (style && this.styleLayersFilter) {
|
|
237
|
-
const styles = style.layers.filter(this.styleLayersFilter);
|
|
238
|
-
this.disabled = !styles.length;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Request feature information for a given coordinate.
|
|
244
|
-
* @param {ol/coordinate~Coordinate} coordinate Coordinate to request the information at.
|
|
245
|
-
* @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
|
|
246
|
-
*/
|
|
247
|
-
getFeatureInfoAtCoordinate(coordinate) {
|
|
248
|
-
const { mbMap } = this.mapboxLayer;
|
|
249
|
-
|
|
250
|
-
// Ignore the getFeatureInfo until the mapbox map is loaded
|
|
251
|
-
if (!mbMap || !mbMap.isStyleLoaded()) {
|
|
252
|
-
return Promise.resolve({ coordinate, features: [], layer: this });
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// We query features only on style layers used by this layer.
|
|
256
|
-
let layers = this.styleLayers || [];
|
|
257
|
-
|
|
258
|
-
if (this.styleLayersFilter) {
|
|
259
|
-
layers = mbMap.getStyle().layers.filter(this.styleLayersFilter);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (this.queryRenderedLayersFilter) {
|
|
263
|
-
layers = mbMap.getStyle().layers.filter(this.queryRenderedLayersFilter);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
return this.mapboxLayer
|
|
267
|
-
.getFeatureInfoAtCoordinate(coordinate, {
|
|
268
|
-
layers: layers.map((layer) => layer && layer.id),
|
|
269
|
-
validate: false,
|
|
270
|
-
})
|
|
271
|
-
.then((featureInfo) => {
|
|
272
|
-
const features = featureInfo.features.filter((feature) =>
|
|
273
|
-
this.featureInfoFilter(feature, this.map.getView().getResolution()),
|
|
274
|
-
);
|
|
275
|
-
this.highlight(features);
|
|
276
|
-
return { ...featureInfo, features, layer: this };
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Set filter that determines which features should be rendered in a style layer.
|
|
282
|
-
* @param {mapboxgl.filter} filter Determines which features should be rendered in a style layer.
|
|
283
|
-
*/
|
|
284
|
-
setFilter(filter) {
|
|
285
|
-
const { mbMap } = this.mapboxLayer;
|
|
286
|
-
|
|
287
|
-
if (!mbMap) {
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
this.styleLayers.forEach(({ id }) => {
|
|
292
|
-
if (mbMap.getLayer(id)) {
|
|
293
|
-
mbMap.setFilter(id, filter);
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Set if features are hovered or not.
|
|
300
|
-
* @param {Array<ol/Feature~Feature>} features
|
|
301
|
-
* @param {boolean} state Is the feature hovered
|
|
302
|
-
* @private
|
|
303
|
-
*/
|
|
304
|
-
setHoverState(features, state) {
|
|
305
|
-
const { mbMap } = this.mapboxLayer;
|
|
306
|
-
|
|
307
|
-
if (!features || !mbMap) {
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
features.forEach((feature) => {
|
|
312
|
-
const { source, sourceLayer } = feature.get('mapboxFeature') || {};
|
|
313
|
-
if ((!source && !sourceLayer) || !feature.getId()) {
|
|
314
|
-
if (!feature.getId()) {
|
|
315
|
-
// eslint-disable-next-line no-console
|
|
316
|
-
console.warn(
|
|
317
|
-
"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.",
|
|
318
|
-
feature.getId(),
|
|
319
|
-
feature.getProperties(),
|
|
320
|
-
);
|
|
321
|
-
}
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
mbMap.setFeatureState(
|
|
326
|
-
{
|
|
327
|
-
id: feature.getId(),
|
|
328
|
-
source,
|
|
329
|
-
sourceLayer,
|
|
330
|
-
},
|
|
331
|
-
{ hover: state },
|
|
332
|
-
);
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* Select a list of features.
|
|
338
|
-
* @param {Array<ol/Feature~Feature>} [features=[]] Features to select.
|
|
339
|
-
* @private
|
|
340
|
-
*/
|
|
341
|
-
select(features = []) {
|
|
342
|
-
this.setHoverState(this.selectedFeatures, false);
|
|
343
|
-
this.selectedFeatures = features;
|
|
344
|
-
this.setHoverState(this.selectedFeatures, true);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Highlight a list of features.
|
|
349
|
-
* @param {Array<ol/Feature~Feature>} [features=[]] Features to highlight.
|
|
350
|
-
* @private
|
|
351
|
-
*/
|
|
352
|
-
highlight(features = []) {
|
|
353
|
-
// Filter out selected features
|
|
354
|
-
const filtered = this.highlightedFeatures.filter(
|
|
355
|
-
(feature) =>
|
|
356
|
-
!this.selectedFeatures
|
|
357
|
-
.map((feat) => feat.getId())
|
|
358
|
-
.includes(feature.getId()),
|
|
359
|
-
);
|
|
360
|
-
|
|
361
|
-
// Remove previous highlight
|
|
362
|
-
this.setHoverState(filtered, false);
|
|
363
|
-
this.highlightedFeatures = features;
|
|
364
|
-
|
|
365
|
-
// Add highlight
|
|
366
|
-
this.setHoverState(this.highlightedFeatures, true);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* Apply visibility to style layers that fits the styleLayersFilter function.
|
|
371
|
-
* @param {Event} evt Layer's event that has called the function.
|
|
372
|
-
* @private
|
|
373
|
-
*/
|
|
374
|
-
// eslint-disable-next-line no-unused-vars
|
|
375
|
-
applyLayoutVisibility(evt) {
|
|
376
|
-
const { visible } = this;
|
|
377
|
-
const { mbMap } = this.mapboxLayer;
|
|
378
|
-
const filterFunc = this.styleLayersFilter;
|
|
379
|
-
|
|
380
|
-
if (!mbMap) {
|
|
381
|
-
return;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
const style = mbMap.getStyle();
|
|
385
|
-
|
|
386
|
-
if (!style) {
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
if (filterFunc) {
|
|
391
|
-
const visibilityValue = visible ? 'visible' : 'none';
|
|
392
|
-
for (let i = 0; i < style.layers.length; i += 1) {
|
|
393
|
-
const styleLayer = style.layers[i];
|
|
394
|
-
if (filterFunc(styleLayer)) {
|
|
395
|
-
if (mbMap.getLayer(styleLayer.id)) {
|
|
396
|
-
mbMap.setLayoutProperty(
|
|
397
|
-
styleLayer.id,
|
|
398
|
-
'visibility',
|
|
399
|
-
visibilityValue,
|
|
400
|
-
);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* Create a copy of the MapboxStyleLayer.
|
|
409
|
-
* @param {Object} newOptions Options to override.
|
|
410
|
-
* @return {MapboxStyleLayer} A MapboxStyleLayer.
|
|
411
|
-
*/
|
|
412
|
-
clone(newOptions) {
|
|
413
|
-
return new MapboxStyleLayer({ ...this.options, ...newOptions });
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
export default MapboxStyleLayer;
|
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-underscore-dangle */
|
|
2
|
-
import { toLonLat } from 'ol/proj';
|
|
3
|
-
import { Map } from 'maplibre-gl';
|
|
4
|
-
import Source from 'ol/source/Source';
|
|
5
|
-
import OLLayer from 'ol/layer/Layer';
|
|
6
|
-
import GeoJSON from 'ol/format/GeoJSON';
|
|
7
|
-
import { toDegrees } from 'ol/math';
|
|
8
|
-
import Layer from './Layer';
|
|
9
|
-
import { getMapboxMapCopyrights, getMapboxStyleUrl } from '../../common/utils';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* A class representing MaplibreLayer to display on BasicMap
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* import { MaplibreLayer } from 'mobility-toolbox-js/ol';
|
|
16
|
-
*
|
|
17
|
-
* const layer = new MaplibreLayer({
|
|
18
|
-
* url: 'https://maps.geops.io/styles/travic_v2/style.json',
|
|
19
|
-
* apikey: 'yourApiKey',
|
|
20
|
-
* });
|
|
21
|
-
*
|
|
22
|
-
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
23
|
-
* @extends {Layer}
|
|
24
|
-
*/
|
|
25
|
-
export default class MaplibreLayer extends Layer {
|
|
26
|
-
/**
|
|
27
|
-
* Constructor.
|
|
28
|
-
*
|
|
29
|
-
* @param {Object} options
|
|
30
|
-
* @param {boolean} [options.preserveDrawingBuffer=false] If true able to export the canvas.
|
|
31
|
-
* @param {number} [options.fadeDuration=300] Duration of the fade effect in ms.
|
|
32
|
-
*/
|
|
33
|
-
constructor(options = {}) {
|
|
34
|
-
const mbLayer = new OLLayer({
|
|
35
|
-
source: new Source({}),
|
|
36
|
-
render: (frameState) => {
|
|
37
|
-
if (!this.mbMap) {
|
|
38
|
-
// eslint-disable-next-line no-console
|
|
39
|
-
console.warn("Mapbox map doesn't exist.");
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const canvas = this.mbMap.getCanvas();
|
|
44
|
-
const { viewState } = frameState;
|
|
45
|
-
|
|
46
|
-
const opacity = this.olLayer.getOpacity();
|
|
47
|
-
canvas.style.opacity = opacity;
|
|
48
|
-
|
|
49
|
-
// adjust view parameters in mapbox
|
|
50
|
-
this.mbMap.jumpTo({
|
|
51
|
-
center: toLonLat(viewState.center),
|
|
52
|
-
zoom: viewState.zoom - 1,
|
|
53
|
-
bearing: toDegrees(-viewState.rotation),
|
|
54
|
-
animate: false,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
if (!canvas.isConnected) {
|
|
58
|
-
// The canvas is not connected to the DOM, request a map rendering at the next animation frame
|
|
59
|
-
// to set the canvas size.
|
|
60
|
-
this.map.render();
|
|
61
|
-
} else if (
|
|
62
|
-
canvas.width !== frameState.size[0] ||
|
|
63
|
-
canvas.height !== frameState.size[1]
|
|
64
|
-
) {
|
|
65
|
-
this.mbMap.resize();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
this.mbMap.redraw();
|
|
69
|
-
|
|
70
|
-
return this.mbMap.getContainer();
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
super({
|
|
75
|
-
...options,
|
|
76
|
-
olLayer: mbLayer,
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Url of the mapbox style.
|
|
81
|
-
* @type {string}
|
|
82
|
-
* @private
|
|
83
|
-
*/
|
|
84
|
-
this.styleUrl = options.url;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Api key for the url of the mapbox style.
|
|
88
|
-
* If set to false, the apiKey is not required.
|
|
89
|
-
* @type {string}
|
|
90
|
-
* @private
|
|
91
|
-
*/
|
|
92
|
-
this.apiKey = options.apiKey;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Name of the apiKey to set in the url request.
|
|
96
|
-
* Default is 'key'.
|
|
97
|
-
* @type {string}
|
|
98
|
-
* @private
|
|
99
|
-
*/
|
|
100
|
-
this.apiKeyName = options.apiKeyName || 'key';
|
|
101
|
-
|
|
102
|
-
/** @ignore */
|
|
103
|
-
this.updateAttribution = this.updateAttribution.bind(this);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Initialize the layer and listen to feature clicks.
|
|
108
|
-
* @param {ol/Map~Map} map
|
|
109
|
-
*/
|
|
110
|
-
init(map) {
|
|
111
|
-
super.init(map);
|
|
112
|
-
|
|
113
|
-
if (!this.map) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* The feature format.
|
|
119
|
-
* @type {ol/format/GeoJSON}
|
|
120
|
-
*/
|
|
121
|
-
this.format = new GeoJSON({
|
|
122
|
-
featureProjection: this.map.getView().getProjection(),
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
this.loadMbMap();
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Terminate what was initialized in init function. Remove layer, events...
|
|
130
|
-
*/
|
|
131
|
-
terminate() {
|
|
132
|
-
if (this.mbMap) {
|
|
133
|
-
this.mbMap.off('idle', this.updateAttribution);
|
|
134
|
-
// Some asynchrone repaints are triggered even if the mbMap has been removed,
|
|
135
|
-
// to avoid display of errors we set an empty function.
|
|
136
|
-
this.mbMap.triggerRepaint = () => {};
|
|
137
|
-
this.mbMap.remove();
|
|
138
|
-
this.mbMap = null;
|
|
139
|
-
}
|
|
140
|
-
this.loaded = false;
|
|
141
|
-
super.terminate();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Returns a style URL with apiKey & apiKeyName infos.
|
|
146
|
-
* @private
|
|
147
|
-
*/
|
|
148
|
-
createStyleUrl() {
|
|
149
|
-
return getMapboxStyleUrl(this.apiKey, this.apiKeyName, this.styleUrl);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Create the mapbox map.
|
|
154
|
-
* @private
|
|
155
|
-
*/
|
|
156
|
-
loadMbMap() {
|
|
157
|
-
this.olListenersKeys.push(
|
|
158
|
-
this.map.on('change:target', () => {
|
|
159
|
-
this.loadMbMap();
|
|
160
|
-
}),
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
if (!this.map.getTargetElement()) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (!this.visible) {
|
|
168
|
-
// On next change of visibility we load the map
|
|
169
|
-
this.olListenersKeys.push(
|
|
170
|
-
this.once('change:visible', () => {
|
|
171
|
-
this.loadMbMap();
|
|
172
|
-
}),
|
|
173
|
-
);
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const container = document.createElement('div');
|
|
178
|
-
container.style.position = 'absolute';
|
|
179
|
-
container.style.width = '100%';
|
|
180
|
-
container.style.height = '100%';
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* A mapbox map
|
|
184
|
-
* @type {mapboxgl.Map}
|
|
185
|
-
*/
|
|
186
|
-
this.mbMap = new Map({
|
|
187
|
-
style: this.createStyleUrl(),
|
|
188
|
-
container,
|
|
189
|
-
interactive: false,
|
|
190
|
-
trackResize: false,
|
|
191
|
-
attributionControl: false,
|
|
192
|
-
...(this.options.mapOptions || {}),
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
this.mbMap.once('load', () => {
|
|
196
|
-
/**
|
|
197
|
-
* Is the map loaded.
|
|
198
|
-
* @type {boolean}
|
|
199
|
-
*/
|
|
200
|
-
this.loaded = true;
|
|
201
|
-
|
|
202
|
-
this.dispatchEvent({
|
|
203
|
-
type: 'load',
|
|
204
|
-
target: this,
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
this.mbMap.on('idle', this.updateAttribution);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Update attributions of the source.
|
|
213
|
-
* @private
|
|
214
|
-
*/
|
|
215
|
-
updateAttribution(evt) {
|
|
216
|
-
const newAttributions = getMapboxMapCopyrights(evt.target) || [];
|
|
217
|
-
if (this.copyrights?.toString() !== newAttributions.toString()) {
|
|
218
|
-
this.copyrights = newAttributions;
|
|
219
|
-
this.olLayer.getSource().setAttributions(newAttributions);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Request feature information for a given coordinate.
|
|
225
|
-
* @param {ol/coordinate~Coordinate} coordinate Coordinate to request the information at.
|
|
226
|
-
* @param {Object} options A [mapboxgl.Map#queryrenderedfeatures](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#queryrenderedfeatures) options parameter.
|
|
227
|
-
* @return {Promise<FeatureInfo>} Promise with features, layer and coordinate. The original Mapbox feature is available as a property named 'mapboxFeature'.
|
|
228
|
-
*/
|
|
229
|
-
getFeatureInfoAtCoordinate(coordinate, options) {
|
|
230
|
-
// Ignore the getFeatureInfo until the mapbox map is loaded
|
|
231
|
-
if (
|
|
232
|
-
!options ||
|
|
233
|
-
!this.format ||
|
|
234
|
-
!this.mbMap ||
|
|
235
|
-
!this.mbMap.isStyleLoaded()
|
|
236
|
-
) {
|
|
237
|
-
return Promise.resolve({ coordinate, features: [], layer: this });
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
let pixel = coordinate && this.mbMap.project(toLonLat(coordinate));
|
|
241
|
-
|
|
242
|
-
if (this.hitTolerance) {
|
|
243
|
-
const { x, y } = pixel;
|
|
244
|
-
pixel = [
|
|
245
|
-
{ x: x - this.hitTolerance, y: y - this.hitTolerance },
|
|
246
|
-
{ x: x + this.hitTolerance, y: y + this.hitTolerance },
|
|
247
|
-
];
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// At this point we get GeoJSON Mapbox feature, we transform it to an OpenLayers
|
|
251
|
-
// feature to be consistent with other layers.
|
|
252
|
-
const features = this.mbMap
|
|
253
|
-
.queryRenderedFeatures(pixel, options)
|
|
254
|
-
.map((feature) => {
|
|
255
|
-
const olFeature = this.format.readFeature(feature);
|
|
256
|
-
if (olFeature) {
|
|
257
|
-
// We save the original mapbox feature to avoid losing informations
|
|
258
|
-
// potentially needed for other functionnality like highlighting
|
|
259
|
-
// (id, layer id, source, sourceLayer ...)
|
|
260
|
-
olFeature.set('mapboxFeature', feature);
|
|
261
|
-
}
|
|
262
|
-
return olFeature;
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
return Promise.resolve({
|
|
266
|
-
layer: this,
|
|
267
|
-
features,
|
|
268
|
-
coordinate,
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Create a copy of the MapboxLayer.
|
|
274
|
-
* @param {Object} newOptions Options to override
|
|
275
|
-
* @return {MapboxLayer} A MapboxLayer
|
|
276
|
-
*/
|
|
277
|
-
clone(newOptions) {
|
|
278
|
-
return new MaplibreLayer({ ...this.options, ...newOptions });
|
|
279
|
-
}
|
|
280
|
-
}
|