mobility-toolbox-js 2.0.0-beta.34 → 2.0.0-beta.37
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/README.md +14 -8
- package/api/RealtimeAPI.d.ts +6 -6
- package/api/RealtimeAPI.d.ts.map +1 -1
- package/api/RealtimeAPI.js +170 -197
- package/api/RealtimeAPI.test.d.ts +2 -0
- package/api/RealtimeAPI.test.d.ts.map +1 -0
- package/api/RealtimeAPI.test.js +67 -0
- package/api/RoutingAPI.d.ts +6 -2
- package/api/RoutingAPI.d.ts.map +1 -1
- package/api/RoutingAPI.js +8 -38
- package/api/RoutingAPI.test.d.ts +2 -0
- package/api/RoutingAPI.test.d.ts.map +1 -0
- package/api/RoutingAPI.test.js +29 -0
- package/api/StopsAPI.d.ts +1 -1
- package/api/StopsAPI.d.ts.map +1 -1
- package/api/StopsAPI.js +8 -40
- package/api/StopsAPI.test.d.ts +2 -0
- package/api/StopsAPI.test.d.ts.map +1 -0
- package/api/StopsAPI.test.js +26 -0
- package/api/index.d.ts +3 -4
- package/api/index.d.ts.map +1 -1
- package/api/index.js +3 -10
- package/api/typedefs.js +1 -0
- package/common/api/HttpAPI.d.ts +2 -2
- package/common/api/HttpAPI.d.ts.map +1 -1
- package/common/api/HttpAPI.js +21 -48
- package/common/api/HttpAPI.test.d.ts +2 -0
- package/common/api/HttpAPI.test.d.ts.map +1 -0
- package/common/api/HttpAPI.test.js +54 -0
- package/common/api/WebSocketAPI.d.ts +8 -4
- package/common/api/WebSocketAPI.d.ts.map +1 -1
- package/common/api/WebSocketAPI.js +125 -129
- package/common/api/WebSocketAPI.test.d.ts +2 -0
- package/common/api/WebSocketAPI.test.d.ts.map +1 -0
- package/common/api/WebSocketAPI.test.js +380 -0
- package/common/controls/Control.d.ts +5 -5
- package/common/controls/Control.d.ts.map +1 -1
- package/common/controls/Control.js +44 -77
- package/common/controls/Control.test.d.ts +2 -0
- package/common/controls/Control.test.d.ts.map +1 -0
- package/common/controls/Control.test.js +89 -0
- package/common/index.js +2 -18
- package/common/layers/Layer.d.ts +11 -11
- package/common/layers/Layer.d.ts.map +1 -1
- package/common/layers/Layer.js +70 -104
- package/common/layers/Layer.test.d.ts +2 -0
- package/common/layers/Layer.test.d.ts.map +1 -0
- package/common/layers/Layer.test.js +137 -0
- package/common/mixins/CopyrightMixin.js +23 -52
- package/common/mixins/MapboxLayerMixin.js +162 -204
- package/common/mixins/RealtimeLayerMixin.js +580 -635
- package/common/mixins/StopFinderMixin.d.ts +3 -3
- package/common/mixins/StopFinderMixin.d.ts.map +1 -1
- package/common/mixins/StopFinderMixin.js +115 -157
- package/common/mixins/UserInteractionsLayerMixin.js +142 -175
- package/common/mixins/UserInteractionsLayerMixin.test.d.ts +2 -0
- package/common/mixins/UserInteractionsLayerMixin.test.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.test.js +214 -0
- package/common/styles/index.js +4 -24
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -1
- package/common/styles/realtimeDefaultStyle.js +67 -78
- package/common/styles/realtimeDelayStyle.js +4 -17
- package/common/styles/realtimeSimpleStyle.js +5 -7
- package/common/typedefs.js +1 -0
- package/common/utils/cleanStopTime.js +3 -5
- package/common/utils/compareDepartures.d.ts +1 -1
- package/common/utils/compareDepartures.d.ts.map +1 -1
- package/common/utils/compareDepartures.js +8 -11
- package/common/utils/createCanvas.js +3 -5
- package/common/utils/createTrackerFilters.d.ts +1 -1
- package/common/utils/createTrackerFilters.d.ts.map +1 -1
- package/common/utils/createTrackerFilters.js +22 -32
- package/common/utils/createTrackerFilters.test.d.ts +2 -0
- package/common/utils/createTrackerFilters.test.d.ts.map +1 -0
- package/common/utils/createTrackerFilters.test.js +79 -0
- package/common/utils/getLayersAsFlatArray.js +6 -8
- package/common/utils/getMapboxMapCopyrights.js +9 -11
- package/common/utils/getMapboxMapCopyrights.test.d.ts +2 -0
- package/common/utils/getMapboxMapCopyrights.test.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.test.js +40 -0
- package/common/utils/getMapboxRender.js +12 -15
- package/common/utils/getMaplibreRender.js +10 -13
- package/common/utils/getRealtimeModeSuffix.js +2 -6
- package/common/utils/getUrlWithParams.js +5 -8
- package/common/utils/getVehiclePosition.js +20 -23
- package/common/utils/index.js +12 -37
- package/common/utils/removeDuplicate.d.ts +1 -1
- package/common/utils/removeDuplicate.d.ts.map +1 -1
- package/common/utils/removeDuplicate.js +6 -21
- package/common/utils/removeDuplicate.test.d.ts +2 -0
- package/common/utils/removeDuplicate.test.d.ts.map +1 -0
- package/common/utils/removeDuplicate.test.js +19 -0
- package/common/utils/renderTrajectories.js +31 -43
- package/common/utils/sortByDelay.js +4 -6
- package/common/utils/timeUtils.js +14 -24
- package/common/utils/timeUtils.test.d.ts +2 -0
- package/common/utils/timeUtils.test.d.ts.map +1 -0
- package/common/utils/timeUtils.test.js +10 -0
- package/common/utils/trackerConfig.js +27 -39
- package/common/utils/trackerConfig.test.d.ts +2 -0
- package/common/utils/trackerConfig.test.d.ts.map +1 -0
- package/common/utils/trackerConfig.test.js +23 -0
- package/iife.js +3 -5
- package/index.d.ts +4 -0
- package/index.js +9 -10
- package/mapbox/controls/CopyrightControl.d.ts +0 -1
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -1
- package/mapbox/controls/CopyrightControl.js +18 -38
- package/mapbox/controls/index.js +1 -5
- package/mapbox/index.js +4 -20
- package/mapbox/layers/Layer.d.ts +1 -1
- package/mapbox/layers/Layer.d.ts.map +1 -1
- package/mapbox/layers/Layer.js +29 -71
- package/mapbox/layers/Layer.test.d.ts +2 -0
- package/mapbox/layers/Layer.test.d.ts.map +1 -0
- package/mapbox/layers/Layer.test.js +204 -0
- package/mapbox/layers/RealtimeLayer.d.ts +4 -4
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -1
- package/mapbox/layers/RealtimeLayer.js +83 -125
- package/mapbox/layers/RealtimeLayer.test.d.ts +2 -0
- package/mapbox/layers/RealtimeLayer.test.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.test.js +10 -0
- package/mapbox/layers/index.js +2 -7
- package/mapbox/utils.js +19 -33
- package/mbt.js +59 -37
- package/mbt.js.map +2 -2
- package/mbt.min.js +10 -10
- package/mbt.min.js.map +2 -2
- package/ol/controls/CopyrightControl.js +26 -47
- package/ol/controls/CopyrightControl.test.d.ts +2 -0
- package/ol/controls/CopyrightControl.test.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.test.js +177 -0
- package/ol/controls/RoutingControl.d.ts +6 -5
- package/ol/controls/RoutingControl.d.ts.map +1 -1
- package/ol/controls/RoutingControl.js +209 -270
- package/ol/controls/RoutingControl.test.d.ts +2 -0
- package/ol/controls/RoutingControl.test.d.ts.map +1 -0
- package/ol/controls/RoutingControl.test.js +150 -0
- package/ol/controls/StopFinderControl.js +9 -32
- package/ol/controls/StopFinderControl.test.d.ts +2 -0
- package/ol/controls/StopFinderControl.test.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.test.js +49 -0
- package/ol/controls/index.js +3 -9
- package/ol/index.js +5 -21
- package/ol/layers/Layer.d.ts +1 -1
- package/ol/layers/Layer.d.ts.map +1 -1
- package/ol/layers/Layer.js +40 -72
- package/ol/layers/Layer.test.d.ts +2 -0
- package/ol/layers/Layer.test.d.ts.map +1 -0
- package/ol/layers/Layer.test.js +196 -0
- package/ol/layers/MapboxLayer.d.ts +7 -7
- package/ol/layers/MapboxLayer.d.ts.map +1 -1
- package/ol/layers/MapboxLayer.js +30 -66
- package/ol/layers/MapboxLayer.test.d.ts +2 -0
- package/ol/layers/MapboxLayer.test.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.test.js +164 -0
- package/ol/layers/MapboxStyleLayer.d.ts +3 -3
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -1
- package/ol/layers/MapboxStyleLayer.js +92 -135
- package/ol/layers/MapboxStyleLayer.test.d.ts +2 -0
- package/ol/layers/MapboxStyleLayer.test.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.test.js +232 -0
- package/ol/layers/MaplibreLayer.d.ts +1 -1
- package/ol/layers/MaplibreLayer.d.ts.map +1 -1
- package/ol/layers/MaplibreLayer.js +14 -48
- package/ol/layers/RealtimeLayer.d.ts +2 -2
- package/ol/layers/RealtimeLayer.d.ts.map +1 -1
- package/ol/layers/RealtimeLayer.js +111 -147
- package/ol/layers/RealtimeLayer.test.d.ts +2 -0
- package/ol/layers/RealtimeLayer.test.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.test.js +71 -0
- package/ol/layers/RoutingLayer.d.ts +2 -2
- package/ol/layers/RoutingLayer.d.ts.map +1 -1
- package/ol/layers/RoutingLayer.js +29 -61
- package/ol/layers/RoutingLayer.test.d.ts +2 -0
- package/ol/layers/RoutingLayer.test.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.test.js +39 -0
- package/ol/layers/VectorLayer.d.ts +1 -1
- package/ol/layers/VectorLayer.d.ts.map +1 -1
- package/ol/layers/VectorLayer.js +14 -48
- package/ol/layers/VectorLayer.test.d.ts +2 -0
- package/ol/layers/VectorLayer.test.d.ts.map +1 -0
- package/ol/layers/VectorLayer.test.js +87 -0
- package/ol/layers/WMSLayer.d.ts +1 -1
- package/ol/layers/WMSLayer.d.ts.map +1 -1
- package/ol/layers/WMSLayer.js +34 -68
- package/ol/layers/WMSLayer.test.d.ts +2 -0
- package/ol/layers/WMSLayer.test.d.ts.map +1 -0
- package/ol/layers/WMSLayer.test.js +66 -0
- package/ol/layers/index.js +8 -19
- package/ol/styles/fullTrajectoryDelayStyle.js +11 -13
- package/ol/styles/fullTrajectoryStyle.js +16 -18
- package/ol/styles/index.js +2 -7
- package/package.json +5 -2
- package/setupTests.js +12 -14
|
@@ -1,52 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
29
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
30
|
-
if (ar || !(i in from)) {
|
|
31
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
32
|
-
ar[i] = from[i];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
var ol_1 = require("ol");
|
|
39
|
-
var geom_1 = require("ol/geom");
|
|
40
|
-
var interaction_1 = require("ol/interaction");
|
|
41
|
-
var Observable_1 = require("ol/Observable");
|
|
42
|
-
var condition_1 = require("ol/events/condition");
|
|
43
|
-
var format_1 = require("ol/format");
|
|
44
|
-
var extent_1 = require("ol/extent");
|
|
45
|
-
var proj_1 = require("ol/proj");
|
|
46
|
-
var GeometryType_1 = require("ol/geom/GeometryType");
|
|
47
|
-
var api_1 = require("../../api");
|
|
48
|
-
var Control_1 = require("../../common/controls/Control");
|
|
49
|
-
var RoutingLayer_1 = require("../layers/RoutingLayer");
|
|
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 GeomType from 'ol/geom/GeometryType';
|
|
10
|
+
import { RoutingAPI } from '../../api';
|
|
11
|
+
import Control from '../../common/controls/Control';
|
|
12
|
+
import RoutingLayer from '../layers/RoutingLayer';
|
|
50
13
|
// Examples for a single hop:
|
|
51
14
|
// basel sbb a station named "basel sbb"
|
|
52
15
|
// ZUE, station "Zürich HB" by its common abbreviation
|
|
@@ -55,25 +18,25 @@ var RoutingLayer_1 = require("../layers/RoutingLayer");
|
|
|
55
18
|
// @47.37811,8.53935$4 track 4 in a station at position 47.37811, 8.53935
|
|
56
19
|
// zürich hb@47.37811,8.53935$8 track 8 in station "Zürich HB" at position 47.37811, 8.53935
|
|
57
20
|
/** @private */
|
|
58
|
-
|
|
21
|
+
const REGEX_VIA_POINT = /^([^@$!\n]*)(@?([\d.]+),([\d.]+))?(\$?([a-zA-Z0-9]{0,2}))$/;
|
|
59
22
|
// Examples for a single hop:
|
|
60
23
|
//
|
|
61
24
|
// 47.37811,8.53935 a position 47.37811, 8.53935
|
|
62
25
|
/** @private */
|
|
63
|
-
|
|
26
|
+
const REGEX_VIA_POINT_COORD = /^([\d.]+),([\d.]+)$/;
|
|
64
27
|
// Examples for a single hop:
|
|
65
28
|
//
|
|
66
29
|
// !8596126 a station with id 8596126
|
|
67
30
|
// !8596126$4 a station with id 8596126
|
|
68
31
|
/** @private */
|
|
69
|
-
|
|
32
|
+
const REGEX_VIA_POINT_STATION_ID = /^!([^$]*)(\$?([a-zA-Z0-9]{0,2}))$/;
|
|
70
33
|
/** @private */
|
|
71
|
-
|
|
34
|
+
const STOP_FETCH_ABORT_CONTROLLER_KEY = 'stop-fetch';
|
|
72
35
|
/** @private */
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
segmentArray.forEach(
|
|
76
|
-
coords.push
|
|
36
|
+
const getFlatCoordinatesFromSegments = (segmentArray) => {
|
|
37
|
+
const coords = [];
|
|
38
|
+
segmentArray.forEach((seg) => {
|
|
39
|
+
coords.push(...seg.getGeometry().getCoordinates());
|
|
77
40
|
});
|
|
78
41
|
return coords;
|
|
79
42
|
};
|
|
@@ -108,112 +71,106 @@ var getFlatCoordinatesFromSegments = function (segmentArray) {
|
|
|
108
71
|
* @extends {Control}
|
|
109
72
|
* @implements {RoutingInterface}
|
|
110
73
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
var _this = _super.call(this, options) || this;
|
|
116
|
-
Object.defineProperties(_this, {
|
|
74
|
+
class RoutingControl extends Control {
|
|
75
|
+
constructor(options = {}) {
|
|
76
|
+
super(options);
|
|
77
|
+
Object.defineProperties(this, {
|
|
117
78
|
mot: {
|
|
118
|
-
get:
|
|
119
|
-
set:
|
|
79
|
+
get: () => this.get('mot'),
|
|
80
|
+
set: (newMot) => {
|
|
120
81
|
if (newMot) {
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
|
|
82
|
+
this.set('mot', newMot);
|
|
83
|
+
if (this.viaPoints) {
|
|
84
|
+
this.drawRoute();
|
|
124
85
|
}
|
|
125
86
|
}
|
|
126
87
|
},
|
|
127
88
|
},
|
|
128
89
|
loading: {
|
|
129
|
-
get:
|
|
130
|
-
set:
|
|
131
|
-
|
|
90
|
+
get: () => this.get('loading'),
|
|
91
|
+
set: (newLoading) => {
|
|
92
|
+
this.set('loading', newLoading);
|
|
132
93
|
},
|
|
133
94
|
},
|
|
134
95
|
modify: {
|
|
135
|
-
get:
|
|
136
|
-
set:
|
|
137
|
-
|
|
96
|
+
get: () => this.get('modify'),
|
|
97
|
+
set: (modify) => {
|
|
98
|
+
this.set('modify', modify);
|
|
138
99
|
},
|
|
139
100
|
},
|
|
140
101
|
});
|
|
141
102
|
/** True if the control is requesting the backend. */
|
|
142
|
-
|
|
103
|
+
this.loading = false;
|
|
143
104
|
/** @ignore */
|
|
144
|
-
|
|
105
|
+
this.graphs = options.graphs || [['osm', 0, 99]];
|
|
145
106
|
/** @ignore */
|
|
146
|
-
|
|
107
|
+
this.mot = options.mot || 'bus';
|
|
147
108
|
/** @ignore */
|
|
148
|
-
|
|
109
|
+
this.modify = options.modify !== false;
|
|
149
110
|
/** @ignore */
|
|
150
|
-
|
|
111
|
+
this.routingApiParams = options.routingApiParams || {};
|
|
151
112
|
/** @ignore */
|
|
152
|
-
|
|
113
|
+
this.useRawViaPoints = options.useRawViaPoints || false;
|
|
153
114
|
/** @ignore */
|
|
154
|
-
|
|
115
|
+
this.snapToClosestStation = options.snapToClosestStation || false;
|
|
155
116
|
/** @ignore */
|
|
156
|
-
|
|
117
|
+
this.cacheStationData = {};
|
|
157
118
|
/** @ignore */
|
|
158
|
-
|
|
119
|
+
this.abortControllers = [];
|
|
159
120
|
/** @ignore */
|
|
160
|
-
|
|
121
|
+
this.apiKey = options.apiKey;
|
|
161
122
|
/** @ignore */
|
|
162
|
-
|
|
123
|
+
this.stopsApiKey = options.stopsApiKey || this.apiKey;
|
|
163
124
|
/** @ignore */
|
|
164
|
-
|
|
125
|
+
this.segments = [];
|
|
165
126
|
/** @ignore */
|
|
166
|
-
|
|
127
|
+
this.stopsApiUrl = options.stopsApiUrl || 'https://api.geops.io/stops/v1/';
|
|
167
128
|
/** @ignore */
|
|
168
|
-
|
|
129
|
+
this.api = new RoutingAPI(Object.assign({}, options));
|
|
169
130
|
/** @ignore */
|
|
170
|
-
|
|
131
|
+
this.routingLayer =
|
|
171
132
|
options.routingLayer ||
|
|
172
|
-
new
|
|
133
|
+
new RoutingLayer({
|
|
173
134
|
name: 'routing-layer',
|
|
174
135
|
style: options.style,
|
|
175
136
|
});
|
|
176
137
|
/** @ignore */
|
|
177
|
-
|
|
138
|
+
this.onRouteError =
|
|
178
139
|
options.onRouteError ||
|
|
179
|
-
(
|
|
180
|
-
|
|
140
|
+
((error) => {
|
|
141
|
+
this.dispatchEvent({
|
|
181
142
|
type: 'change:route',
|
|
182
|
-
target:
|
|
143
|
+
target: this,
|
|
183
144
|
});
|
|
184
|
-
|
|
145
|
+
this.reset();
|
|
185
146
|
// eslint-disable-next-line no-console
|
|
186
147
|
console.error(error);
|
|
187
148
|
});
|
|
188
149
|
/** @ignore */
|
|
189
|
-
|
|
150
|
+
this.viaPoints = [];
|
|
190
151
|
/** @ignore */
|
|
191
|
-
|
|
152
|
+
this.onMapClick = this.onMapClick.bind(this);
|
|
192
153
|
/** @ignore */
|
|
193
|
-
|
|
154
|
+
this.onModifyEnd = this.onModifyEnd.bind(this);
|
|
194
155
|
/** @ignore */
|
|
195
|
-
|
|
156
|
+
this.onModifyStart = this.onModifyStart.bind(this);
|
|
196
157
|
/** @ignore */
|
|
197
|
-
|
|
158
|
+
this.apiChangeListener = () => this.drawRoute();
|
|
198
159
|
/** @ignore */
|
|
199
|
-
|
|
200
|
-
return _this;
|
|
160
|
+
this.createModifyInteraction();
|
|
201
161
|
}
|
|
202
162
|
/**
|
|
203
163
|
* Calculate at which resolutions corresponds each generalizations.
|
|
204
164
|
*
|
|
205
165
|
* @private
|
|
206
166
|
*/
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
return graphs.map(
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
];
|
|
215
|
-
});
|
|
216
|
-
};
|
|
167
|
+
static getGraphsResolutions(graphs, map) {
|
|
168
|
+
const view = map.getView();
|
|
169
|
+
return graphs.map(([, minZoom, maxZoom]) => [
|
|
170
|
+
view.getResolutionForZoom(minZoom),
|
|
171
|
+
view.getResolutionForZoom(maxZoom || minZoom + 1),
|
|
172
|
+
]);
|
|
173
|
+
}
|
|
217
174
|
/**
|
|
218
175
|
* Adds/Replaces a viaPoint to the viaPoints array and redraws route:
|
|
219
176
|
* Adds a viaPoint at end of array by default.
|
|
@@ -224,9 +181,7 @@ var RoutingControl = /** @class */ (function (_super) {
|
|
|
224
181
|
* @param {number} [index=-1] Integer representing the index of the added viaPoint. If not specified, the viaPoint is added at the end of the array.
|
|
225
182
|
* @param {number} [overwrite=0] Marks the number of viaPoints that are removed at the specified index on add.
|
|
226
183
|
*/
|
|
227
|
-
|
|
228
|
-
if (index === void 0) { index = -1; }
|
|
229
|
-
if (overwrite === void 0) { overwrite = 0; }
|
|
184
|
+
addViaPoint(coordinatesOrString, index = -1, overwrite = 0) {
|
|
230
185
|
/* Add/Insert/Overwrite viapoint and redraw route */
|
|
231
186
|
this.viaPoints.splice(index === -1 ? this.viaPoints.length : index, overwrite, coordinatesOrString);
|
|
232
187
|
this.drawRoute();
|
|
@@ -234,14 +189,13 @@ var RoutingControl = /** @class */ (function (_super) {
|
|
|
234
189
|
type: 'change:route',
|
|
235
190
|
target: this,
|
|
236
191
|
});
|
|
237
|
-
}
|
|
192
|
+
}
|
|
238
193
|
/**
|
|
239
194
|
* Removes a viaPoint at the passed array index and redraws route
|
|
240
195
|
* By default the last viaPoint is removed.
|
|
241
196
|
* @param {number} index Integer representing the index of the viaPoint to delete.
|
|
242
197
|
*/
|
|
243
|
-
|
|
244
|
-
if (index === void 0) { index = this.viaPoints.length - 1; }
|
|
198
|
+
removeViaPoint(index = this.viaPoints.length - 1) {
|
|
245
199
|
/* Remove viapoint and redraw route */
|
|
246
200
|
if (this.viaPoints.length && this.viaPoints[index]) {
|
|
247
201
|
this.viaPoints.splice(index, 1);
|
|
@@ -251,23 +205,23 @@ var RoutingControl = /** @class */ (function (_super) {
|
|
|
251
205
|
type: 'change:route',
|
|
252
206
|
target: this,
|
|
253
207
|
});
|
|
254
|
-
}
|
|
208
|
+
}
|
|
255
209
|
/**
|
|
256
210
|
* Replaces the current viaPoints with a new coordinate array.
|
|
257
211
|
* @param {Array<Array<number>>} coordinateArray Array of nested coordinates
|
|
258
212
|
*/
|
|
259
|
-
|
|
260
|
-
this.viaPoints =
|
|
213
|
+
setViaPoints(coordinateArray) {
|
|
214
|
+
this.viaPoints = [...coordinateArray];
|
|
261
215
|
this.drawRoute();
|
|
262
216
|
this.dispatchEvent({
|
|
263
217
|
type: 'change:route',
|
|
264
218
|
target: this,
|
|
265
219
|
});
|
|
266
|
-
}
|
|
220
|
+
}
|
|
267
221
|
/**
|
|
268
222
|
* Removes all viaPoints, clears the source and triggers a change event
|
|
269
223
|
*/
|
|
270
|
-
|
|
224
|
+
reset() {
|
|
271
225
|
// Clear viaPoints and source
|
|
272
226
|
this.abortRequests();
|
|
273
227
|
this.viaPoints = [];
|
|
@@ -276,28 +230,26 @@ var RoutingControl = /** @class */ (function (_super) {
|
|
|
276
230
|
type: 'change:route',
|
|
277
231
|
target: this,
|
|
278
232
|
});
|
|
279
|
-
}
|
|
233
|
+
}
|
|
280
234
|
/**
|
|
281
235
|
* Aborts viapoint and route requests
|
|
282
236
|
* @private
|
|
283
237
|
*/
|
|
284
|
-
|
|
285
|
-
var _this = this;
|
|
238
|
+
abortRequests() {
|
|
286
239
|
var _a;
|
|
287
240
|
// Abort Routing API requests
|
|
288
|
-
this.graphs.forEach(
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
_this.abortControllers[graph].abort();
|
|
241
|
+
this.graphs.forEach(([graph]) => {
|
|
242
|
+
if (this.abortControllers[graph]) {
|
|
243
|
+
this.abortControllers[graph].abort();
|
|
292
244
|
}
|
|
293
|
-
|
|
245
|
+
this.abortControllers[graph] = new AbortController();
|
|
294
246
|
});
|
|
295
247
|
// Abort Stops API requests
|
|
296
248
|
(_a = this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]) === null || _a === void 0 ? void 0 : _a.abort();
|
|
297
249
|
this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY] =
|
|
298
250
|
new AbortController();
|
|
299
251
|
this.loading = false;
|
|
300
|
-
}
|
|
252
|
+
}
|
|
301
253
|
/**
|
|
302
254
|
* Draws route on map using an array of coordinates:
|
|
303
255
|
* If a single coordinate is passed a single point feature is added to map.
|
|
@@ -305,8 +257,7 @@ var RoutingControl = /** @class */ (function (_super) {
|
|
|
305
257
|
* the route using the passed coordinates and the current mot.
|
|
306
258
|
* @private
|
|
307
259
|
*/
|
|
308
|
-
|
|
309
|
-
var _this = this;
|
|
260
|
+
drawRoute() {
|
|
310
261
|
/* Calls RoutingAPI to draw a route using the viaPoints array */
|
|
311
262
|
this.abortRequests();
|
|
312
263
|
this.routingLayer.olLayer.getSource().clear();
|
|
@@ -317,92 +268,87 @@ var RoutingControl = /** @class */ (function (_super) {
|
|
|
317
268
|
// Add point for first node
|
|
318
269
|
return this.drawViaPoint(this.viaPoints[0], 0, this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]);
|
|
319
270
|
}
|
|
320
|
-
|
|
271
|
+
const formattedViaPoints = this.viaPoints.map((viaPoint) => {
|
|
321
272
|
if (Array.isArray(viaPoint)) {
|
|
322
|
-
|
|
273
|
+
const projection = this.map.getView().getProjection();
|
|
323
274
|
// viaPoint is a coordinate
|
|
324
275
|
// Coordinates need to be reversed as required by the backend RoutingAPI
|
|
325
|
-
|
|
326
|
-
return
|
|
276
|
+
const [lon, lat] = toLonLat(viaPoint, projection);
|
|
277
|
+
return this.snapToClosestStation ? [`@${lat}`, lon] : [lat, lon];
|
|
327
278
|
}
|
|
328
279
|
// viaPoint is a string to use as it is
|
|
329
|
-
return
|
|
280
|
+
return this.useRawViaPoints ? viaPoint : `!${viaPoint}`;
|
|
330
281
|
});
|
|
331
282
|
this.loading = true;
|
|
332
283
|
// Clear source
|
|
333
284
|
this.routingLayer.olLayer.getSource().clear();
|
|
334
285
|
// Create point features for the viaPoints
|
|
335
|
-
this.viaPoints.forEach(
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
.then(function (featureCollection) {
|
|
344
|
-
_this.segments = _this.format.readFeatures(featureCollection);
|
|
345
|
-
if (_this.mot === 'foot') {
|
|
286
|
+
this.viaPoints.forEach((viaPoint, idx) => this.drawViaPoint(viaPoint, idx, this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]));
|
|
287
|
+
return Promise.all(this.graphs.map(([graph], index) => {
|
|
288
|
+
const { signal } = this.abortControllers[graph];
|
|
289
|
+
return this.api
|
|
290
|
+
.route(Object.assign({ graph, via: `${formattedViaPoints.join('|')}`, mot: `${this.mot}`, 'resolve-hops': false, elevation: false, 'coord-radius': 100.0, 'coord-punish': 1000.0 }, this.routingApiParams), { signal })
|
|
291
|
+
.then((featureCollection) => {
|
|
292
|
+
this.segments = this.format.readFeatures(featureCollection);
|
|
293
|
+
if (this.mot === 'foot') {
|
|
346
294
|
// Extract unique values from viaPoint target value
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
return resultVias.find(
|
|
295
|
+
const uniqueVias = this.segments.reduce((resultVias, currentFeat) => {
|
|
296
|
+
const segTrg = currentFeat.get('trg');
|
|
297
|
+
return resultVias.find((via) => via[0] === segTrg[0] && via[1] === segTrg[1])
|
|
350
298
|
? resultVias
|
|
351
|
-
:
|
|
299
|
+
: [...resultVias, segTrg];
|
|
352
300
|
}, []);
|
|
353
301
|
// Create LineString features from segments with same unique value
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
302
|
+
this.segments = uniqueVias.map((via) => {
|
|
303
|
+
const viaSegments = this.segments.filter((seg) => {
|
|
304
|
+
const segTrg = seg.get('trg');
|
|
357
305
|
return segTrg[0] === via[0] && segTrg[1] === via[1];
|
|
358
306
|
});
|
|
359
|
-
|
|
360
|
-
return new
|
|
361
|
-
geometry: new
|
|
307
|
+
const coords = getFlatCoordinatesFromSegments(viaSegments);
|
|
308
|
+
return new Feature({
|
|
309
|
+
geometry: new LineString(coords),
|
|
362
310
|
});
|
|
363
311
|
});
|
|
364
312
|
}
|
|
365
313
|
// Create the new route. This route will be modifiable by the Modifiy interaction.
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
geometry: new
|
|
314
|
+
const coords = getFlatCoordinatesFromSegments(this.segments);
|
|
315
|
+
const routeFeature = new Feature({
|
|
316
|
+
geometry: new LineString(coords),
|
|
369
317
|
});
|
|
370
318
|
routeFeature.set('graph', graph);
|
|
371
|
-
routeFeature.set('mot',
|
|
372
|
-
routeFeature.set('minResolution',
|
|
373
|
-
routeFeature.set('maxResolution',
|
|
374
|
-
|
|
375
|
-
|
|
319
|
+
routeFeature.set('mot', this.mot);
|
|
320
|
+
routeFeature.set('minResolution', this.graphsResolutions[index][0]);
|
|
321
|
+
routeFeature.set('maxResolution', this.graphsResolutions[index][1]);
|
|
322
|
+
this.routingLayer.olLayer.getSource().addFeature(routeFeature);
|
|
323
|
+
this.loading = false;
|
|
376
324
|
})
|
|
377
|
-
.catch(
|
|
325
|
+
.catch((error) => {
|
|
378
326
|
if (error.name === 'AbortError') {
|
|
379
327
|
// Ignore abort error
|
|
380
328
|
return;
|
|
381
329
|
}
|
|
382
|
-
|
|
330
|
+
this.segments = [];
|
|
383
331
|
// Dispatch error event and execute error function
|
|
384
|
-
|
|
332
|
+
this.dispatchEvent({
|
|
385
333
|
type: 'error',
|
|
386
|
-
target:
|
|
334
|
+
target: this,
|
|
387
335
|
});
|
|
388
|
-
|
|
389
|
-
|
|
336
|
+
this.onRouteError(error, this);
|
|
337
|
+
this.loading = false;
|
|
390
338
|
});
|
|
391
339
|
}));
|
|
392
|
-
}
|
|
340
|
+
}
|
|
393
341
|
/**
|
|
394
342
|
* Draw a via point. This function can parse all the possibilitiies
|
|
395
343
|
*
|
|
396
344
|
* @private
|
|
397
345
|
*/
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
var _this = this;
|
|
401
|
-
var pointFeature = new ol_1.Feature();
|
|
346
|
+
drawViaPoint(viaPoint, idx, abortController) {
|
|
347
|
+
const pointFeature = new Feature();
|
|
402
348
|
pointFeature.set('viaPointIdx', idx);
|
|
403
349
|
// The via point is a coordinate using the current map's projection
|
|
404
350
|
if (Array.isArray(viaPoint)) {
|
|
405
|
-
pointFeature.setGeometry(new
|
|
351
|
+
pointFeature.setGeometry(new Point(viaPoint));
|
|
406
352
|
this.routingLayer.olLayer.getSource().addFeature(pointFeature);
|
|
407
353
|
return Promise.resolve(pointFeature);
|
|
408
354
|
}
|
|
@@ -411,36 +357,36 @@ var RoutingControl = /** @class */ (function (_super) {
|
|
|
411
357
|
// !8596126 a station with id 8596126
|
|
412
358
|
// !8596126$4 a station with id 8596126
|
|
413
359
|
if (!this.useRawViaPoints || REGEX_VIA_POINT_STATION_ID.test(viaPoint)) {
|
|
414
|
-
|
|
415
|
-
|
|
360
|
+
let stationId;
|
|
361
|
+
let track;
|
|
416
362
|
if (this.useRawViaPoints) {
|
|
417
|
-
|
|
363
|
+
[, stationId, , track] = REGEX_VIA_POINT_STATION_ID.exec(viaPoint);
|
|
418
364
|
}
|
|
419
365
|
else {
|
|
420
|
-
|
|
366
|
+
[stationId, track] = viaPoint.split('$');
|
|
421
367
|
}
|
|
422
|
-
return fetch(
|
|
423
|
-
.then(
|
|
424
|
-
.then(
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
pointFeature.set('viaPointTrack',
|
|
428
|
-
pointFeature.setGeometry(new
|
|
429
|
-
|
|
368
|
+
return fetch(`${this.stopsApiUrl}lookup/${stationId}?key=${this.stopsApiKey}`, { signal: abortController.signal })
|
|
369
|
+
.then((res) => res.json())
|
|
370
|
+
.then((stationData) => {
|
|
371
|
+
const { coordinates } = stationData.features[0].geometry;
|
|
372
|
+
this.cacheStationData[viaPoint] = fromLonLat(coordinates);
|
|
373
|
+
pointFeature.set('viaPointTrack', track);
|
|
374
|
+
pointFeature.setGeometry(new Point(fromLonLat(coordinates)));
|
|
375
|
+
this.routingLayer.olLayer.getSource().addFeature(pointFeature);
|
|
430
376
|
return pointFeature;
|
|
431
377
|
})
|
|
432
|
-
.catch(
|
|
378
|
+
.catch((error) => {
|
|
433
379
|
if (error.name === 'AbortError') {
|
|
434
380
|
// Ignore abort error
|
|
435
381
|
return;
|
|
436
382
|
}
|
|
437
383
|
// Dispatch error event and execute error function
|
|
438
|
-
|
|
384
|
+
this.dispatchEvent({
|
|
439
385
|
type: 'error',
|
|
440
|
-
target:
|
|
386
|
+
target: this,
|
|
441
387
|
});
|
|
442
|
-
|
|
443
|
-
|
|
388
|
+
this.onRouteError(error, this);
|
|
389
|
+
this.loading = false;
|
|
444
390
|
});
|
|
445
391
|
}
|
|
446
392
|
// Only when this.useRawViaPoints is true.
|
|
@@ -448,9 +394,9 @@ var RoutingControl = /** @class */ (function (_super) {
|
|
|
448
394
|
//
|
|
449
395
|
// 47.37811,8.53935 a position 47.37811, 8.53935
|
|
450
396
|
if (this.useRawViaPoints && REGEX_VIA_POINT_COORD.test(viaPoint)) {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
pointFeature.setGeometry(new
|
|
397
|
+
const [lat, lon] = REGEX_VIA_POINT_COORD.exec(viaPoint);
|
|
398
|
+
const coordinates = fromLonLat([parseFloat(lon), parseFloat(lat)], this.map.getView().getProjection());
|
|
399
|
+
pointFeature.setGeometry(new Point(coordinates));
|
|
454
400
|
this.routingLayer.olLayer.getSource().addFeature(pointFeature);
|
|
455
401
|
return Promise.resolve(pointFeature);
|
|
456
402
|
}
|
|
@@ -462,49 +408,49 @@ var RoutingControl = /** @class */ (function (_super) {
|
|
|
462
408
|
// @47.37811,8.53935 a station at position 47.37811, 8.53935
|
|
463
409
|
// @47.37811,8.53935$4 track 4 in a station at position 47.37811, 8.53935
|
|
464
410
|
// zürich hb@47.37811,8.53935$8 track 8 in station "Zürich HB" at position 47.37811, 8.53935
|
|
465
|
-
|
|
411
|
+
const [, stationName, , lat, lon, , track] = REGEX_VIA_POINT.exec(viaPoint);
|
|
466
412
|
if (lon && lat) {
|
|
467
|
-
|
|
413
|
+
const coordinates = fromLonLat([parseFloat(lon), parseFloat(lat)], this.map.getView().getProjection());
|
|
468
414
|
pointFeature.set('viaPointTrack', track);
|
|
469
|
-
pointFeature.setGeometry(new
|
|
415
|
+
pointFeature.setGeometry(new Point(coordinates));
|
|
470
416
|
this.routingLayer.olLayer.getSource().addFeature(pointFeature);
|
|
471
417
|
return Promise.resolve(pointFeature);
|
|
472
418
|
}
|
|
473
419
|
if (stationName) {
|
|
474
|
-
return fetch(
|
|
475
|
-
.then(
|
|
476
|
-
.then(
|
|
477
|
-
|
|
478
|
-
|
|
420
|
+
return fetch(`${this.stopsApiUrl}?key=${this.stopsApiKey}&q=${stationName}&limit=1`, { signal: abortController.signal })
|
|
421
|
+
.then((res) => res.json())
|
|
422
|
+
.then((stationData) => {
|
|
423
|
+
const { coordinates } = stationData.features[0].geometry;
|
|
424
|
+
this.cacheStationData[viaPoint] = fromLonLat(coordinates);
|
|
479
425
|
pointFeature.set('viaPointTrack', track);
|
|
480
|
-
pointFeature.setGeometry(new
|
|
481
|
-
|
|
426
|
+
pointFeature.setGeometry(new Point(fromLonLat(coordinates)));
|
|
427
|
+
this.routingLayer.olLayer.getSource().addFeature(pointFeature);
|
|
482
428
|
return pointFeature;
|
|
483
429
|
})
|
|
484
|
-
.catch(
|
|
430
|
+
.catch((error) => {
|
|
485
431
|
// Dispatch error event and execute error function
|
|
486
|
-
|
|
432
|
+
this.dispatchEvent({
|
|
487
433
|
type: 'error',
|
|
488
|
-
target:
|
|
434
|
+
target: this,
|
|
489
435
|
});
|
|
490
|
-
|
|
491
|
-
|
|
436
|
+
this.onRouteError(error, this);
|
|
437
|
+
this.loading = false;
|
|
492
438
|
return null;
|
|
493
439
|
});
|
|
494
440
|
}
|
|
495
441
|
return Promise.resolve(null);
|
|
496
|
-
}
|
|
442
|
+
}
|
|
497
443
|
/**
|
|
498
444
|
* Used on click on map while control is active:
|
|
499
445
|
* By default adds a viaPoint to the end of array.
|
|
500
446
|
* If an existing viaPoint is clicked removes the clicked viaPoint.
|
|
501
447
|
* @private
|
|
502
448
|
*/
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
449
|
+
onMapClick(e) {
|
|
450
|
+
const feats = e.target.getFeaturesAtPixel(e.pixel);
|
|
451
|
+
const viaPoint = feats.find((feat) => {
|
|
506
452
|
var _a;
|
|
507
|
-
return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) ===
|
|
453
|
+
return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === GeomType.POINT &&
|
|
508
454
|
feat.get('viaPointIdx') !== undefined;
|
|
509
455
|
});
|
|
510
456
|
if (viaPoint) {
|
|
@@ -513,48 +459,46 @@ var RoutingControl = /** @class */ (function (_super) {
|
|
|
513
459
|
return;
|
|
514
460
|
}
|
|
515
461
|
this.addViaPoint(e.coordinate);
|
|
516
|
-
}
|
|
462
|
+
}
|
|
517
463
|
/**
|
|
518
464
|
* Used on start of the modify interaction. Stores relevant data
|
|
519
465
|
* in this.initialRouteDrag object
|
|
520
466
|
* @private
|
|
521
467
|
*/
|
|
522
|
-
|
|
468
|
+
onModifyStart(evt) {
|
|
523
469
|
// When modify start, we search the index of the segment that is modifying.
|
|
524
|
-
|
|
525
|
-
|
|
470
|
+
let segmentIndex = -1;
|
|
471
|
+
const route = evt.features
|
|
526
472
|
.getArray()
|
|
527
|
-
.find(
|
|
473
|
+
.find((feat) => { var _a; return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === GeomType.LINE_STRING; });
|
|
528
474
|
// Find the segment index that is being modified
|
|
529
475
|
if (route) {
|
|
530
476
|
// We use a buff extent to fix floating issues , see https://github.com/openlayers/openlayers/issues/7130#issuecomment-535856422
|
|
531
|
-
|
|
532
|
-
segmentIndex = this.segments.findIndex(
|
|
533
|
-
return segment.getGeometry().intersectsExtent(closestExtent_1);
|
|
534
|
-
});
|
|
477
|
+
const closestExtent = buffer(new Point(route.getGeometry().getClosestPoint(evt.mapBrowserEvent.coordinate)).getExtent(), 0.001);
|
|
478
|
+
segmentIndex = this.segments.findIndex((segment) => segment.getGeometry().intersectsExtent(closestExtent));
|
|
535
479
|
}
|
|
536
480
|
// Find the viaPoint that is being modified
|
|
537
|
-
|
|
481
|
+
const viaPoint = (evt.features
|
|
538
482
|
.getArray()
|
|
539
|
-
.filter(
|
|
483
|
+
.filter((feat) => { var _a; return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === GeomType.POINT; }) ||
|
|
540
484
|
[])[0];
|
|
541
485
|
// Write object with modify info
|
|
542
486
|
/** @ignore */
|
|
543
487
|
this.initialRouteDrag = {
|
|
544
|
-
viaPoint
|
|
488
|
+
viaPoint,
|
|
545
489
|
oldRoute: route && route.clone(),
|
|
546
|
-
segmentIndex
|
|
490
|
+
segmentIndex,
|
|
547
491
|
};
|
|
548
|
-
}
|
|
492
|
+
}
|
|
549
493
|
/**
|
|
550
494
|
* Used on end of the modify interaction. Resolves feature modification:
|
|
551
495
|
* Line drag creates new viaPoint at the final coordinate of drag.
|
|
552
496
|
* Point drag replaces old viaPoint.
|
|
553
497
|
* @private
|
|
554
498
|
*/
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
499
|
+
onModifyEnd(evt) {
|
|
500
|
+
const coord = evt.mapBrowserEvent.coordinate;
|
|
501
|
+
const { oldRoute, viaPoint, segmentIndex } = this.initialRouteDrag;
|
|
558
502
|
// If viaPoint is being relocated overwrite the old viaPoint
|
|
559
503
|
if (viaPoint) {
|
|
560
504
|
return this.addViaPoint(coord, viaPoint.get('viaPointIdx'), 1);
|
|
@@ -569,54 +513,50 @@ var RoutingControl = /** @class */ (function (_super) {
|
|
|
569
513
|
}
|
|
570
514
|
// Insert new viaPoint at the modified segment index + 1
|
|
571
515
|
return this.addViaPoint(coord, segmentIndex + 1);
|
|
572
|
-
}
|
|
516
|
+
}
|
|
573
517
|
/**
|
|
574
518
|
* Define a default element.
|
|
575
519
|
*
|
|
576
520
|
* @private
|
|
577
521
|
*/
|
|
578
|
-
|
|
579
|
-
var _this = this;
|
|
522
|
+
createDefaultElement() {
|
|
580
523
|
/** @ignore */
|
|
581
524
|
this.element = document.createElement('button');
|
|
582
525
|
this.element.id = 'ol-toggle-routing';
|
|
583
526
|
this.element.innerHTML = 'Toggle Route Control';
|
|
584
|
-
this.element.onclick =
|
|
585
|
-
return _this.active ? _this.deactivate() : _this.activate();
|
|
586
|
-
};
|
|
527
|
+
this.element.onclick = () => this.active ? this.deactivate() : this.activate();
|
|
587
528
|
Object.assign(this.element.style, {
|
|
588
529
|
position: 'absolute',
|
|
589
530
|
right: '10px',
|
|
590
531
|
top: '10px',
|
|
591
532
|
});
|
|
592
|
-
}
|
|
533
|
+
}
|
|
593
534
|
/**
|
|
594
535
|
* Create the interaction used to modify vertexes of features.
|
|
595
536
|
* @private
|
|
596
537
|
*/
|
|
597
|
-
|
|
598
|
-
var _this = this;
|
|
538
|
+
createModifyInteraction() {
|
|
599
539
|
/**
|
|
600
540
|
* @type {ol.interaction.Modify}
|
|
601
541
|
* @private
|
|
602
542
|
*/
|
|
603
543
|
// Define and add modify interaction
|
|
604
|
-
this.modifyInteraction = new
|
|
544
|
+
this.modifyInteraction = new Modify({
|
|
605
545
|
source: this.routingLayer.olLayer.getSource(),
|
|
606
546
|
pixelTolerance: 4,
|
|
607
547
|
hitDetection: this.routingLayer.olLayer,
|
|
608
|
-
deleteCondition:
|
|
609
|
-
|
|
548
|
+
deleteCondition: (e) => {
|
|
549
|
+
const feats = e.target.getFeaturesAtPixel(e.pixel, {
|
|
610
550
|
hitTolerance: 5,
|
|
611
551
|
});
|
|
612
|
-
|
|
552
|
+
const viaPoint = feats.find((feat) => {
|
|
613
553
|
var _a;
|
|
614
|
-
return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) ===
|
|
554
|
+
return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === GeomType.POINT &&
|
|
615
555
|
feat.get('index');
|
|
616
556
|
});
|
|
617
|
-
if (
|
|
557
|
+
if (click(e) && viaPoint) {
|
|
618
558
|
// Remove node & viaPoint if an existing viaPoint was clicked
|
|
619
|
-
|
|
559
|
+
this.removeViaPoint(viaPoint.get('index'));
|
|
620
560
|
return true;
|
|
621
561
|
}
|
|
622
562
|
return false;
|
|
@@ -625,31 +565,31 @@ var RoutingControl = /** @class */ (function (_super) {
|
|
|
625
565
|
this.modifyInteraction.on('modifystart', this.onModifyStart);
|
|
626
566
|
this.modifyInteraction.on('modifyend', this.onModifyEnd);
|
|
627
567
|
this.modifyInteraction.setActive(false);
|
|
628
|
-
}
|
|
568
|
+
}
|
|
629
569
|
/**
|
|
630
570
|
* Add click listener to map.
|
|
631
571
|
* @private
|
|
632
572
|
*/
|
|
633
|
-
|
|
573
|
+
addListeners() {
|
|
634
574
|
if (!this.modify) {
|
|
635
575
|
return;
|
|
636
576
|
}
|
|
637
577
|
this.removeListeners();
|
|
638
578
|
/** @ignore */
|
|
639
579
|
this.onMapClickKey = this.map.on('singleclick', this.onMapClick);
|
|
640
|
-
}
|
|
580
|
+
}
|
|
641
581
|
/**
|
|
642
582
|
* Remove click listener from map.
|
|
643
583
|
* @private
|
|
644
584
|
*/
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
|
|
585
|
+
removeListeners() {
|
|
586
|
+
unByKey(this.onMapClickKey);
|
|
587
|
+
}
|
|
588
|
+
activate() {
|
|
589
|
+
super.activate();
|
|
650
590
|
if (this.map) {
|
|
651
591
|
/** @ignore */
|
|
652
|
-
this.format = new
|
|
592
|
+
this.format = new GeoJSON({
|
|
653
593
|
featureProjection: this.map.getView().getProjection(),
|
|
654
594
|
});
|
|
655
595
|
/** @ignore */
|
|
@@ -664,11 +604,11 @@ var RoutingControl = /** @class */ (function (_super) {
|
|
|
664
604
|
}
|
|
665
605
|
else {
|
|
666
606
|
// fall back to some default values if map is not available
|
|
667
|
-
this.format = new
|
|
607
|
+
this.format = new GeoJSON({ featureProjection: 'EPSG:3857' });
|
|
668
608
|
this.graphsResolutions = this.graphs;
|
|
669
609
|
}
|
|
670
|
-
}
|
|
671
|
-
|
|
610
|
+
}
|
|
611
|
+
deactivate() {
|
|
672
612
|
if (this.map) {
|
|
673
613
|
// Remove modify interaction, RoutingLayer, listeners and viaPoints
|
|
674
614
|
this.routingLayer.detachFromMap(this.map);
|
|
@@ -676,8 +616,7 @@ var RoutingControl = /** @class */ (function (_super) {
|
|
|
676
616
|
this.removeListeners();
|
|
677
617
|
this.reset();
|
|
678
618
|
}
|
|
679
|
-
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
exports.default = RoutingControl;
|
|
619
|
+
super.deactivate();
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
export default RoutingControl;
|