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
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { inView } from "ol/layer/Layer";
|
|
2
|
+
import Control from "../../common/controls/Control";
|
|
3
|
+
import mixin from "../../common/mixins/CopyrightMixin";
|
|
4
|
+
import removeDuplicate from "../../common/utils/removeDuplicate";
|
|
5
|
+
class CopyrightControl extends mixin(Control) {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super(options);
|
|
8
|
+
this.onPostRender = this.onPostRender.bind(this);
|
|
9
|
+
}
|
|
10
|
+
getCopyrights() {
|
|
11
|
+
if (!this.frameState) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
let copyrights = [];
|
|
15
|
+
this.frameState.layerStatesArray.forEach((layerState) => {
|
|
16
|
+
const { layer } = layerState;
|
|
17
|
+
if (inView(layerState, this.frameState.viewState) && layer && layer.getSource && layer.getSource() && layer.getSource().getAttributions()) {
|
|
18
|
+
copyrights = copyrights.concat(layer.getSource().getAttributions()(this.frameState));
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return removeDuplicate(copyrights);
|
|
22
|
+
}
|
|
23
|
+
activate() {
|
|
24
|
+
super.activate();
|
|
25
|
+
if (this.map) {
|
|
26
|
+
this.map.on("postrender", this.onPostRender);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
deactivate() {
|
|
30
|
+
if (this.map) {
|
|
31
|
+
this.map.un("postrender", this.onPostRender);
|
|
32
|
+
}
|
|
33
|
+
super.deactivate();
|
|
34
|
+
}
|
|
35
|
+
onPostRender(evt) {
|
|
36
|
+
if (this.map && this.element) {
|
|
37
|
+
this.frameState = evt.frameState;
|
|
38
|
+
this.render();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export default CopyrightControl;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import View from "ol/View";
|
|
2
|
+
import Tile from "ol/Tile";
|
|
3
|
+
import TileLayer from "ol/layer/Tile";
|
|
4
|
+
import TileSource from "ol/source/Tile";
|
|
5
|
+
import { createXYZ } from "ol/tilegrid";
|
|
6
|
+
import { Map } from "ol";
|
|
7
|
+
import Layer from "../layers/Layer";
|
|
8
|
+
import CopyrightControl from "./CopyrightControl";
|
|
9
|
+
const tileLoadFunction = () => {
|
|
10
|
+
const tile = new Tile([0, 0, -1], 2);
|
|
11
|
+
tile.getImage = () => {
|
|
12
|
+
const image = new Image();
|
|
13
|
+
image.width = 256;
|
|
14
|
+
image.height = 256;
|
|
15
|
+
return image;
|
|
16
|
+
};
|
|
17
|
+
return tile;
|
|
18
|
+
};
|
|
19
|
+
const getOLTileLayer = () => {
|
|
20
|
+
const layer = new TileLayer({
|
|
21
|
+
source: new TileSource({
|
|
22
|
+
projection: "EPSG:3857",
|
|
23
|
+
tileGrid: createXYZ()
|
|
24
|
+
})
|
|
25
|
+
});
|
|
26
|
+
layer.getSource().getTile = tileLoadFunction;
|
|
27
|
+
return layer;
|
|
28
|
+
};
|
|
29
|
+
const getLayer = (copyrights, visible = true) => new Layer({
|
|
30
|
+
visible,
|
|
31
|
+
copyrights,
|
|
32
|
+
olLayer: getOLTileLayer()
|
|
33
|
+
});
|
|
34
|
+
describe("CopyrightControl", () => {
|
|
35
|
+
let map;
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
const target = document.createElement("div");
|
|
38
|
+
document.body.appendChild(target);
|
|
39
|
+
map = new Map({
|
|
40
|
+
target,
|
|
41
|
+
view: new View({
|
|
42
|
+
center: [0, 0],
|
|
43
|
+
zoom: 0
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
getLayer(true, "bar").attachToMap(map);
|
|
47
|
+
map.setSize([200, 200]);
|
|
48
|
+
map.renderSync();
|
|
49
|
+
});
|
|
50
|
+
afterEach(() => {
|
|
51
|
+
if (map) {
|
|
52
|
+
map.setTarget(null);
|
|
53
|
+
map = null;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
test("should be activate by default", () => {
|
|
57
|
+
const control = new CopyrightControl();
|
|
58
|
+
expect(control.active).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
test("renders a string copyright", () => {
|
|
61
|
+
const control = new CopyrightControl();
|
|
62
|
+
control.attachToMap(map);
|
|
63
|
+
expect(control.element.innerHTML).toBe("");
|
|
64
|
+
getLayer("copyright").attachToMap(map);
|
|
65
|
+
map.renderSync();
|
|
66
|
+
expect(control.element.innerHTML).toBe("copyright");
|
|
67
|
+
});
|
|
68
|
+
test("renders an array of copyrights", () => {
|
|
69
|
+
const control = new CopyrightControl();
|
|
70
|
+
control.attachToMap(map);
|
|
71
|
+
expect(control.element.innerHTML).toBe("");
|
|
72
|
+
getLayer(["copyright 1", "copyright 2"]).attachToMap(map);
|
|
73
|
+
map.renderSync();
|
|
74
|
+
expect(control.element.innerHTML).toBe("copyright 1 | copyright 2");
|
|
75
|
+
});
|
|
76
|
+
test("renders unique copyrights", () => {
|
|
77
|
+
const control = new CopyrightControl();
|
|
78
|
+
control.attachToMap(map);
|
|
79
|
+
expect(control.element.innerHTML).toBe("");
|
|
80
|
+
getLayer(["copyright 1", "copyright 2"]).attachToMap(map);
|
|
81
|
+
getLayer("copyright 1").attachToMap(map);
|
|
82
|
+
getLayer(["copyright 2"]).attachToMap(map);
|
|
83
|
+
map.renderSync();
|
|
84
|
+
expect(control.element.innerHTML).toBe("copyright 1 | copyright 2");
|
|
85
|
+
});
|
|
86
|
+
test("doesn't render copyright of an hidden layer", () => {
|
|
87
|
+
const control = new CopyrightControl();
|
|
88
|
+
control.attachToMap(map);
|
|
89
|
+
expect(control.element.innerHTML).toBe("");
|
|
90
|
+
const layer1 = getLayer("copyright hidden", false);
|
|
91
|
+
layer1.attachToMap(map);
|
|
92
|
+
const layer2 = getLayer("copyright", true);
|
|
93
|
+
layer2.attachToMap(map);
|
|
94
|
+
map.renderSync();
|
|
95
|
+
expect(control.element.innerHTML).toBe("copyright");
|
|
96
|
+
layer1.setVisible(true);
|
|
97
|
+
map.renderSync();
|
|
98
|
+
layer2.setVisible(false);
|
|
99
|
+
map.renderSync();
|
|
100
|
+
expect(control.element.innerHTML).toBe("copyright hidden");
|
|
101
|
+
});
|
|
102
|
+
test("should activate the control on construction then deactivate it", () => {
|
|
103
|
+
getLayer("copyright 1").attachToMap(map);
|
|
104
|
+
const control = new CopyrightControl({ active: true });
|
|
105
|
+
control.attachToMap(map);
|
|
106
|
+
map.renderSync();
|
|
107
|
+
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
108
|
+
expect(control.active).toBe(true);
|
|
109
|
+
expect(control.element.innerHTML).toBe("copyright 1");
|
|
110
|
+
control.active = false;
|
|
111
|
+
map.renderSync();
|
|
112
|
+
expect(control.element.innerHTML).toBe("");
|
|
113
|
+
});
|
|
114
|
+
test("should deactivate the control on constrcution then activate it", () => {
|
|
115
|
+
getLayer("copyright 1").attachToMap(map);
|
|
116
|
+
const control = new CopyrightControl({ active: false });
|
|
117
|
+
control.attachToMap(map);
|
|
118
|
+
map.renderSync();
|
|
119
|
+
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
120
|
+
expect(control.active).toBe(false);
|
|
121
|
+
map.renderSync();
|
|
122
|
+
expect(control.element.innerHTML).toBe("");
|
|
123
|
+
control.active = true;
|
|
124
|
+
map.renderSync();
|
|
125
|
+
expect(control.element.innerHTML).toBe("copyright 1");
|
|
126
|
+
});
|
|
127
|
+
test("should add copyrights in the map container element then remove it.", () => {
|
|
128
|
+
getLayer("copyright value").attachToMap(map);
|
|
129
|
+
map.renderSync();
|
|
130
|
+
const control = new CopyrightControl();
|
|
131
|
+
control.attachToMap(map);
|
|
132
|
+
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
133
|
+
control.detachFromMap();
|
|
134
|
+
expect(control.element.parentNode).toBe(null);
|
|
135
|
+
});
|
|
136
|
+
test("should add copyrights in the target element then remove it.", () => {
|
|
137
|
+
getLayer(["copyright value"]).attachToMap(map);
|
|
138
|
+
map.renderSync();
|
|
139
|
+
const target = document.createElement("div");
|
|
140
|
+
target.setAttribute("id", "copyright");
|
|
141
|
+
document.body.appendChild(target);
|
|
142
|
+
const control = new CopyrightControl({
|
|
143
|
+
target: document.getElementById("copyright")
|
|
144
|
+
});
|
|
145
|
+
control.attachToMap(map);
|
|
146
|
+
expect(control.element.parentNode).toBe(target);
|
|
147
|
+
control.detachFromMap();
|
|
148
|
+
expect(control.element.parentNode).toBe(null);
|
|
149
|
+
});
|
|
150
|
+
test("renders custom copyrights with the render method ", () => {
|
|
151
|
+
const control = new CopyrightControl({
|
|
152
|
+
active: true,
|
|
153
|
+
render() {
|
|
154
|
+
if (!this.element) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this.element.innerHTML = this.active ? this.getCopyrights().join(", ") : "";
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
control.attachToMap(map);
|
|
161
|
+
getLayer(["copyright 1", "copyright 2", "copyright 3"]).attachToMap(map);
|
|
162
|
+
map.renderSync();
|
|
163
|
+
expect(control.element.innerHTML).toBe("copyright 1, copyright 2, copyright 3");
|
|
164
|
+
});
|
|
165
|
+
});
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { Feature } from "ol";
|
|
2
|
+
import { LineString, Point } from "ol/geom";
|
|
3
|
+
import { Modify } from "ol/interaction";
|
|
4
|
+
import { unByKey } from "ol/Observable";
|
|
5
|
+
import { click } from "ol/events/condition";
|
|
6
|
+
import { GeoJSON } from "ol/format";
|
|
7
|
+
import { buffer } from "ol/extent";
|
|
8
|
+
import { fromLonLat, toLonLat } from "ol/proj";
|
|
9
|
+
import { RoutingAPI } from "../../api";
|
|
10
|
+
import Control from "../../common/controls/Control";
|
|
11
|
+
import RoutingLayer from "../layers/RoutingLayer";
|
|
12
|
+
const REGEX_VIA_POINT = /^([^@$!\n]*)(@?([\d.]+),([\d.]+))?(\$?([a-zA-Z0-9]{0,2}))$/;
|
|
13
|
+
const REGEX_VIA_POINT_COORD = /^([\d.]+),([\d.]+)$/;
|
|
14
|
+
const REGEX_VIA_POINT_STATION_ID = /^!([^$]*)(\$?([a-zA-Z0-9]{0,2}))$/;
|
|
15
|
+
const STOP_FETCH_ABORT_CONTROLLER_KEY = "stop-fetch";
|
|
16
|
+
const getFlatCoordinatesFromSegments = (segmentArray) => {
|
|
17
|
+
const coords = [];
|
|
18
|
+
segmentArray.forEach((seg) => {
|
|
19
|
+
coords.push(...seg.getGeometry().getCoordinates());
|
|
20
|
+
});
|
|
21
|
+
return coords;
|
|
22
|
+
};
|
|
23
|
+
class RoutingControl extends Control {
|
|
24
|
+
constructor(options = {}) {
|
|
25
|
+
super(options);
|
|
26
|
+
Object.defineProperties(this, {
|
|
27
|
+
mot: {
|
|
28
|
+
get: () => this.get("mot"),
|
|
29
|
+
set: (newMot) => {
|
|
30
|
+
if (newMot) {
|
|
31
|
+
this.set("mot", newMot);
|
|
32
|
+
if (this.viaPoints) {
|
|
33
|
+
this.drawRoute();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
loading: {
|
|
39
|
+
get: () => this.get("loading"),
|
|
40
|
+
set: (newLoading) => {
|
|
41
|
+
this.set("loading", newLoading);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
modify: {
|
|
45
|
+
get: () => this.get("modify"),
|
|
46
|
+
set: (modify) => {
|
|
47
|
+
this.set("modify", modify);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
this.loading = false;
|
|
52
|
+
this.graphs = options.graphs || [["osm", 0, 99]];
|
|
53
|
+
this.mot = options.mot || "bus";
|
|
54
|
+
this.modify = options.modify !== false;
|
|
55
|
+
this.routingApiParams = options.routingApiParams || {};
|
|
56
|
+
this.useRawViaPoints = options.useRawViaPoints || false;
|
|
57
|
+
this.snapToClosestStation = options.snapToClosestStation || false;
|
|
58
|
+
this.cacheStationData = {};
|
|
59
|
+
this.abortControllers = [];
|
|
60
|
+
this.apiKey = options.apiKey;
|
|
61
|
+
this.stopsApiKey = options.stopsApiKey || this.apiKey;
|
|
62
|
+
this.segments = [];
|
|
63
|
+
this.stopsApiUrl = options.stopsApiUrl || "https://api.geops.io/stops/v1/";
|
|
64
|
+
this.api = new RoutingAPI({
|
|
65
|
+
...options
|
|
66
|
+
});
|
|
67
|
+
this.routingLayer = options.routingLayer || new RoutingLayer({
|
|
68
|
+
name: "routing-layer",
|
|
69
|
+
style: options.style
|
|
70
|
+
});
|
|
71
|
+
this.onRouteError = options.onRouteError || ((error) => {
|
|
72
|
+
this.dispatchEvent({
|
|
73
|
+
type: "change:route",
|
|
74
|
+
target: this
|
|
75
|
+
});
|
|
76
|
+
this.reset();
|
|
77
|
+
console.error(error);
|
|
78
|
+
});
|
|
79
|
+
this.viaPoints = [];
|
|
80
|
+
this.onMapClick = this.onMapClick.bind(this);
|
|
81
|
+
this.onModifyEnd = this.onModifyEnd.bind(this);
|
|
82
|
+
this.onModifyStart = this.onModifyStart.bind(this);
|
|
83
|
+
this.apiChangeListener = () => this.drawRoute();
|
|
84
|
+
this.createModifyInteraction();
|
|
85
|
+
}
|
|
86
|
+
static getGraphsResolutions(graphs, map) {
|
|
87
|
+
const view = map.getView();
|
|
88
|
+
return graphs.map(([, minZoom, maxZoom]) => [
|
|
89
|
+
view.getResolutionForZoom(minZoom),
|
|
90
|
+
view.getResolutionForZoom(maxZoom || minZoom + 1)
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
addViaPoint(coordinatesOrString, index = this.viaPoints.length, overwrite = 0) {
|
|
94
|
+
this.viaPoints.splice(index, overwrite, coordinatesOrString);
|
|
95
|
+
this.drawRoute();
|
|
96
|
+
this.dispatchEvent({
|
|
97
|
+
type: "change:route",
|
|
98
|
+
target: this
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
removeViaPoint(index = this.viaPoints.length - 1) {
|
|
102
|
+
if (this.viaPoints.length && this.viaPoints[index]) {
|
|
103
|
+
this.viaPoints.splice(index, 1);
|
|
104
|
+
}
|
|
105
|
+
this.drawRoute();
|
|
106
|
+
this.dispatchEvent({
|
|
107
|
+
type: "change:route",
|
|
108
|
+
target: this
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
setViaPoints(coordinateArray) {
|
|
112
|
+
this.viaPoints = [...coordinateArray];
|
|
113
|
+
this.drawRoute();
|
|
114
|
+
this.dispatchEvent({
|
|
115
|
+
type: "change:route",
|
|
116
|
+
target: this
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
reset() {
|
|
120
|
+
this.abortRequests();
|
|
121
|
+
this.viaPoints = [];
|
|
122
|
+
this.routingLayer.olLayer.getSource().clear();
|
|
123
|
+
this.dispatchEvent({
|
|
124
|
+
type: "change:route",
|
|
125
|
+
target: this
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
abortRequests() {
|
|
129
|
+
this.graphs.forEach(([graph]) => {
|
|
130
|
+
if (this.abortControllers[graph]) {
|
|
131
|
+
this.abortControllers[graph].abort();
|
|
132
|
+
}
|
|
133
|
+
this.abortControllers[graph] = new AbortController();
|
|
134
|
+
});
|
|
135
|
+
this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]?.abort();
|
|
136
|
+
this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY] = new AbortController();
|
|
137
|
+
this.loading = false;
|
|
138
|
+
}
|
|
139
|
+
drawRoute() {
|
|
140
|
+
this.abortRequests();
|
|
141
|
+
this.routingLayer.olLayer.getSource().clear();
|
|
142
|
+
if (!this.viaPoints.length) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
if (this.viaPoints.length === 1) {
|
|
146
|
+
return this.drawViaPoint(this.viaPoints[0], 0, this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]);
|
|
147
|
+
}
|
|
148
|
+
const formattedViaPoints = this.viaPoints.map((viaPoint) => {
|
|
149
|
+
if (Array.isArray(viaPoint)) {
|
|
150
|
+
const projection = this.map.getView().getProjection();
|
|
151
|
+
const [lon, lat] = toLonLat(viaPoint, projection);
|
|
152
|
+
return this.snapToClosestStation ? [`@${lat}`, lon] : [lat, lon];
|
|
153
|
+
}
|
|
154
|
+
return this.useRawViaPoints ? viaPoint : `!${viaPoint}`;
|
|
155
|
+
});
|
|
156
|
+
this.loading = true;
|
|
157
|
+
this.routingLayer.olLayer.getSource().clear();
|
|
158
|
+
this.viaPoints.forEach((viaPoint, idx) => this.drawViaPoint(viaPoint, idx, this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]));
|
|
159
|
+
return Promise.all(this.graphs.map(([graph], index) => {
|
|
160
|
+
return this.api.route({
|
|
161
|
+
graph,
|
|
162
|
+
via: `${formattedViaPoints.join("|")}`,
|
|
163
|
+
mot: `${this.mot}`,
|
|
164
|
+
"resolve-hops": false,
|
|
165
|
+
elevation: false,
|
|
166
|
+
"coord-radius": 100,
|
|
167
|
+
"coord-punish": 1e3,
|
|
168
|
+
...this.routingApiParams
|
|
169
|
+
}, this.abortControllers[graph]).then((featureCollection) => {
|
|
170
|
+
this.segments = this.format.readFeatures(featureCollection);
|
|
171
|
+
if (this.mot === "foot") {
|
|
172
|
+
const uniqueVias = this.segments.reduce((resultVias, currentFeat) => {
|
|
173
|
+
const segTrg = currentFeat.get("trg");
|
|
174
|
+
return resultVias.find((via) => via[0] === segTrg[0] && via[1] === segTrg[1]) ? resultVias : [...resultVias, segTrg];
|
|
175
|
+
}, []);
|
|
176
|
+
this.segments = uniqueVias.map((via) => {
|
|
177
|
+
const viaSegments = this.segments.filter((seg) => {
|
|
178
|
+
const segTrg = seg.get("trg");
|
|
179
|
+
return segTrg[0] === via[0] && segTrg[1] === via[1];
|
|
180
|
+
});
|
|
181
|
+
const coords2 = getFlatCoordinatesFromSegments(viaSegments);
|
|
182
|
+
return new Feature({
|
|
183
|
+
geometry: new LineString(coords2)
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
const coords = getFlatCoordinatesFromSegments(this.segments);
|
|
188
|
+
const routeFeature = new Feature({
|
|
189
|
+
geometry: new LineString(coords)
|
|
190
|
+
});
|
|
191
|
+
routeFeature.set("graph", graph);
|
|
192
|
+
routeFeature.set("mot", this.mot);
|
|
193
|
+
routeFeature.set("minResolution", this.graphsResolutions[index][0]);
|
|
194
|
+
routeFeature.set("maxResolution", this.graphsResolutions[index][1]);
|
|
195
|
+
this.routingLayer.olLayer.getSource().addFeature(routeFeature);
|
|
196
|
+
this.loading = false;
|
|
197
|
+
}).catch((error) => {
|
|
198
|
+
if (error.name === "AbortError") {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
this.segments = [];
|
|
202
|
+
this.dispatchEvent({
|
|
203
|
+
type: "error",
|
|
204
|
+
target: this
|
|
205
|
+
});
|
|
206
|
+
this.onRouteError(error, this);
|
|
207
|
+
this.loading = false;
|
|
208
|
+
});
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
211
|
+
drawViaPoint(viaPoint, idx, abortController) {
|
|
212
|
+
const pointFeature = new Feature();
|
|
213
|
+
pointFeature.set("viaPointIdx", idx);
|
|
214
|
+
if (Array.isArray(viaPoint)) {
|
|
215
|
+
pointFeature.setGeometry(new Point(viaPoint));
|
|
216
|
+
this.routingLayer.olLayer.getSource().addFeature(pointFeature);
|
|
217
|
+
return Promise.resolve(pointFeature);
|
|
218
|
+
}
|
|
219
|
+
if (!this.useRawViaPoints || REGEX_VIA_POINT_STATION_ID.test(viaPoint)) {
|
|
220
|
+
let stationId;
|
|
221
|
+
let track2;
|
|
222
|
+
if (this.useRawViaPoints) {
|
|
223
|
+
[, stationId, , track2] = REGEX_VIA_POINT_STATION_ID.exec(viaPoint);
|
|
224
|
+
} else {
|
|
225
|
+
[stationId, track2] = viaPoint.split("$");
|
|
226
|
+
}
|
|
227
|
+
return fetch(`${this.stopsApiUrl}lookup/${stationId}?key=${this.stopsApiKey}`, { signal: abortController.signal }).then((res) => res.json()).then((stationData) => {
|
|
228
|
+
const { coordinates } = stationData.features[0].geometry;
|
|
229
|
+
this.cacheStationData[viaPoint] = fromLonLat(coordinates);
|
|
230
|
+
pointFeature.set("viaPointTrack", track2);
|
|
231
|
+
pointFeature.setGeometry(new Point(fromLonLat(coordinates)));
|
|
232
|
+
this.routingLayer.olLayer.getSource().addFeature(pointFeature);
|
|
233
|
+
return pointFeature;
|
|
234
|
+
}).catch((error) => {
|
|
235
|
+
if (error.name === "AbortError") {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
this.dispatchEvent({
|
|
239
|
+
type: "error",
|
|
240
|
+
target: this
|
|
241
|
+
});
|
|
242
|
+
this.onRouteError(error, this);
|
|
243
|
+
this.loading = false;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
if (this.useRawViaPoints && REGEX_VIA_POINT_COORD.test(viaPoint)) {
|
|
247
|
+
const [lat2, lon2] = REGEX_VIA_POINT_COORD.exec(viaPoint);
|
|
248
|
+
const coordinates = fromLonLat([parseFloat(lon2), parseFloat(lat2)], this.map.getView().getProjection());
|
|
249
|
+
pointFeature.setGeometry(new Point(coordinates));
|
|
250
|
+
this.routingLayer.olLayer.getSource().addFeature(pointFeature);
|
|
251
|
+
return Promise.resolve(pointFeature);
|
|
252
|
+
}
|
|
253
|
+
const [, stationName, , lat, lon, , track] = REGEX_VIA_POINT.exec(viaPoint);
|
|
254
|
+
if (lon && lat) {
|
|
255
|
+
const coordinates = fromLonLat([parseFloat(lon), parseFloat(lat)], this.map.getView().getProjection());
|
|
256
|
+
pointFeature.set("viaPointTrack", track);
|
|
257
|
+
pointFeature.setGeometry(new Point(coordinates));
|
|
258
|
+
this.routingLayer.olLayer.getSource().addFeature(pointFeature);
|
|
259
|
+
return Promise.resolve(pointFeature);
|
|
260
|
+
}
|
|
261
|
+
if (stationName) {
|
|
262
|
+
return fetch(`${this.stopsApiUrl}?key=${this.stopsApiKey}&q=${stationName}&limit=1`, { signal: abortController.signal }).then((res) => res.json()).then((stationData) => {
|
|
263
|
+
const { coordinates } = stationData.features[0].geometry;
|
|
264
|
+
this.cacheStationData[viaPoint] = fromLonLat(coordinates);
|
|
265
|
+
pointFeature.set("viaPointTrack", track);
|
|
266
|
+
pointFeature.setGeometry(new Point(fromLonLat(coordinates)));
|
|
267
|
+
this.routingLayer.olLayer.getSource().addFeature(pointFeature);
|
|
268
|
+
return pointFeature;
|
|
269
|
+
}).catch((error) => {
|
|
270
|
+
this.dispatchEvent({
|
|
271
|
+
type: "error",
|
|
272
|
+
target: this
|
|
273
|
+
});
|
|
274
|
+
this.onRouteError(error, this);
|
|
275
|
+
this.loading = false;
|
|
276
|
+
return null;
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
return Promise.resolve(null);
|
|
280
|
+
}
|
|
281
|
+
onMapClick(e) {
|
|
282
|
+
const feats = e.target.getFeaturesAtPixel(e.pixel);
|
|
283
|
+
const viaPoint = feats.find((feat) => feat.getGeometry() instanceof Point && feat.get("viaPointIdx") !== void 0);
|
|
284
|
+
if (viaPoint) {
|
|
285
|
+
this.removeViaPoint(viaPoint.get("viaPointIdx"));
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
this.addViaPoint(e.coordinate);
|
|
289
|
+
}
|
|
290
|
+
onModifyStart(evt) {
|
|
291
|
+
let segmentIndex = -1;
|
|
292
|
+
const route = evt.features.getArray().find((feat) => feat.getGeometry() instanceof LineString);
|
|
293
|
+
if (route) {
|
|
294
|
+
const closestExtent = buffer(new Point(route.getGeometry().getClosestPoint(evt.mapBrowserEvent.coordinate)).getExtent(), 1e-3);
|
|
295
|
+
segmentIndex = this.segments.findIndex((segment) => segment.getGeometry().intersectsExtent(closestExtent));
|
|
296
|
+
}
|
|
297
|
+
const viaPoint = (evt.features.getArray().filter((feat) => feat.getGeometry() instanceof Point) || [])[0];
|
|
298
|
+
this.initialRouteDrag = {
|
|
299
|
+
viaPoint,
|
|
300
|
+
oldRoute: route && route.clone(),
|
|
301
|
+
segmentIndex
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
onModifyEnd(evt) {
|
|
305
|
+
const coord = evt.mapBrowserEvent.coordinate;
|
|
306
|
+
const { oldRoute, viaPoint, segmentIndex } = this.initialRouteDrag;
|
|
307
|
+
if (viaPoint) {
|
|
308
|
+
return this.addViaPoint(coord, viaPoint.get("viaPointIdx"), 1);
|
|
309
|
+
}
|
|
310
|
+
if (!oldRoute) {
|
|
311
|
+
return this.addViaPoint(coord, 0, 1);
|
|
312
|
+
}
|
|
313
|
+
if (segmentIndex === -1) {
|
|
314
|
+
return Promise.reject(new Error("No segment found"));
|
|
315
|
+
}
|
|
316
|
+
return this.addViaPoint(coord, segmentIndex + 1);
|
|
317
|
+
}
|
|
318
|
+
createDefaultElement() {
|
|
319
|
+
this.element = document.createElement("button");
|
|
320
|
+
this.element.id = "ol-toggle-routing";
|
|
321
|
+
this.element.innerHTML = "Toggle Route Control";
|
|
322
|
+
this.element.onclick = () => this.active ? this.deactivate() : this.activate();
|
|
323
|
+
Object.assign(this.element.style, {
|
|
324
|
+
position: "absolute",
|
|
325
|
+
right: "10px",
|
|
326
|
+
top: "10px"
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
createModifyInteraction() {
|
|
330
|
+
this.modifyInteraction = new Modify({
|
|
331
|
+
source: this.routingLayer.olLayer.getSource(),
|
|
332
|
+
pixelTolerance: 4,
|
|
333
|
+
hitDetection: this.routingLayer.olLayer,
|
|
334
|
+
deleteCondition: (e) => {
|
|
335
|
+
const feats = e.target.getFeaturesAtPixel(e.pixel, {
|
|
336
|
+
hitTolerance: 5
|
|
337
|
+
});
|
|
338
|
+
const viaPoint = feats.find((feat) => feat.getGeometry() instanceof Point && feat.get("index"));
|
|
339
|
+
if (click(e) && viaPoint) {
|
|
340
|
+
this.removeViaPoint(viaPoint.get("index"));
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
this.modifyInteraction.on("modifystart", this.onModifyStart);
|
|
347
|
+
this.modifyInteraction.on("modifyend", this.onModifyEnd);
|
|
348
|
+
this.modifyInteraction.setActive(false);
|
|
349
|
+
}
|
|
350
|
+
addListeners() {
|
|
351
|
+
if (!this.modify) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
this.removeListeners();
|
|
355
|
+
this.onMapClickKey = this.map.on("singleclick", this.onMapClick);
|
|
356
|
+
}
|
|
357
|
+
removeListeners() {
|
|
358
|
+
unByKey(this.onMapClickKey);
|
|
359
|
+
}
|
|
360
|
+
activate() {
|
|
361
|
+
super.activate();
|
|
362
|
+
if (this.map) {
|
|
363
|
+
this.format = new GeoJSON({
|
|
364
|
+
featureProjection: this.map.getView().getProjection()
|
|
365
|
+
});
|
|
366
|
+
this.graphsResolutions = RoutingControl.getGraphsResolutions(this.graphs, this.map);
|
|
367
|
+
this.map.removeInteraction(this.modifyInteraction);
|
|
368
|
+
this.routingLayer.attachToMap(this.map);
|
|
369
|
+
this.map.addInteraction(this.modifyInteraction);
|
|
370
|
+
this.modifyInteraction.setActive(this.modify);
|
|
371
|
+
this.addListeners();
|
|
372
|
+
} else {
|
|
373
|
+
this.format = new GeoJSON({ featureProjection: "EPSG:3857" });
|
|
374
|
+
this.graphsResolutions = this.graphs;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
deactivate() {
|
|
378
|
+
if (this.map) {
|
|
379
|
+
this.routingLayer.detachFromMap(this.map);
|
|
380
|
+
this.map.removeInteraction(this.modifyInteraction);
|
|
381
|
+
this.removeListeners();
|
|
382
|
+
this.reset();
|
|
383
|
+
}
|
|
384
|
+
super.deactivate();
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
export default RoutingControl;
|