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,91 +0,0 @@
|
|
|
1
|
-
import { Circle, Fill, Stroke, Style } from 'ol/style';
|
|
2
|
-
import { Vector as VectorSource } from 'ol/source';
|
|
3
|
-
import { Vector } from 'ol/layer';
|
|
4
|
-
import Layer from './Layer';
|
|
5
|
-
|
|
6
|
-
const circleStyle = new Circle({
|
|
7
|
-
radius: 6,
|
|
8
|
-
fill: new Fill({
|
|
9
|
-
color: [255, 0, 0, 1],
|
|
10
|
-
}),
|
|
11
|
-
stroke: new Stroke({
|
|
12
|
-
color: [0, 0, 0, 1],
|
|
13
|
-
width: 1,
|
|
14
|
-
}),
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const blackBorder = new Style({
|
|
18
|
-
stroke: new Stroke({
|
|
19
|
-
color: [0, 0, 0, 1],
|
|
20
|
-
width: 5,
|
|
21
|
-
}),
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const redLine = new Style({
|
|
25
|
-
image: circleStyle,
|
|
26
|
-
stroke: new Stroke({
|
|
27
|
-
color: [255, 0, 0, 1],
|
|
28
|
-
width: 3,
|
|
29
|
-
}),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const dashedRedLine = new Style({
|
|
33
|
-
image: circleStyle,
|
|
34
|
-
stroke: new Stroke({
|
|
35
|
-
color: [255, 0, 0, 1],
|
|
36
|
-
width: 3,
|
|
37
|
-
lineDash: [1, 10],
|
|
38
|
-
}),
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const defaultStyleFunction = (feature, resolution) => {
|
|
42
|
-
const minResolution = feature.get('minResolution');
|
|
43
|
-
const maxResolution = feature.get('maxResolution');
|
|
44
|
-
const inRange = resolution <= minResolution && resolution > maxResolution;
|
|
45
|
-
|
|
46
|
-
if (minResolution && maxResolution && !inRange) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
const mot = feature.get('mot');
|
|
50
|
-
|
|
51
|
-
if (mot !== 'foot') {
|
|
52
|
-
return [blackBorder, redLine];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return [dashedRedLine];
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* A class use to display vector data.
|
|
60
|
-
*
|
|
61
|
-
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
62
|
-
* @extends {Layer}
|
|
63
|
-
*/
|
|
64
|
-
class RoutingLayer extends Layer {
|
|
65
|
-
/**
|
|
66
|
-
* Constructor.
|
|
67
|
-
* @param {Object} [options]
|
|
68
|
-
* @param {ol/style/Style~StyleLike} [options.style] Style to be used for routes, uses (ol/StyleLike) [https://openlayers.org/en/latest/apidoc/module-ol_style_Style.html#~StyleLike] instances
|
|
69
|
-
*/
|
|
70
|
-
constructor(options = {}) {
|
|
71
|
-
super(options);
|
|
72
|
-
|
|
73
|
-
this.olLayer =
|
|
74
|
-
options.olLayer ||
|
|
75
|
-
new Vector({
|
|
76
|
-
source: new VectorSource(),
|
|
77
|
-
style: options.style || defaultStyleFunction,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Create a copy of the RoutingLayer.
|
|
83
|
-
* @param {Object} newOptions Options to override
|
|
84
|
-
* @return {RoutingLayer} A RoutingLayer
|
|
85
|
-
*/
|
|
86
|
-
clone(newOptions) {
|
|
87
|
-
return new RoutingLayer({ ...this.options, ...newOptions });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export default RoutingLayer;
|
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
import GeoJSON from 'ol/format/GeoJSON';
|
|
2
|
-
import { Layer as OLLayer, Group, Vector as VectorLayer } from 'ol/layer';
|
|
3
|
-
import Source from 'ol/source/Source';
|
|
4
|
-
import { composeCssTransform } from 'ol/transform';
|
|
5
|
-
import { Vector as VectorSource } from 'ol/source';
|
|
6
|
-
import Layer from './Layer';
|
|
7
|
-
import mixin from '../../common/mixins/TralisLayerMixin';
|
|
8
|
-
import { fullTrajectoryStyle } from '../styles';
|
|
9
|
-
|
|
10
|
-
const format = new GeoJSON();
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Responsible for loading and display data from a Tralis service.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* import { TralisLayer } from 'mobility-toolbox-js/ol';
|
|
17
|
-
*
|
|
18
|
-
* const layer = new TralisLayer({
|
|
19
|
-
* url: [yourUrl],
|
|
20
|
-
* apiKey: [yourApiKey],
|
|
21
|
-
* });
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @see <a href="/api/class/src/api/tralis/TralisAPI%20js~TralisAPI%20html">TralisAPI</a>
|
|
25
|
-
*
|
|
26
|
-
* @extends {Layer}
|
|
27
|
-
* @implements {TralisLayerInterface}
|
|
28
|
-
*/
|
|
29
|
-
class TralisLayer extends mixin(Layer) {
|
|
30
|
-
/**
|
|
31
|
-
* Constructor.
|
|
32
|
-
*
|
|
33
|
-
* @param {Object} options
|
|
34
|
-
* @private
|
|
35
|
-
*/
|
|
36
|
-
constructor(options = {}) {
|
|
37
|
-
// We use a group to be able to add custom vector layer in extended class.
|
|
38
|
-
// For example TrajservLayer use a vectorLayer to display the complete trajectory.
|
|
39
|
-
super({
|
|
40
|
-
...options,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
/** @ignore */
|
|
44
|
-
this.olLayer =
|
|
45
|
-
options.olLayer ||
|
|
46
|
-
new Group({
|
|
47
|
-
layers: [
|
|
48
|
-
new VectorLayer({
|
|
49
|
-
source: new VectorSource({ features: [] }),
|
|
50
|
-
style: options.fullTrajectoryStyle || fullTrajectoryStyle,
|
|
51
|
-
}),
|
|
52
|
-
new OLLayer({
|
|
53
|
-
source: new Source({}),
|
|
54
|
-
render: (frameState) => {
|
|
55
|
-
if (!this.tracker || !this.tracker.canvas) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (!this.container) {
|
|
60
|
-
this.container = document.createElement('div');
|
|
61
|
-
this.container.style.position = 'absolute';
|
|
62
|
-
this.container.style.width = '100%';
|
|
63
|
-
this.container.style.height = '100%';
|
|
64
|
-
this.transformContainer = document.createElement('div');
|
|
65
|
-
this.transformContainer.style.position = 'absolute';
|
|
66
|
-
this.transformContainer.style.width = '100%';
|
|
67
|
-
this.transformContainer.style.height = '100%';
|
|
68
|
-
this.container.appendChild(this.transformContainer);
|
|
69
|
-
this.tracker.canvas.style.position = 'absolute';
|
|
70
|
-
this.tracker.canvas.style.top = '0';
|
|
71
|
-
this.tracker.canvas.style.left = '0';
|
|
72
|
-
this.tracker.canvas.style.transformOrigin = 'top left';
|
|
73
|
-
this.transformContainer.appendChild(this.tracker.canvas);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (this.renderedViewState) {
|
|
77
|
-
const { center, resolution, rotation } = frameState.viewState;
|
|
78
|
-
const {
|
|
79
|
-
center: renderedCenter,
|
|
80
|
-
resolution: renderedResolution,
|
|
81
|
-
rotation: renderedRotation,
|
|
82
|
-
} = this.renderedViewState;
|
|
83
|
-
|
|
84
|
-
if (renderedResolution / resolution >= 3) {
|
|
85
|
-
// Avoid having really big points when zooming fast.
|
|
86
|
-
const { canvas } = this.tracker;
|
|
87
|
-
const context = canvas.getContext('2d');
|
|
88
|
-
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
89
|
-
} else {
|
|
90
|
-
const pixelCenterRendered =
|
|
91
|
-
this.map.getPixelFromCoordinate(renderedCenter);
|
|
92
|
-
const pixelCenter = this.map.getPixelFromCoordinate(center);
|
|
93
|
-
this.transformContainer.style.transform = composeCssTransform(
|
|
94
|
-
pixelCenterRendered[0] - pixelCenter[0],
|
|
95
|
-
pixelCenterRendered[1] - pixelCenter[1],
|
|
96
|
-
renderedResolution / resolution,
|
|
97
|
-
renderedResolution / resolution,
|
|
98
|
-
rotation - renderedRotation,
|
|
99
|
-
0,
|
|
100
|
-
0,
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return this.container;
|
|
105
|
-
},
|
|
106
|
-
}),
|
|
107
|
-
],
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// We store the layer used to highlight the full Trajectory
|
|
111
|
-
this.vectorLayer = this.olLayer.getLayers().item(0);
|
|
112
|
-
|
|
113
|
-
// Options the last render run did happen. If something changes
|
|
114
|
-
// we have to render again
|
|
115
|
-
/** @ignore */
|
|
116
|
-
this.renderState = {
|
|
117
|
-
center: [0, 0],
|
|
118
|
-
zoom: null,
|
|
119
|
-
rotation: 0,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
init(map) {
|
|
124
|
-
super.init(map);
|
|
125
|
-
if (this.map) {
|
|
126
|
-
this.olListenersKeys.push(
|
|
127
|
-
this.map.on(['moveend', 'change:target'], (evt) => {
|
|
128
|
-
const view = this.map.getView();
|
|
129
|
-
if (view.getAnimating() || view.getInteracting()) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
const zoom = view.getZoom();
|
|
133
|
-
|
|
134
|
-
// Update the interval between render updates
|
|
135
|
-
if (this.currentZoom !== zoom) {
|
|
136
|
-
this.onZoomEnd(evt);
|
|
137
|
-
}
|
|
138
|
-
this.currentZoom = zoom;
|
|
139
|
-
|
|
140
|
-
this.onMoveEnd(evt);
|
|
141
|
-
}),
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Destroy the container of the tracker.
|
|
148
|
-
*/
|
|
149
|
-
terminate() {
|
|
150
|
-
super.terminate();
|
|
151
|
-
this.container = null;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Detect in the canvas if there is data to query at a specific coordinate.
|
|
156
|
-
* @param {ol/coordinate~Coordinate} coordinate The coordinate to test
|
|
157
|
-
* @returns
|
|
158
|
-
*/
|
|
159
|
-
hasFeatureInfoAtCoordinate(coordinate) {
|
|
160
|
-
if (this.map && this.tracker && this.tracker.canvas) {
|
|
161
|
-
const context = this.tracker.canvas.getContext('2d');
|
|
162
|
-
const pixel = this.map.getPixelFromCoordinate(coordinate);
|
|
163
|
-
return !!context.getImageData(
|
|
164
|
-
pixel[0] * this.pixelRatio,
|
|
165
|
-
pixel[1] * this.pixelRatio,
|
|
166
|
-
1,
|
|
167
|
-
1,
|
|
168
|
-
).data[3];
|
|
169
|
-
}
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Render the trajectories using current map's size, resolution and rotation.
|
|
175
|
-
* @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
|
|
176
|
-
* @overrides
|
|
177
|
-
*/
|
|
178
|
-
renderTrajectories(noInterpolate) {
|
|
179
|
-
const view = this.map.getView();
|
|
180
|
-
super.renderTrajectories(
|
|
181
|
-
{
|
|
182
|
-
size: this.map.getSize(),
|
|
183
|
-
center: this.map.getView().getCenter(),
|
|
184
|
-
extent: view.calculateExtent(),
|
|
185
|
-
resolution: view.getResolution(),
|
|
186
|
-
rotation: view.getRotation(),
|
|
187
|
-
zoom: view.getZoom(),
|
|
188
|
-
pixelRatio: this.pixelRatio,
|
|
189
|
-
},
|
|
190
|
-
noInterpolate,
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Launch renderTrajectories. it avoids duplicating code in renderTrajectories methhod.
|
|
196
|
-
* @private
|
|
197
|
-
* @override
|
|
198
|
-
*/
|
|
199
|
-
renderTrajectoriesInternal(viewState, noInterpolate) {
|
|
200
|
-
let isRendered = false;
|
|
201
|
-
|
|
202
|
-
const blockRendering =
|
|
203
|
-
this.map.getView().getAnimating() || this.map.getView().getInteracting();
|
|
204
|
-
|
|
205
|
-
// Don't render the map when the map is animating or interacting.
|
|
206
|
-
isRendered = blockRendering
|
|
207
|
-
? false
|
|
208
|
-
: super.renderTrajectoriesInternal(viewState, noInterpolate);
|
|
209
|
-
|
|
210
|
-
// We update the current render state.
|
|
211
|
-
if (isRendered) {
|
|
212
|
-
this.renderedViewState = { ...viewState };
|
|
213
|
-
|
|
214
|
-
if (this.transformContainer) {
|
|
215
|
-
this.transformContainer.style.transform = '';
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Return the delay in ms before the next rendering.
|
|
222
|
-
*/
|
|
223
|
-
getRefreshTimeInMs() {
|
|
224
|
-
return super.getRefreshTimeInMs(this.map.getView().getZoom());
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
getFeatureInfoAtCoordinate(coordinate, options = {}) {
|
|
228
|
-
const resolution = this.map.getView().getResolution();
|
|
229
|
-
return super.getFeatureInfoAtCoordinate(coordinate, {
|
|
230
|
-
resolution,
|
|
231
|
-
...options,
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* On move end we update the websocket with the new bbox.
|
|
237
|
-
*
|
|
238
|
-
* @param {ol/MapEvent~MapEvent} evt Moveend event
|
|
239
|
-
* @private
|
|
240
|
-
* @override
|
|
241
|
-
*/
|
|
242
|
-
onMoveEnd() {
|
|
243
|
-
if (this.visible && this.isUpdateBboxOnMoveEnd) {
|
|
244
|
-
this.setBbox();
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (
|
|
248
|
-
this.visible &&
|
|
249
|
-
this.isUpdateBboxOnMoveEnd &&
|
|
250
|
-
this.isClickActive &&
|
|
251
|
-
this.selectedVehicleId
|
|
252
|
-
) {
|
|
253
|
-
this.highlightTrajectory(this.selectedVehicleId);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Function called on moveend event only when the zoom has changed.
|
|
259
|
-
*
|
|
260
|
-
* @param {ol/MapEvent~MapEvent} evt Moveend event.
|
|
261
|
-
* @private
|
|
262
|
-
* @override
|
|
263
|
-
*/
|
|
264
|
-
// eslint-disable-next-line no-unused-vars
|
|
265
|
-
onZoomEnd(evt) {
|
|
266
|
-
super.onZoomEnd(evt);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Update the cursor style when hovering a vehicle.
|
|
271
|
-
*
|
|
272
|
-
* @private
|
|
273
|
-
* @override
|
|
274
|
-
*/
|
|
275
|
-
onFeatureHover(features, layer, coordinate) {
|
|
276
|
-
super.onFeatureHover(features, layer, coordinate);
|
|
277
|
-
this.map.getTargetElement().style.cursor = features.length
|
|
278
|
-
? 'pointer'
|
|
279
|
-
: 'auto';
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Display the complete trajectory of the vehicle.
|
|
284
|
-
*
|
|
285
|
-
* @private
|
|
286
|
-
* @override
|
|
287
|
-
*/
|
|
288
|
-
onFeatureClick(features, layer, coordinate) {
|
|
289
|
-
super.onFeatureClick(features, layer, coordinate);
|
|
290
|
-
if (!features.length && this.vectorLayer) {
|
|
291
|
-
this.vectorLayer.getSource().clear();
|
|
292
|
-
}
|
|
293
|
-
if (this.selectedVehicleId) {
|
|
294
|
-
this.highlightTrajectory(this.selectedVehicleId);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Remove the trajectory form the list if necessary.
|
|
300
|
-
*
|
|
301
|
-
* @private
|
|
302
|
-
*/
|
|
303
|
-
purgeTrajectory(trajectory, extent, zoom) {
|
|
304
|
-
return super.purgeTrajectory(
|
|
305
|
-
trajectory,
|
|
306
|
-
extent || this.map.getView().calculateExtent(),
|
|
307
|
-
zoom || this.map.getView().getZoom(),
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Send the current bbox to the websocket
|
|
313
|
-
*
|
|
314
|
-
* @private
|
|
315
|
-
*/
|
|
316
|
-
setBbox(extent, zoom) {
|
|
317
|
-
let newExtent = extent;
|
|
318
|
-
let newZoom = zoom;
|
|
319
|
-
if (!newExtent && this.isUpdateBboxOnMoveEnd) {
|
|
320
|
-
newExtent = extent || this.map.getView().calculateExtent();
|
|
321
|
-
newZoom = Math.floor(this.map.getView().getZoom());
|
|
322
|
-
}
|
|
323
|
-
super.setBbox(newExtent, newZoom);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Highlight the trajectory of journey.
|
|
328
|
-
* @private
|
|
329
|
-
*/
|
|
330
|
-
highlightTrajectory(id) {
|
|
331
|
-
this.api
|
|
332
|
-
.getFullTrajectory(id, this.mode, this.generalizationLevel)
|
|
333
|
-
.then((fullTrajectory) => {
|
|
334
|
-
const vectorSource = this.vectorLayer.getSource();
|
|
335
|
-
vectorSource.clear();
|
|
336
|
-
|
|
337
|
-
if (
|
|
338
|
-
!fullTrajectory ||
|
|
339
|
-
!fullTrajectory.features ||
|
|
340
|
-
!fullTrajectory.features.length
|
|
341
|
-
) {
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
const features = format.readFeatures(fullTrajectory);
|
|
345
|
-
this.vectorLayer.getSource().addFeatures(features);
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Create a copy of the TralisLayer.
|
|
351
|
-
* @param {Object} newOptions Options to override
|
|
352
|
-
* @return {TralisLayer} A TralisLayer
|
|
353
|
-
*/
|
|
354
|
-
clone(newOptions) {
|
|
355
|
-
return new TralisLayer({ ...this.options, ...newOptions });
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
export default TralisLayer;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import fetch from 'jest-fetch-mock';
|
|
2
|
-
import Map from 'ol/Map';
|
|
3
|
-
import View from 'ol/View';
|
|
4
|
-
import WS from 'jest-websocket-mock';
|
|
5
|
-
import TralisLayer from './TralisLayer';
|
|
6
|
-
|
|
7
|
-
// create a WS instance, listening on port 1234 on localhost
|
|
8
|
-
let layer;
|
|
9
|
-
let onClick;
|
|
10
|
-
let olMap;
|
|
11
|
-
let server;
|
|
12
|
-
|
|
13
|
-
describe('TralisLayer', () => {
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
server = new WS('ws://localhost:1234');
|
|
16
|
-
global.fetch = fetch;
|
|
17
|
-
fetch.resetMocks();
|
|
18
|
-
|
|
19
|
-
onClick = jest.fn();
|
|
20
|
-
layer = new TralisLayer({
|
|
21
|
-
url: 'ws://localhost:1234',
|
|
22
|
-
apiKey: 'apiKey',
|
|
23
|
-
onClick,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
olMap = new Map({
|
|
27
|
-
view: new View({
|
|
28
|
-
center: [831634, 5933959],
|
|
29
|
-
zoom: 9,
|
|
30
|
-
}),
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
afterEach(() => {
|
|
35
|
-
// ...or gracefully close the connection
|
|
36
|
-
server.close();
|
|
37
|
-
|
|
38
|
-
// The WS class also has a static "clean" method to gracefully close all open connections,
|
|
39
|
-
// particularly useful to reset the environment between test runs.
|
|
40
|
-
WS.clean();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('should be instanced.', () => {
|
|
44
|
-
expect(layer).toBeInstanceOf(TralisLayer);
|
|
45
|
-
expect(layer.clickCallbacks[0]).toBe(onClick);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('should called terminate on initalization.', () => {
|
|
49
|
-
const spy = jest.spyOn(layer, 'terminate');
|
|
50
|
-
|
|
51
|
-
fetch.mockResponseOnce(JSON.stringify(global.fetchTrajectoriesResponse));
|
|
52
|
-
|
|
53
|
-
layer.init(olMap);
|
|
54
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('should clone', () => {
|
|
58
|
-
const clone = layer.clone({ name: 'clone' });
|
|
59
|
-
expect(clone).not.toBe(layer);
|
|
60
|
-
expect(clone.name).toBe('clone');
|
|
61
|
-
expect(clone).toBeInstanceOf(TralisLayer);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('should use the sort function.', () => {
|
|
65
|
-
const fn = () => true;
|
|
66
|
-
const laye = new TralisLayer({
|
|
67
|
-
url: 'ws://localhost:1234',
|
|
68
|
-
apiKey: 'apiKey',
|
|
69
|
-
sort: fn,
|
|
70
|
-
});
|
|
71
|
-
expect(laye).toBeInstanceOf(TralisLayer);
|
|
72
|
-
expect(laye.sort).toBe(fn);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test('should use filter function.', () => {
|
|
76
|
-
const fn = () => true;
|
|
77
|
-
const laye = new TralisLayer({
|
|
78
|
-
url: 'ws://localhost:1234',
|
|
79
|
-
apiKey: 'apiKey',
|
|
80
|
-
filter: fn, // reverse the array
|
|
81
|
-
});
|
|
82
|
-
expect(laye).toBeInstanceOf(TralisLayer);
|
|
83
|
-
expect(laye.filter).toBe(fn);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test('should override filter function if operator, tripNumber, regexPublishedLineName is set.', () => {
|
|
87
|
-
const fn = () => true;
|
|
88
|
-
const laye = new TralisLayer({
|
|
89
|
-
url: 'ws://localhost:1234',
|
|
90
|
-
apiKey: 'apiKey',
|
|
91
|
-
filter: fn, // reverse the array
|
|
92
|
-
publishedLineName: '.*',
|
|
93
|
-
});
|
|
94
|
-
expect(laye).toBeInstanceOf(TralisLayer);
|
|
95
|
-
expect(laye.filter).not.toBe(fn);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import Layer from './Layer';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A class use to display vector data.
|
|
5
|
-
*
|
|
6
|
-
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
7
|
-
* @extends {Layer}
|
|
8
|
-
*/
|
|
9
|
-
class VectorLayer extends Layer {
|
|
10
|
-
/**
|
|
11
|
-
* Request feature information for a given coordinate.
|
|
12
|
-
* @param {ol/coordinate~Coordinate} coordinate the coordinate to request the information at.
|
|
13
|
-
* @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
|
|
14
|
-
*/
|
|
15
|
-
getFeatureInfoAtCoordinate(coordinate) {
|
|
16
|
-
let features = [];
|
|
17
|
-
|
|
18
|
-
if (this.map) {
|
|
19
|
-
const pixel = this.map.getPixelFromCoordinate(coordinate);
|
|
20
|
-
features = this.map.getFeaturesAtPixel(pixel, {
|
|
21
|
-
layerFilter: (l) => l === this.olLayer,
|
|
22
|
-
hitTolerance: this.hitTolerance,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return Promise.resolve({
|
|
27
|
-
features,
|
|
28
|
-
layer: this,
|
|
29
|
-
coordinate,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Create a copy of the VectorLayer.
|
|
35
|
-
* @param {Object} newOptions Options to override
|
|
36
|
-
* @return {VectorLayer} A VectorLayer
|
|
37
|
-
*/
|
|
38
|
-
clone(newOptions) {
|
|
39
|
-
return new VectorLayer({ ...this.options, ...newOptions });
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export default VectorLayer;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import GeoJSON from 'ol/format/GeoJSON';
|
|
2
|
-
import Layer from './Layer';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Class use to display a WMS layer.
|
|
6
|
-
*
|
|
7
|
-
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
8
|
-
* @extends {Layer}
|
|
9
|
-
*/
|
|
10
|
-
class WMSLayer extends Layer {
|
|
11
|
-
/**
|
|
12
|
-
* @override
|
|
13
|
-
*/
|
|
14
|
-
constructor(options = {}) {
|
|
15
|
-
super(options);
|
|
16
|
-
|
|
17
|
-
/** @ignore */
|
|
18
|
-
this.abortController = new AbortController();
|
|
19
|
-
/** @ignore */
|
|
20
|
-
this.format = new GeoJSON();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Get features infos' Url.
|
|
25
|
-
* @param {ol/coordinate~Coordinate} coord
|
|
26
|
-
* @return {ol/layer/Layer~Layer}
|
|
27
|
-
*/
|
|
28
|
-
getFeatureInfoUrl(coord) {
|
|
29
|
-
const projection = this.map.getView().getProjection();
|
|
30
|
-
const resolution = this.map.getView().getResolution();
|
|
31
|
-
|
|
32
|
-
if (this.olLayer.getSource().getFeatureInfoUrl) {
|
|
33
|
-
return this.olLayer
|
|
34
|
-
.getSource()
|
|
35
|
-
.getFeatureInfoUrl(coord, resolution, projection, {
|
|
36
|
-
info_format: 'application/json',
|
|
37
|
-
query_layers: this.olLayer.getSource().getParams().layers,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Request feature information for a given coordinate.
|
|
45
|
-
* @param {ol/coordinate~Coordinate} coordinate to request the information at.
|
|
46
|
-
* @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
|
|
47
|
-
*/
|
|
48
|
-
getFeatureInfoAtCoordinate(coordinate) {
|
|
49
|
-
this.abortController.abort();
|
|
50
|
-
this.abortController = new AbortController();
|
|
51
|
-
const { signal } = this.abortController;
|
|
52
|
-
return fetch(this.getFeatureInfoUrl(coordinate), { signal })
|
|
53
|
-
.then((resp) => resp.json())
|
|
54
|
-
.then((r) => r.features)
|
|
55
|
-
.then((data) => ({
|
|
56
|
-
layer: this,
|
|
57
|
-
coordinate,
|
|
58
|
-
features: data.map((d) => this.format.readFeature(d)),
|
|
59
|
-
}))
|
|
60
|
-
.catch(() =>
|
|
61
|
-
// resolve an empty feature array something fails
|
|
62
|
-
Promise.resolve({
|
|
63
|
-
features: [],
|
|
64
|
-
coordinate,
|
|
65
|
-
layer: this,
|
|
66
|
-
}),
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Create a copy of the WMSLayer.
|
|
72
|
-
* @param {Object} newOptions Options to override
|
|
73
|
-
* @return {WMSLayer} A WMSLayer
|
|
74
|
-
*/
|
|
75
|
-
clone(newOptions) {
|
|
76
|
-
return new WMSLayer({ ...this.options, ...newOptions });
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export default WMSLayer;
|