mobility-toolbox-js 3.0.0-beta.19 → 3.0.0-beta.20
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/HttpAPI.d.ts +5 -5
- package/api/RealtimeAPI.d.ts +204 -171
- package/api/RealtimeAPI.js +306 -258
- package/api/RoutingAPI.d.ts +4 -4
- package/api/StopsAPI.d.ts +4 -4
- package/api/WebSocketAPI.d.ts +60 -66
- package/api/WebSocketAPI.js +164 -164
- package/api/index.js +1 -1
- package/common/controls/StopFinderControlCommon.d.ts +11 -11
- package/common/controls/StopFinderControlCommon.js +30 -30
- package/common/index.d.ts +1 -1
- package/common/index.js +1 -1
- package/common/mixins/RealtimeLayerMixin.d.ts +149 -155
- package/common/mixins/RealtimeLayerMixin.js +395 -395
- package/common/styles/realtimeDefaultStyle.js +6 -6
- package/common/styles/realtimeHeadingStyle.js +5 -5
- package/common/utils/getMapGlCopyrights.d.ts +1 -1
- package/common/utils/getMapGlCopyrights.js +3 -3
- package/common/utils/getVehiclePosition.d.ts +2 -2
- package/common/utils/getVehiclePosition.js +7 -7
- package/common/utils/renderTrajectories.js +5 -5
- package/common/utils/sortByDelay.js +5 -5
- package/maplibre/layers/RealtimeLayer.d.ts +59 -64
- package/maplibre/layers/RealtimeLayer.js +8 -8
- package/maplibre/utils/getSourceCoordinates.js +5 -5
- package/mbt.js +7205 -7031
- package/mbt.js.map +4 -4
- package/mbt.min.js +25 -25
- package/mbt.min.js.map +4 -4
- package/ol/controls/RoutingControl.d.ts +81 -87
- package/ol/controls/RoutingControl.js +216 -218
- package/ol/layers/Layer.d.ts +9 -9
- package/ol/layers/MaplibreLayer.d.ts +10 -10
- package/ol/layers/MaplibreLayer.js +9 -3
- package/ol/layers/MaplibreStyleLayer.d.ts +77 -76
- package/ol/layers/MaplibreStyleLayer.js +237 -238
- package/ol/layers/RealtimeLayer.d.ts +92 -96
- package/ol/layers/RealtimeLayer.js +139 -131
- package/ol/mixins/MobilityLayerMixin.d.ts +9 -9
- package/ol/mixins/PropertiesLayerMixin.d.ts +33 -36
- package/ol/mixins/PropertiesLayerMixin.js +73 -72
- package/ol/renderers/MaplibreLayerRenderer.js +3 -3
- package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +6 -6
- package/ol/renderers/MaplibreStyleLayerRenderer.js +14 -17
- package/ol/renderers/RealtimeLayerRenderer.d.ts +6 -6
- package/ol/renderers/RealtimeLayerRenderer.js +54 -52
- package/ol/utils/getFeatureInfoAtCoordinate.d.ts +1 -1
- package/ol/utils/getFeatureInfoAtCoordinate.js +10 -16
- package/package.json +6 -5
- package/setupTests.js +3 -4
- package/types/common.d.ts +53 -49
- package/types/index.d.ts +1 -1
- package/types/realtime.d.ts +91 -93
- package/types/routing.d.ts +60 -60
- package/types/stops.d.ts +62 -62
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Feature } from 'ol';
|
|
2
|
+
import Control from 'ol/control/Control';
|
|
3
|
+
import { click } from 'ol/events/condition';
|
|
4
|
+
import BaseEvent from 'ol/events/Event';
|
|
5
|
+
import { buffer } from 'ol/extent';
|
|
6
|
+
import { GeoJSON } from 'ol/format';
|
|
2
7
|
import { LineString, Point } from 'ol/geom';
|
|
3
8
|
import { Modify } from 'ol/interaction';
|
|
9
|
+
import VectorLayer from 'ol/layer/Vector';
|
|
4
10
|
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
11
|
import { fromLonLat, toLonLat } from 'ol/proj';
|
|
9
|
-
import BaseEvent from 'ol/events/Event';
|
|
10
|
-
import VectorLayer from 'ol/layer/Vector';
|
|
11
12
|
import VectorSource from 'ol/source/Vector';
|
|
12
|
-
import Control from 'ol/control/Control';
|
|
13
13
|
import { RoutingAPI } from '../../api';
|
|
14
14
|
// Examples for a single hop:
|
|
15
15
|
// basel sbb a station named "basel sbb"
|
|
@@ -38,7 +38,7 @@ const getFlatCoordinatesFromSegments = (segmentArray) => {
|
|
|
38
38
|
const coords = [];
|
|
39
39
|
segmentArray.forEach((seg) => {
|
|
40
40
|
var _a;
|
|
41
|
-
// @ts-
|
|
41
|
+
// @ts-expect-error
|
|
42
42
|
const coordArr = (_a = seg.getGeometry()) === null || _a === void 0 ? void 0 : _a.getCoordinates();
|
|
43
43
|
if (coordArr === null || coordArr === void 0 ? void 0 : coordArr.length) {
|
|
44
44
|
coords.push(...coordArr);
|
|
@@ -79,41 +79,17 @@ const getFlatCoordinatesFromSegments = (segmentArray) => {
|
|
|
79
79
|
* @public
|
|
80
80
|
*/
|
|
81
81
|
class RoutingControl extends Control {
|
|
82
|
-
get active() {
|
|
83
|
-
return this.get('active');
|
|
84
|
-
}
|
|
85
|
-
set active(newValue) {
|
|
86
|
-
this.set('active', newValue);
|
|
87
|
-
}
|
|
88
|
-
get loading() {
|
|
89
|
-
return this.get('loading');
|
|
90
|
-
}
|
|
91
|
-
set loading(newValue) {
|
|
92
|
-
this.set('loading', newValue);
|
|
93
|
-
}
|
|
94
|
-
get modify() {
|
|
95
|
-
return this.get('modify');
|
|
96
|
-
}
|
|
97
|
-
set modify(newValue) {
|
|
98
|
-
this.set('modify', newValue);
|
|
99
|
-
}
|
|
100
|
-
get mot() {
|
|
101
|
-
return this.get('mot');
|
|
102
|
-
}
|
|
103
|
-
set mot(newValue) {
|
|
104
|
-
this.set('mot', newValue);
|
|
105
|
-
}
|
|
106
82
|
constructor(options = {}) {
|
|
107
83
|
super(options);
|
|
108
|
-
this.viaPoints = [];
|
|
109
|
-
this.graphs = [];
|
|
110
|
-
this.useRawViaPoints = false;
|
|
111
|
-
this.snapToClosestStation = false;
|
|
112
|
-
this.cacheStationData = {};
|
|
113
84
|
this.abortControllers = {};
|
|
114
|
-
this.
|
|
85
|
+
this.cacheStationData = {};
|
|
115
86
|
this.format = new GeoJSON({ featureProjection: 'EPSG:3857' });
|
|
87
|
+
this.graphs = [];
|
|
116
88
|
this.initialRouteDrag = {};
|
|
89
|
+
this.segments = [];
|
|
90
|
+
this.snapToClosestStation = false;
|
|
91
|
+
this.useRawViaPoints = false;
|
|
92
|
+
this.viaPoints = [];
|
|
117
93
|
if (!this.element) {
|
|
118
94
|
this.createDefaultElement();
|
|
119
95
|
}
|
|
@@ -189,17 +165,60 @@ class RoutingControl extends Control {
|
|
|
189
165
|
]);
|
|
190
166
|
}
|
|
191
167
|
/**
|
|
192
|
-
*
|
|
168
|
+
* Aborts viapoint and route requests
|
|
193
169
|
* @private
|
|
194
170
|
*/
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
171
|
+
abortRequests() {
|
|
172
|
+
var _a;
|
|
173
|
+
// Abort Routing API requests
|
|
174
|
+
this.graphs.forEach((graph) => {
|
|
175
|
+
const graphName = graph[0];
|
|
176
|
+
if (this.abortControllers[graphName]) {
|
|
177
|
+
this.abortControllers[graphName].abort();
|
|
178
|
+
}
|
|
179
|
+
this.abortControllers[graphName] = new AbortController();
|
|
180
|
+
});
|
|
181
|
+
// Abort Stops API requests
|
|
182
|
+
(_a = this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]) === null || _a === void 0 ? void 0 : _a.abort();
|
|
183
|
+
this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY] =
|
|
184
|
+
new AbortController();
|
|
185
|
+
this.loading = false;
|
|
186
|
+
}
|
|
187
|
+
activate() {
|
|
188
|
+
var _a;
|
|
189
|
+
const map = this.getMap();
|
|
190
|
+
if (map) {
|
|
191
|
+
/** @private */
|
|
192
|
+
this.format = new GeoJSON({
|
|
193
|
+
featureProjection: map.getView().getProjection(),
|
|
194
|
+
});
|
|
195
|
+
/** @private */
|
|
196
|
+
this.graphsResolutions = RoutingControl.getGraphsResolutions(this.graphs, map);
|
|
197
|
+
// Clean the modifyInteraction if present
|
|
198
|
+
if (this.modifyInteraction) {
|
|
199
|
+
map.removeInteraction(this.modifyInteraction);
|
|
200
|
+
}
|
|
201
|
+
// Add modify interaction, RoutingLayer and listeners
|
|
202
|
+
// this.routingLayer?.attachToMap(this.getMap());
|
|
203
|
+
if (this.modifyInteraction) {
|
|
204
|
+
map.addInteraction(this.modifyInteraction);
|
|
205
|
+
}
|
|
206
|
+
(_a = this.modifyInteraction) === null || _a === void 0 ? void 0 : _a.setActive(this.modify);
|
|
207
|
+
this.addListeners();
|
|
198
208
|
}
|
|
199
|
-
|
|
200
|
-
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Add click listener to map.
|
|
212
|
+
* @private
|
|
213
|
+
*/
|
|
214
|
+
addListeners() {
|
|
215
|
+
var _a;
|
|
216
|
+
if (!this.modify) {
|
|
217
|
+
return;
|
|
201
218
|
}
|
|
202
|
-
this.
|
|
219
|
+
this.removeListeners();
|
|
220
|
+
/** @private */
|
|
221
|
+
this.onMapClickKey = (_a = this.getMap()) === null || _a === void 0 ? void 0 : _a.on('singleclick', this.onMapClick);
|
|
203
222
|
}
|
|
204
223
|
/**
|
|
205
224
|
* Adds/Replaces a viaPoint to the viaPoints array and redraws route:
|
|
@@ -219,60 +238,66 @@ class RoutingControl extends Control {
|
|
|
219
238
|
this.dispatchEvent(new BaseEvent('change:route'));
|
|
220
239
|
}
|
|
221
240
|
/**
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
* @
|
|
225
|
-
* @public
|
|
226
|
-
*/
|
|
227
|
-
removeViaPoint(index = (this.viaPoints || []).length - 1) {
|
|
228
|
-
/* Remove viapoint and redraw route */
|
|
229
|
-
if (this.viaPoints.length && this.viaPoints[index]) {
|
|
230
|
-
this.viaPoints.splice(index, 1);
|
|
231
|
-
}
|
|
232
|
-
this.drawRoute();
|
|
233
|
-
this.dispatchEvent(new BaseEvent('change:route'));
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Replaces the current viaPoints with a new coordinate array.
|
|
237
|
-
* @param {Array<Array<number>>} coordinateArray Array of nested coordinates
|
|
238
|
-
* @public
|
|
239
|
-
*/
|
|
240
|
-
setViaPoints(coordinateArray) {
|
|
241
|
-
this.viaPoints = [...coordinateArray];
|
|
242
|
-
this.drawRoute();
|
|
243
|
-
this.dispatchEvent(new BaseEvent('change:route'));
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Removes all viaPoints, clears the source and triggers a change event
|
|
247
|
-
* @public
|
|
241
|
+
* Define a default element.
|
|
242
|
+
*
|
|
243
|
+
* @private
|
|
248
244
|
*/
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
this.
|
|
253
|
-
this.
|
|
254
|
-
|
|
255
|
-
this.
|
|
245
|
+
createDefaultElement() {
|
|
246
|
+
/** @private */
|
|
247
|
+
this.element = document.createElement('button');
|
|
248
|
+
this.element.id = 'ol-toggle-routing';
|
|
249
|
+
this.element.innerHTML = 'Toggle Route Control';
|
|
250
|
+
this.element.onclick = () => this.active ? this.deactivate() : this.activate();
|
|
251
|
+
Object.assign(this.element.style, {
|
|
252
|
+
position: 'absolute',
|
|
253
|
+
right: '10px',
|
|
254
|
+
top: '10px',
|
|
255
|
+
});
|
|
256
256
|
}
|
|
257
257
|
/**
|
|
258
|
-
*
|
|
258
|
+
* Create the interaction used to modify vertexes of features.
|
|
259
259
|
* @private
|
|
260
260
|
*/
|
|
261
|
-
|
|
261
|
+
createModifyInteraction() {
|
|
262
262
|
var _a;
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
this.
|
|
263
|
+
/**
|
|
264
|
+
* @type {ol.interaction.Modify}
|
|
265
|
+
* @private
|
|
266
|
+
*/
|
|
267
|
+
// Define and add modify interaction
|
|
268
|
+
this.modifyInteraction = new Modify({
|
|
269
|
+
// hitDetection: this.routingLayer, // Create a bug, the first point is always selected even if the mous eis far away
|
|
270
|
+
deleteCondition: (e) => {
|
|
271
|
+
var _a;
|
|
272
|
+
const feats = (_a = e.target) === null || _a === void 0 ? void 0 : _a.getFeaturesAtPixel(e.pixel, {
|
|
273
|
+
hitTolerance: 5,
|
|
274
|
+
} || []);
|
|
275
|
+
const viaPoint = feats.find((feat) => { var _a; return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === 'Point' && feat.get('index'); });
|
|
276
|
+
if (click(e) && viaPoint) {
|
|
277
|
+
// Remove node & viaPoint if an existing viaPoint was clicked
|
|
278
|
+
this.removeViaPoint(viaPoint.get('index'));
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
return false;
|
|
282
|
+
},
|
|
283
|
+
pixelTolerance: 6,
|
|
284
|
+
source: ((_a = this.routingLayer) === null || _a === void 0 ? void 0 : _a.getSource()) || undefined,
|
|
270
285
|
});
|
|
271
|
-
|
|
272
|
-
(
|
|
273
|
-
this.
|
|
274
|
-
|
|
275
|
-
|
|
286
|
+
this.modifyInteraction.on('modifystart', this.onModifyStart);
|
|
287
|
+
this.modifyInteraction.on('modifyend', this.onModifyEnd);
|
|
288
|
+
this.modifyInteraction.setActive(false);
|
|
289
|
+
}
|
|
290
|
+
deactivate() {
|
|
291
|
+
const map = this.getMap();
|
|
292
|
+
if (map) {
|
|
293
|
+
// Remove modify interaction, RoutingLayer, listeners and viaPoints
|
|
294
|
+
// this.routingLayer?.detachFromMap();
|
|
295
|
+
if (this.modifyInteraction) {
|
|
296
|
+
map.removeInteraction(this.modifyInteraction);
|
|
297
|
+
}
|
|
298
|
+
this.removeListeners();
|
|
299
|
+
this.reset();
|
|
300
|
+
}
|
|
276
301
|
}
|
|
277
302
|
/**
|
|
278
303
|
* Draws route on map using an array of coordinates:
|
|
@@ -314,9 +339,9 @@ class RoutingControl extends Control {
|
|
|
314
339
|
return Promise.resolve([]);
|
|
315
340
|
}
|
|
316
341
|
return this.api
|
|
317
|
-
.route(Object.assign({
|
|
318
|
-
// @ts-
|
|
319
|
-
|
|
342
|
+
.route(Object.assign({ 'coord-punish': 1000.0, 'coord-radius': 100.0,
|
|
343
|
+
// @ts-expect-error missing property in swagger
|
|
344
|
+
elevation: false, graph, mot: this.mot, 'resolve-hops': false, via: `${formattedViaPoints.join('|')}` }, (this.routingApiParams || {})), { signal })
|
|
320
345
|
.then((featureCollection) => {
|
|
321
346
|
var _a, _b, _c;
|
|
322
347
|
this.segments = this.format.readFeatures(featureCollection);
|
|
@@ -474,6 +499,19 @@ class RoutingControl extends Control {
|
|
|
474
499
|
}
|
|
475
500
|
return Promise.resolve(null);
|
|
476
501
|
}
|
|
502
|
+
/**
|
|
503
|
+
* Activet7deactivate the control when activ eproperty changes
|
|
504
|
+
* @private
|
|
505
|
+
*/
|
|
506
|
+
onActiveChange() {
|
|
507
|
+
if (this.get('active')) {
|
|
508
|
+
this.activate();
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
this.deactivate();
|
|
512
|
+
}
|
|
513
|
+
this.render();
|
|
514
|
+
}
|
|
477
515
|
/**
|
|
478
516
|
* Used on click on map while control is active:
|
|
479
517
|
* By default adds a viaPoint to the end of array.
|
|
@@ -482,8 +520,8 @@ class RoutingControl extends Control {
|
|
|
482
520
|
*/
|
|
483
521
|
onMapClick(evt) {
|
|
484
522
|
const feats = evt.target.getFeaturesAtPixel(evt.pixel, {
|
|
485
|
-
layerFilter: (layer) => layer === this.routingLayer,
|
|
486
523
|
hitTolerance: 5,
|
|
524
|
+
layerFilter: (layer) => layer === this.routingLayer,
|
|
487
525
|
});
|
|
488
526
|
const viaPoint = feats.find((feat) => {
|
|
489
527
|
var _a;
|
|
@@ -497,6 +535,30 @@ class RoutingControl extends Control {
|
|
|
497
535
|
}
|
|
498
536
|
this.addViaPoint(evt.coordinate);
|
|
499
537
|
}
|
|
538
|
+
/**
|
|
539
|
+
* Used on end of the modify interaction. Resolves feature modification:
|
|
540
|
+
* Line drag creates new viaPoint at the final coordinate of drag.
|
|
541
|
+
* Point drag replaces old viaPoint.
|
|
542
|
+
* @private
|
|
543
|
+
*/
|
|
544
|
+
onModifyEnd(evt) {
|
|
545
|
+
const coord = evt.mapBrowserEvent.coordinate;
|
|
546
|
+
const { oldRoute, segmentIndex, viaPoint } = this.initialRouteDrag || {};
|
|
547
|
+
// If viaPoint is being relocated overwrite the old viaPoint
|
|
548
|
+
if (viaPoint) {
|
|
549
|
+
return this.addViaPoint(coord, viaPoint.get('viaPointIdx'), 1);
|
|
550
|
+
}
|
|
551
|
+
// In case there is no route overwrite first coordinate
|
|
552
|
+
if (!oldRoute) {
|
|
553
|
+
return this.addViaPoint(coord, 0, 1);
|
|
554
|
+
}
|
|
555
|
+
// We can't add a via point because we haven't found which segment has been modified.
|
|
556
|
+
if (segmentIndex === -1) {
|
|
557
|
+
return Promise.reject(new Error('No segment found'));
|
|
558
|
+
}
|
|
559
|
+
// Insert new viaPoint at the modified segment index + 1
|
|
560
|
+
return this.addViaPoint(coord, (segmentIndex || 0) + 1);
|
|
561
|
+
}
|
|
500
562
|
/**
|
|
501
563
|
* Used on start of the modify interaction. Stores relevant data
|
|
502
564
|
* in this.initialRouteDrag object
|
|
@@ -510,10 +572,10 @@ class RoutingControl extends Control {
|
|
|
510
572
|
.getArray()
|
|
511
573
|
.find((feat) => { var _a; return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === 'LineString'; });
|
|
512
574
|
// Find the segment index that is being modified
|
|
513
|
-
if (route
|
|
575
|
+
if ((route === null || route === void 0 ? void 0 : route.getGeometry()) && evt.mapBrowserEvent.coordinate) {
|
|
514
576
|
// We use a buff extent to fix floating issues , see https://github.com/openlayers/openlayers/issues/7130#issuecomment-535856422
|
|
515
577
|
const closestExtent = buffer(new Point(
|
|
516
|
-
// @ts-
|
|
578
|
+
// @ts-expect-error
|
|
517
579
|
(_a = route.getGeometry()) === null || _a === void 0 ? void 0 : _a.getClosestPoint(evt.mapBrowserEvent.coordinate)).getExtent(), 0.001);
|
|
518
580
|
segmentIndex = this.segments.findIndex((segment) => { var _a; return (_a = segment.getGeometry()) === null || _a === void 0 ? void 0 : _a.intersectsExtent(closestExtent); });
|
|
519
581
|
}
|
|
@@ -525,106 +587,46 @@ class RoutingControl extends Control {
|
|
|
525
587
|
// Write object with modify info
|
|
526
588
|
/** @private */
|
|
527
589
|
this.initialRouteDrag = {
|
|
528
|
-
viaPoint,
|
|
529
590
|
oldRoute: route && route.clone(),
|
|
530
591
|
segmentIndex,
|
|
592
|
+
viaPoint,
|
|
531
593
|
};
|
|
532
594
|
}
|
|
533
595
|
/**
|
|
534
|
-
*
|
|
535
|
-
* Line drag creates new viaPoint at the final coordinate of drag.
|
|
536
|
-
* Point drag replaces old viaPoint.
|
|
596
|
+
* Remove click listener from map.
|
|
537
597
|
* @private
|
|
538
598
|
*/
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
// If viaPoint is being relocated overwrite the old viaPoint
|
|
543
|
-
if (viaPoint) {
|
|
544
|
-
return this.addViaPoint(coord, viaPoint.get('viaPointIdx'), 1);
|
|
545
|
-
}
|
|
546
|
-
// In case there is no route overwrite first coordinate
|
|
547
|
-
if (!oldRoute) {
|
|
548
|
-
return this.addViaPoint(coord, 0, 1);
|
|
549
|
-
}
|
|
550
|
-
// We can't add a via point because we haven't found which segment has been modified.
|
|
551
|
-
if (segmentIndex === -1) {
|
|
552
|
-
return Promise.reject(new Error('No segment found'));
|
|
599
|
+
removeListeners() {
|
|
600
|
+
if (this.onMapClickKey) {
|
|
601
|
+
unByKey(this.onMapClickKey);
|
|
553
602
|
}
|
|
554
|
-
// Insert new viaPoint at the modified segment index + 1
|
|
555
|
-
return this.addViaPoint(coord, (segmentIndex || 0) + 1);
|
|
556
|
-
}
|
|
557
|
-
/**
|
|
558
|
-
* Define a default element.
|
|
559
|
-
*
|
|
560
|
-
* @private
|
|
561
|
-
*/
|
|
562
|
-
createDefaultElement() {
|
|
563
|
-
/** @private */
|
|
564
|
-
this.element = document.createElement('button');
|
|
565
|
-
this.element.id = 'ol-toggle-routing';
|
|
566
|
-
this.element.innerHTML = 'Toggle Route Control';
|
|
567
|
-
this.element.onclick = () => this.active ? this.deactivate() : this.activate();
|
|
568
|
-
Object.assign(this.element.style, {
|
|
569
|
-
position: 'absolute',
|
|
570
|
-
right: '10px',
|
|
571
|
-
top: '10px',
|
|
572
|
-
});
|
|
573
603
|
}
|
|
574
604
|
/**
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
var _a;
|
|
580
|
-
/**
|
|
581
|
-
* @type {ol.interaction.Modify}
|
|
582
|
-
* @private
|
|
583
|
-
*/
|
|
584
|
-
// Define and add modify interaction
|
|
585
|
-
this.modifyInteraction = new Modify({
|
|
586
|
-
source: ((_a = this.routingLayer) === null || _a === void 0 ? void 0 : _a.getSource()) || undefined,
|
|
587
|
-
pixelTolerance: 6,
|
|
588
|
-
// hitDetection: this.routingLayer, // Create a bug, the first point is always selected even if the mous eis far away
|
|
589
|
-
deleteCondition: (e) => {
|
|
590
|
-
var _a;
|
|
591
|
-
const feats = (_a = e.target) === null || _a === void 0 ? void 0 : _a.getFeaturesAtPixel(e.pixel, {
|
|
592
|
-
hitTolerance: 5,
|
|
593
|
-
} || []);
|
|
594
|
-
const viaPoint = feats.find((feat) => { var _a; return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === 'Point' && feat.get('index'); });
|
|
595
|
-
if (click(e) && viaPoint) {
|
|
596
|
-
// Remove node & viaPoint if an existing viaPoint was clicked
|
|
597
|
-
this.removeViaPoint(viaPoint.get('index'));
|
|
598
|
-
return true;
|
|
599
|
-
}
|
|
600
|
-
return false;
|
|
601
|
-
},
|
|
602
|
-
});
|
|
603
|
-
this.modifyInteraction.on('modifystart', this.onModifyStart);
|
|
604
|
-
this.modifyInteraction.on('modifyend', this.onModifyEnd);
|
|
605
|
-
this.modifyInteraction.setActive(false);
|
|
606
|
-
}
|
|
607
|
-
/**
|
|
608
|
-
* Add click listener to map.
|
|
609
|
-
* @private
|
|
605
|
+
* Removes a viaPoint at the passed array index and redraws route
|
|
606
|
+
* By default the last viaPoint is removed.
|
|
607
|
+
* @param {number} index Integer representing the index of the viaPoint to delete.
|
|
608
|
+
* @public
|
|
610
609
|
*/
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
if (
|
|
614
|
-
|
|
610
|
+
removeViaPoint(index = (this.viaPoints || []).length - 1) {
|
|
611
|
+
/* Remove viapoint and redraw route */
|
|
612
|
+
if (this.viaPoints.length && this.viaPoints[index]) {
|
|
613
|
+
this.viaPoints.splice(index, 1);
|
|
615
614
|
}
|
|
616
|
-
this.
|
|
617
|
-
|
|
618
|
-
this.onMapClickKey = (_a = this.getMap()) === null || _a === void 0 ? void 0 : _a.on('singleclick', this.onMapClick);
|
|
615
|
+
this.drawRoute();
|
|
616
|
+
this.dispatchEvent(new BaseEvent('change:route'));
|
|
619
617
|
}
|
|
618
|
+
render() { }
|
|
620
619
|
/**
|
|
621
|
-
*
|
|
622
|
-
* @
|
|
620
|
+
* Removes all viaPoints, clears the source and triggers a change event
|
|
621
|
+
* @public
|
|
623
622
|
*/
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
623
|
+
reset() {
|
|
624
|
+
var _a, _b;
|
|
625
|
+
// Clear viaPoints and source
|
|
626
|
+
this.abortRequests();
|
|
627
|
+
this.viaPoints = [];
|
|
628
|
+
(_b = (_a = this.routingLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear();
|
|
629
|
+
this.dispatchEvent(new BaseEvent('change:route'));
|
|
628
630
|
}
|
|
629
631
|
setMap(map) {
|
|
630
632
|
super.setMap(map);
|
|
@@ -635,43 +637,39 @@ class RoutingControl extends Control {
|
|
|
635
637
|
this.active = false;
|
|
636
638
|
}
|
|
637
639
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
this.graphsResolutions = RoutingControl.getGraphsResolutions(this.graphs, map);
|
|
648
|
-
// Clean the modifyInteraction if present
|
|
649
|
-
if (this.modifyInteraction) {
|
|
650
|
-
map.removeInteraction(this.modifyInteraction);
|
|
651
|
-
}
|
|
652
|
-
// Add modify interaction, RoutingLayer and listeners
|
|
653
|
-
// @ts-ignore
|
|
654
|
-
// this.routingLayer?.attachToMap(this.getMap());
|
|
655
|
-
if (this.modifyInteraction) {
|
|
656
|
-
map.addInteraction(this.modifyInteraction);
|
|
657
|
-
}
|
|
658
|
-
(_a = this.modifyInteraction) === null || _a === void 0 ? void 0 : _a.setActive(this.modify);
|
|
659
|
-
this.addListeners();
|
|
660
|
-
}
|
|
640
|
+
/**
|
|
641
|
+
* Replaces the current viaPoints with a new coordinate array.
|
|
642
|
+
* @param {Array<Array<number>>} coordinateArray Array of nested coordinates
|
|
643
|
+
* @public
|
|
644
|
+
*/
|
|
645
|
+
setViaPoints(coordinateArray) {
|
|
646
|
+
this.viaPoints = [...coordinateArray];
|
|
647
|
+
this.drawRoute();
|
|
648
|
+
this.dispatchEvent(new BaseEvent('change:route'));
|
|
661
649
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
650
|
+
get active() {
|
|
651
|
+
return this.get('active');
|
|
652
|
+
}
|
|
653
|
+
set active(newValue) {
|
|
654
|
+
this.set('active', newValue);
|
|
655
|
+
}
|
|
656
|
+
get loading() {
|
|
657
|
+
return this.get('loading');
|
|
658
|
+
}
|
|
659
|
+
set loading(newValue) {
|
|
660
|
+
this.set('loading', newValue);
|
|
661
|
+
}
|
|
662
|
+
get modify() {
|
|
663
|
+
return this.get('modify');
|
|
664
|
+
}
|
|
665
|
+
set modify(newValue) {
|
|
666
|
+
this.set('modify', newValue);
|
|
667
|
+
}
|
|
668
|
+
get mot() {
|
|
669
|
+
return this.get('mot');
|
|
670
|
+
}
|
|
671
|
+
set mot(newValue) {
|
|
672
|
+
this.set('mot', newValue);
|
|
674
673
|
}
|
|
675
|
-
render() { }
|
|
676
674
|
}
|
|
677
675
|
export default RoutingControl;
|
package/ol/layers/Layer.d.ts
CHANGED
|
@@ -2,8 +2,13 @@ import OLLayer from 'ol/layer/Layer';
|
|
|
2
2
|
import { MobilityLayerOptions } from '../mixins/MobilityLayerMixin';
|
|
3
3
|
declare const Layer_base: {
|
|
4
4
|
new (...args: any[]): {
|
|
5
|
-
options?: import("../mixins/PropertiesLayerMixin").PropertiesLayerMixinOptions;
|
|
6
5
|
olEventsKeys: import("ol/events").EventsKey[];
|
|
6
|
+
options?: import("../mixins/PropertiesLayerMixin").PropertiesLayerMixinOptions;
|
|
7
|
+
attachToMap(map: import("ol").Map): void;
|
|
8
|
+
detachFromMap(): void;
|
|
9
|
+
flat(): any[];
|
|
10
|
+
onChildrenChange(oldValue: OLLayer[]): void;
|
|
11
|
+
setMapInternal: ((map: import("ol").Map) => void) & ((map: import("ol").default | null) => void);
|
|
7
12
|
children: OLLayer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>[];
|
|
8
13
|
get copyrights(): string;
|
|
9
14
|
set copyrights(newCopyrights: string | string[]);
|
|
@@ -16,17 +21,10 @@ declare const Layer_base: {
|
|
|
16
21
|
olLayer: OLLayer;
|
|
17
22
|
parent: OLLayer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>;
|
|
18
23
|
visible: boolean;
|
|
19
|
-
setMapInternal: ((map: import("ol").Map) => void) & ((map: import("ol").default | null) => void);
|
|
20
|
-
onChildrenChange(oldValue: OLLayer[]): void;
|
|
21
|
-
attachToMap(map: import("ol").Map): void;
|
|
22
|
-
detachFromMap(): void;
|
|
23
|
-
flat(): any[];
|
|
24
|
-
addEventListener: (type: string, listener: import("ol/events").Listener) => void;
|
|
25
|
-
removeEventListener: (type: string, listener: import("ol/events").Listener) => void;
|
|
26
24
|
on: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
|
|
27
|
-
render: (frameState: import("ol/Map").FrameState | null, target: HTMLElement) => HTMLElement | null;
|
|
28
25
|
once: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
|
|
29
26
|
un: import("ol/layer/Layer").LayerOnSignature<void>;
|
|
27
|
+
render: (frameState: import("ol/Map").FrameState | null, target: HTMLElement) => HTMLElement | null;
|
|
30
28
|
getSource: () => import("ol/source").Source | null;
|
|
31
29
|
getRenderSource: () => import("ol/source").Source | null;
|
|
32
30
|
getFeatures: (pixel: import("ol/pixel").Pixel) => Promise<Array<import("ol/Feature").FeatureLike>>;
|
|
@@ -84,9 +82,11 @@ declare const Layer_base: {
|
|
|
84
82
|
unset: (key: string, silent?: boolean | undefined) => void;
|
|
85
83
|
changed: () => void;
|
|
86
84
|
getRevision: () => number;
|
|
85
|
+
addEventListener: (type: string, listener: import("ol/events").Listener) => void;
|
|
87
86
|
dispatchEvent: (event: import("ol/events/Event").default | string) => boolean | undefined;
|
|
88
87
|
getListeners: (type: string) => Array<import("ol/events").Listener> | undefined;
|
|
89
88
|
hasListener: (type?: string | undefined) => boolean;
|
|
89
|
+
removeEventListener: (type: string, listener: import("ol/events").Listener) => void;
|
|
90
90
|
dispose: () => void;
|
|
91
91
|
};
|
|
92
92
|
} & typeof OLLayer;
|
|
@@ -5,14 +5,19 @@ import { MobilityLayerOptions } from '../mixins/MobilityLayerMixin';
|
|
|
5
5
|
export type MaplibreLayerOptions = MobilityLayerOptions & MapLibreLayerOptions & {
|
|
6
6
|
apiKey?: string;
|
|
7
7
|
apiKeyName?: string;
|
|
8
|
-
style?: string | maplibregl.StyleSpecification;
|
|
8
|
+
style?: null | string | maplibregl.StyleSpecification;
|
|
9
9
|
url?: string;
|
|
10
10
|
mapLibreOptions?: MapLibreOptions;
|
|
11
11
|
};
|
|
12
12
|
declare const MaplibreLayer_base: {
|
|
13
13
|
new (...args: any[]): {
|
|
14
|
-
options?: import("../mixins/PropertiesLayerMixin").PropertiesLayerMixinOptions;
|
|
15
14
|
olEventsKeys: import("ol/events").EventsKey[];
|
|
15
|
+
options?: import("../mixins/PropertiesLayerMixin").PropertiesLayerMixinOptions;
|
|
16
|
+
attachToMap(map: OlMap): void;
|
|
17
|
+
detachFromMap(): void;
|
|
18
|
+
flat(): any[];
|
|
19
|
+
onChildrenChange(oldValue: import("ol/layer").Layer[]): void;
|
|
20
|
+
setMapInternal: ((map: OlMap) => void) & ((map: import("ol/Map").default | null) => void);
|
|
16
21
|
children: import("ol/layer").Layer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>[];
|
|
17
22
|
get copyrights(): string;
|
|
18
23
|
set copyrights(newCopyrights: string | string[]);
|
|
@@ -25,17 +30,10 @@ declare const MaplibreLayer_base: {
|
|
|
25
30
|
olLayer: import("ol/layer").Layer;
|
|
26
31
|
parent: import("ol/layer").Layer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>;
|
|
27
32
|
visible: boolean;
|
|
28
|
-
setMapInternal: ((map: OlMap) => void) & ((map: import("ol/Map").default | null) => void);
|
|
29
|
-
onChildrenChange(oldValue: import("ol/layer").Layer[]): void;
|
|
30
|
-
attachToMap(map: OlMap): void;
|
|
31
|
-
detachFromMap(): void;
|
|
32
|
-
flat(): any[];
|
|
33
|
-
addEventListener: (type: string, listener: import("ol/events").Listener) => void;
|
|
34
|
-
removeEventListener: (type: string, listener: import("ol/events").Listener) => void;
|
|
35
33
|
on: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
|
|
36
|
-
render: (frameState: import("ol/Map").FrameState | null, target: HTMLElement) => HTMLElement | null;
|
|
37
34
|
once: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
|
|
38
35
|
un: import("ol/layer/Layer").LayerOnSignature<void>;
|
|
36
|
+
render: (frameState: import("ol/Map").FrameState | null, target: HTMLElement) => HTMLElement | null;
|
|
39
37
|
getSource: () => import("ol/source").Source | null;
|
|
40
38
|
getRenderSource: () => import("ol/source").Source | null;
|
|
41
39
|
getFeatures: (pixel: import("ol/pixel").Pixel) => Promise<Array<import("ol/Feature").FeatureLike>>;
|
|
@@ -93,9 +91,11 @@ declare const MaplibreLayer_base: {
|
|
|
93
91
|
unset: (key: string, silent?: boolean | undefined) => void;
|
|
94
92
|
changed: () => void;
|
|
95
93
|
getRevision: () => number;
|
|
94
|
+
addEventListener: (type: string, listener: import("ol/events").Listener) => void;
|
|
96
95
|
dispatchEvent: (event: import("ol/events/Event").default | string) => boolean | undefined;
|
|
97
96
|
getListeners: (type: string) => Array<import("ol/events").Listener> | undefined;
|
|
98
97
|
hasListener: (type?: string | undefined) => boolean;
|
|
98
|
+
removeEventListener: (type: string, listener: import("ol/events").Listener) => void;
|
|
99
99
|
dispose: () => void;
|
|
100
100
|
};
|
|
101
101
|
} & typeof MapLibreLayer;
|