mobility-toolbox-js 3.0.0-beta.32 → 3.0.0-beta.34
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.js +1 -3
- package/api/RealtimeAPI.d.ts +5 -5
- package/api/RealtimeAPI.js +3 -3
- package/api/WebSocketAPI.js +0 -1
- package/common/controls/StopFinderControlCommon.d.ts +1 -1
- package/common/controls/StopFinderControlCommon.js +1 -1
- package/common/styles/realtimeDefaultStyle.js +0 -5
- package/common/styles/realtimeHeadingStyle.js +0 -5
- package/common/styles/realtimeSimpleStyle.d.ts +0 -1
- package/common/styles/realtimeSimpleStyle.js +0 -1
- package/common/utils/RealtimeEngine.d.ts +214 -0
- package/common/utils/RealtimeEngine.js +555 -0
- package/common/utils/getLayersAsFlatArray.d.ts +0 -1
- package/common/utils/getLayersAsFlatArray.js +0 -1
- package/common/utils/realtimeConfig.d.ts +1 -1
- package/common/utils/realtimeConfig.js +0 -1
- package/common/utils/renderTrajectories.d.ts +1 -0
- package/common/utils/renderTrajectories.js +1 -0
- package/common/utils/sortAndFilterDepartures.d.ts +1 -0
- package/common/utils/sortAndFilterDepartures.js +1 -0
- package/maplibre/controls/CopyrightControl.d.ts +9 -6
- package/maplibre/controls/CopyrightControl.js +11 -8
- package/maplibre/layers/Layer.d.ts +7 -6
- package/maplibre/layers/Layer.js +1 -2
- package/maplibre/layers/RealtimeLayer.d.ts +54 -111
- package/maplibre/layers/RealtimeLayer.js +126 -114
- package/maplibre/utils/getSourceCoordinates.d.ts +1 -0
- package/maplibre/utils/getSourceCoordinates.js +5 -4
- package/mbt.js +5329 -13530
- package/mbt.js.map +4 -4
- package/mbt.min.js +68 -71
- package/mbt.min.js.map +4 -4
- package/ol/controls/CopyrightControl.d.ts +13 -5
- package/ol/controls/CopyrightControl.js +13 -5
- package/ol/controls/RoutingControl.d.ts +30 -19
- package/ol/controls/RoutingControl.js +33 -48
- package/ol/controls/StopFinderControl.d.ts +23 -4
- package/ol/controls/StopFinderControl.js +22 -3
- package/ol/layers/MaplibreLayer.d.ts +22 -9
- package/ol/layers/MaplibreLayer.js +22 -9
- package/ol/layers/MaplibreStyleLayer.d.ts +35 -27
- package/ol/layers/MaplibreStyleLayer.js +36 -29
- package/ol/layers/RealtimeLayer.d.ts +76 -125
- package/ol/layers/RealtimeLayer.js +134 -169
- package/ol/mixins/PropertiesLayerMixin.d.ts +4 -6
- package/ol/mixins/PropertiesLayerMixin.js +0 -2
- package/ol/renderers/RealtimeLayerRenderer.js +6 -31
- package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
- package/ol/styles/fullTrajectoryStyle.d.ts +1 -2
- package/ol/styles/fullTrajectoryStyle.js +5 -7
- package/ol/styles/routingStyle.d.ts +0 -1
- package/ol/styles/routingStyle.js +2 -7
- package/package.json +34 -32
- package/types/common.d.ts +2 -1
- package/common/mixins/RealtimeLayerMixin.d.ts +0 -267
- package/common/mixins/RealtimeLayerMixin.js +0 -751
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { MapEvent } from 'ol';
|
|
2
2
|
import Control, { Options } from 'ol/control/Control';
|
|
3
|
-
export type CopyrightControlOptions =
|
|
3
|
+
export type CopyrightControlOptions = {
|
|
4
4
|
className?: 'string';
|
|
5
5
|
format?: (copyrights: string[]) => string;
|
|
6
|
-
};
|
|
6
|
+
} & Options;
|
|
7
7
|
/**
|
|
8
|
-
* Display layer's copyrights.
|
|
8
|
+
* Display layer's copyrights. Adding the possibility to format them as you wish.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* import { Map } from 'ol';
|
|
@@ -19,12 +19,20 @@ export type CopyrightControlOptions = Options & {
|
|
|
19
19
|
* map.addControl(control);
|
|
20
20
|
*
|
|
21
21
|
*
|
|
22
|
-
* @see <a href="/example/ol-
|
|
22
|
+
* @see <a href="/example/ol-realtime>OpenLayers Realtime layer example</a>
|
|
23
|
+
*
|
|
24
|
+
* @extends {ol/control/Control~Control}
|
|
23
25
|
*
|
|
24
|
-
* @extends {ol/control/Control}
|
|
25
26
|
*/
|
|
26
27
|
declare class CopyrightControl extends Control {
|
|
27
28
|
format: (copyrights: string[]) => string;
|
|
29
|
+
/**
|
|
30
|
+
* Constructor.
|
|
31
|
+
*
|
|
32
|
+
* @param {Object} options
|
|
33
|
+
* @param {Function} format Function used to format the list of copyrights available to a single string. By default join all the copyrights with a |.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
28
36
|
constructor(options?: CopyrightControlOptions);
|
|
29
37
|
render({ frameState }: MapEvent): void;
|
|
30
38
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { inView } from 'ol/layer/Layer';
|
|
2
1
|
import Control from 'ol/control/Control';
|
|
3
|
-
import
|
|
2
|
+
import { inView } from 'ol/layer/Layer';
|
|
4
3
|
import createDefaultCopyrightElement from '../../common/utils/createDefaultCopyrightElt';
|
|
4
|
+
import removeDuplicate from '../../common/utils/removeDuplicate';
|
|
5
5
|
/**
|
|
6
|
-
* Display layer's copyrights.
|
|
6
|
+
* Display layer's copyrights. Adding the possibility to format them as you wish.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* import { Map } from 'ol';
|
|
@@ -17,11 +17,19 @@ import createDefaultCopyrightElement from '../../common/utils/createDefaultCopyr
|
|
|
17
17
|
* map.addControl(control);
|
|
18
18
|
*
|
|
19
19
|
*
|
|
20
|
-
* @see <a href="/example/ol-
|
|
20
|
+
* @see <a href="/example/ol-realtime>OpenLayers Realtime layer example</a>
|
|
21
|
+
*
|
|
22
|
+
* @extends {ol/control/Control~Control}
|
|
21
23
|
*
|
|
22
|
-
* @extends {ol/control/Control}
|
|
23
24
|
*/
|
|
24
25
|
class CopyrightControl extends Control {
|
|
26
|
+
/**
|
|
27
|
+
* Constructor.
|
|
28
|
+
*
|
|
29
|
+
* @param {Object} options
|
|
30
|
+
* @param {Function} format Function used to format the list of copyrights available to a single string. By default join all the copyrights with a |.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
25
33
|
constructor(options = {}) {
|
|
26
34
|
const element = createDefaultCopyrightElement();
|
|
27
35
|
element.className = options.className || 'mbt-copyright';
|
|
@@ -6,29 +6,31 @@ import { Geometry, LineString, Point } from 'ol/geom';
|
|
|
6
6
|
import { Modify } from 'ol/interaction';
|
|
7
7
|
import { ModifyEvent } from 'ol/interaction/Modify';
|
|
8
8
|
import VectorLayer from 'ol/layer/Vector';
|
|
9
|
+
import VectorSource from 'ol/source/Vector';
|
|
9
10
|
import { RoutingAPI } from '../../api';
|
|
10
11
|
import type { Map, MapBrowserEvent } from 'ol';
|
|
11
12
|
import type { Coordinate } from 'ol/coordinate';
|
|
12
13
|
import type { StyleLike } from 'ol/style/Style';
|
|
13
14
|
import type { RoutingGraph, RoutingMot, RoutingParameters, RoutingViaPoint } from '../../types';
|
|
14
|
-
export type RoutingControlOptions =
|
|
15
|
+
export type RoutingControlOptions = {
|
|
15
16
|
active?: boolean;
|
|
16
17
|
apiKey?: string;
|
|
18
|
+
apiParams?: RoutingParameters;
|
|
17
19
|
graphs?: RoutingGraph[];
|
|
18
20
|
modify?: boolean;
|
|
19
21
|
mot?: string;
|
|
20
22
|
onRouteError?: () => void;
|
|
21
|
-
|
|
22
|
-
routingLayer?: VectorLayer<Feature>;
|
|
23
|
+
routingLayer?: VectorLayer<VectorSource>;
|
|
23
24
|
snapToClosestStation?: boolean;
|
|
24
25
|
stopsApiKey?: string;
|
|
25
26
|
stopsApiUrl?: string;
|
|
26
27
|
style?: StyleLike;
|
|
27
28
|
useRawViaPoints?: boolean;
|
|
28
|
-
};
|
|
29
|
+
} & Options;
|
|
29
30
|
export type AbotControllersByGraph = Record<string, AbortController>;
|
|
30
31
|
/**
|
|
31
|
-
* This OpenLayers control allows the user to add and modifiy via points to
|
|
32
|
+
* This OpenLayers control allows the user to add and modifiy via points to
|
|
33
|
+
* a map and request a route from the [geOps Routing API](https://developer.geops.io/apis/routing/).
|
|
32
34
|
*
|
|
33
35
|
* @example
|
|
34
36
|
* import { Map } from 'ol';
|
|
@@ -40,29 +42,23 @@ export type AbotControllersByGraph = Record<string, AbortController>;
|
|
|
40
42
|
*
|
|
41
43
|
* const control = new RoutingControl();
|
|
42
44
|
*
|
|
43
|
-
*
|
|
45
|
+
* map.addControl(control);
|
|
44
46
|
*
|
|
45
|
-
* @classproperty {string} apiKey - Key used for RoutingApi requests.
|
|
46
|
-
* @classproperty {string} stopsApiKey - Key used for Stop lookup requests (defaults to apiKey).
|
|
47
|
-
* @classproperty {string} stopsApiUrl - Url used for Stop lookup requests (defaults to https://api.geops.io/stops/v1/lookup/).
|
|
48
|
-
* @classproperty {Array.<Array<graph="osm", minZoom=0, maxZoom=99>>} graphs - Array of routing graphs and min/max zoom levels. If you use the control in combination with the [geOps Maps API](https://developer.geops.io/apis/maps/), you may want to use the optimal level of generalizations: "[['gen4', 0, 8], ['gen3', 8, 9], ['gen2', 9, 11], ['gen1', 11, 13], ['osm', 13, 99]]"
|
|
49
47
|
* @classproperty {string} mot - Mean of transport to be used for routing.
|
|
50
|
-
* @classproperty {object} routingApiParams - object of additional parameters to pass to the routing api request.
|
|
51
|
-
* @classproperty {object} snapToClosestStation - If true, the routing will snap the coordinate to the closest station. Default to false.
|
|
52
|
-
* @classproperty {boolean} useRawViaPoints - Experimental property. Wen true, it allows the user to add via points using different kind of string. See "via" parameter defined by the [geOps Routing API](https://developer.geops.io/apis/routing/). Default to false, only array of coordinates and station's id are supported as via points.
|
|
53
48
|
* @classproperty {VectorLayer} routingLayer - Layer for adding route features.
|
|
54
|
-
* @classproperty {function} onRouteError - Callback on error.
|
|
55
49
|
* @classproperty {boolean} loading - True if the control is requesting the backend.
|
|
50
|
+
*
|
|
56
51
|
* @see <a href="/example/ol-routing">Openlayers routing example</a>
|
|
57
52
|
*
|
|
58
|
-
* @extends {Control}
|
|
59
|
-
*
|
|
53
|
+
* @extends {ol/control/Control~Control}
|
|
54
|
+
*
|
|
60
55
|
* @public
|
|
61
56
|
*/
|
|
62
57
|
declare class RoutingControl extends Control {
|
|
63
58
|
abortControllers: Record<string, AbortController>;
|
|
64
59
|
api?: RoutingAPI;
|
|
65
60
|
apiKey?: string;
|
|
61
|
+
apiParams?: RoutingParameters;
|
|
66
62
|
cacheStationData: Record<string, Coordinate>;
|
|
67
63
|
format: GeoJSON;
|
|
68
64
|
graphs: RoutingGraph[];
|
|
@@ -76,14 +72,29 @@ declare class RoutingControl extends Control {
|
|
|
76
72
|
modifyInteraction?: Modify;
|
|
77
73
|
onMapClickKey?: EventsKey;
|
|
78
74
|
onRouteError: (error?: Error, control?: RoutingControl) => void;
|
|
79
|
-
|
|
80
|
-
routingLayer?: VectorLayer<Feature>;
|
|
75
|
+
routingLayer?: VectorLayer<VectorSource>;
|
|
81
76
|
segments: Feature<LineString>[];
|
|
82
77
|
snapToClosestStation: boolean;
|
|
83
78
|
stopsApiKey?: string;
|
|
84
79
|
stopsApiUrl?: string;
|
|
85
80
|
useRawViaPoints: boolean;
|
|
86
81
|
viaPoints: RoutingViaPoint[];
|
|
82
|
+
/**
|
|
83
|
+
* Constructor.
|
|
84
|
+
*
|
|
85
|
+
* @param {Object} options
|
|
86
|
+
* @param {string} options.apiKey Access key for [geOps APIs](https://developer.geops.io/).
|
|
87
|
+
* @param {Object} options.apiParams Request parameters. See [geOps Routing API documentation](https://developer.geops.io/apis/routing/).
|
|
88
|
+
* @param {Array.<Array<graph="osm", minZoom=0, maxZoom=99>>} [options.graphs=[['osm', 0, 99]]] - Array of routing graphs and min/max zoom levels. If you use the control in combination with the [geOps Maps API](https://developer.geops.io/apis/maps/), you may want to use the optimal level of generalizations: "[['gen4', 0, 8], ['gen3', 8, 9], ['gen2', 9, 11], ['gen1', 11, 13], ['osm', 13, 99]]".
|
|
89
|
+
* @param {string} [options.mot="bus"] Mean of transport to be used for routing.
|
|
90
|
+
* @param {function} options.onRouteError Callback on request errors.
|
|
91
|
+
* @param {VectorLayer} [options.routingLayer=new VectorLayer()] Vector layer for adding route features.
|
|
92
|
+
* @param {boolean} [options.snapToClosestStation=false] If true, the routing will snap the coordinate to the closest station. Default to false.
|
|
93
|
+
* @param {StyleLike} options.style Style of the default vector layer.
|
|
94
|
+
* @param {boolean} [options.useRawViaPoints=fale] Experimental property. If true, it allows the user to add via points using different kind of string. See "via" parameter defined by the [geOps Routing API](https://developer.geops.io/apis/routing/). Default to false, only array of coordinates and station's id are supported as via points.
|
|
95
|
+
* @param {string} [options.url='https://api.geops.io/routing/v1/'] [geOps Realtime API](https://developer.geops.io/apis/realtime/) url.
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
87
98
|
constructor(options?: RoutingControlOptions);
|
|
88
99
|
/**
|
|
89
100
|
* Calculate at which resolutions corresponds each generalizations.
|
|
@@ -108,7 +119,7 @@ declare class RoutingControl extends Control {
|
|
|
108
119
|
* If an index is passed a viaPoint is added at the specified index.
|
|
109
120
|
* If an index is passed and overwrite x is > 0, x viaPoints at the specified
|
|
110
121
|
* index are replaced with a single new viaPoint.
|
|
111
|
-
* @param {
|
|
122
|
+
* @param {string | Coordinate} coordinatesOrString Array of coordinates or a string representing a station
|
|
112
123
|
* @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.
|
|
113
124
|
* @param {number} [overwrite=0] Marks the number of viaPoints that are removed at the specified index on add.
|
|
114
125
|
* @public
|
|
@@ -18,27 +18,22 @@ import { RoutingAPI } from '../../api';
|
|
|
18
18
|
// @47.37811,8.53935 a station at position 47.37811, 8.53935
|
|
19
19
|
// @47.37811,8.53935$4 track 4 in a station at position 47.37811, 8.53935
|
|
20
20
|
// zürich hb@47.37811,8.53935$8 track 8 in station "Zürich HB" at position 47.37811, 8.53935
|
|
21
|
-
/** @private */
|
|
22
21
|
const REGEX_VIA_POINT = /^([^@$!\n]*)(@?([\d.]+),([\d.]+))?(\$?([a-zA-Z0-9]{0,2}))$/;
|
|
23
22
|
// Examples for a single hop:
|
|
24
23
|
//
|
|
25
24
|
// 47.37811,8.53935 a position 47.37811, 8.53935
|
|
26
|
-
/** @private */
|
|
27
25
|
const REGEX_VIA_POINT_COORD = /^([\d.]+),([\d.]+)$/;
|
|
28
26
|
// Examples for a single hop:
|
|
29
27
|
//
|
|
30
28
|
// !8596126 a station with id 8596126
|
|
31
29
|
// !8596126$4 a station with id 8596126
|
|
32
|
-
/** @private */
|
|
33
30
|
const REGEX_VIA_POINT_STATION_ID = /^!([^$]*)(\$?([a-zA-Z0-9]{0,2}))$/;
|
|
34
|
-
/** @private */
|
|
35
31
|
const STOP_FETCH_ABORT_CONTROLLER_KEY = 'stop-fetch';
|
|
36
|
-
/** @private */
|
|
37
32
|
const getFlatCoordinatesFromSegments = (segmentArray) => {
|
|
38
33
|
const coords = [];
|
|
39
34
|
segmentArray.forEach((seg) => {
|
|
40
35
|
var _a;
|
|
41
|
-
// @ts-expect-error
|
|
36
|
+
// @ts-expect-error missing type
|
|
42
37
|
const coordArr = (_a = seg.getGeometry()) === null || _a === void 0 ? void 0 : _a.getCoordinates();
|
|
43
38
|
if (coordArr === null || coordArr === void 0 ? void 0 : coordArr.length) {
|
|
44
39
|
coords.push(...coordArr);
|
|
@@ -47,7 +42,8 @@ const getFlatCoordinatesFromSegments = (segmentArray) => {
|
|
|
47
42
|
return coords;
|
|
48
43
|
};
|
|
49
44
|
/**
|
|
50
|
-
* This OpenLayers control allows the user to add and modifiy via points to
|
|
45
|
+
* This OpenLayers control allows the user to add and modifiy via points to
|
|
46
|
+
* a map and request a route from the [geOps Routing API](https://developer.geops.io/apis/routing/).
|
|
51
47
|
*
|
|
52
48
|
* @example
|
|
53
49
|
* import { Map } from 'ol';
|
|
@@ -59,26 +55,35 @@ const getFlatCoordinatesFromSegments = (segmentArray) => {
|
|
|
59
55
|
*
|
|
60
56
|
* const control = new RoutingControl();
|
|
61
57
|
*
|
|
62
|
-
*
|
|
58
|
+
* map.addControl(control);
|
|
63
59
|
*
|
|
64
|
-
* @classproperty {string} apiKey - Key used for RoutingApi requests.
|
|
65
|
-
* @classproperty {string} stopsApiKey - Key used for Stop lookup requests (defaults to apiKey).
|
|
66
|
-
* @classproperty {string} stopsApiUrl - Url used for Stop lookup requests (defaults to https://api.geops.io/stops/v1/lookup/).
|
|
67
|
-
* @classproperty {Array.<Array<graph="osm", minZoom=0, maxZoom=99>>} graphs - Array of routing graphs and min/max zoom levels. If you use the control in combination with the [geOps Maps API](https://developer.geops.io/apis/maps/), you may want to use the optimal level of generalizations: "[['gen4', 0, 8], ['gen3', 8, 9], ['gen2', 9, 11], ['gen1', 11, 13], ['osm', 13, 99]]"
|
|
68
60
|
* @classproperty {string} mot - Mean of transport to be used for routing.
|
|
69
|
-
* @classproperty {object} routingApiParams - object of additional parameters to pass to the routing api request.
|
|
70
|
-
* @classproperty {object} snapToClosestStation - If true, the routing will snap the coordinate to the closest station. Default to false.
|
|
71
|
-
* @classproperty {boolean} useRawViaPoints - Experimental property. Wen true, it allows the user to add via points using different kind of string. See "via" parameter defined by the [geOps Routing API](https://developer.geops.io/apis/routing/). Default to false, only array of coordinates and station's id are supported as via points.
|
|
72
61
|
* @classproperty {VectorLayer} routingLayer - Layer for adding route features.
|
|
73
|
-
* @classproperty {function} onRouteError - Callback on error.
|
|
74
62
|
* @classproperty {boolean} loading - True if the control is requesting the backend.
|
|
63
|
+
*
|
|
75
64
|
* @see <a href="/example/ol-routing">Openlayers routing example</a>
|
|
76
65
|
*
|
|
77
|
-
* @extends {Control}
|
|
78
|
-
*
|
|
66
|
+
* @extends {ol/control/Control~Control}
|
|
67
|
+
*
|
|
79
68
|
* @public
|
|
80
69
|
*/
|
|
81
70
|
class RoutingControl extends Control {
|
|
71
|
+
/**
|
|
72
|
+
* Constructor.
|
|
73
|
+
*
|
|
74
|
+
* @param {Object} options
|
|
75
|
+
* @param {string} options.apiKey Access key for [geOps APIs](https://developer.geops.io/).
|
|
76
|
+
* @param {Object} options.apiParams Request parameters. See [geOps Routing API documentation](https://developer.geops.io/apis/routing/).
|
|
77
|
+
* @param {Array.<Array<graph="osm", minZoom=0, maxZoom=99>>} [options.graphs=[['osm', 0, 99]]] - Array of routing graphs and min/max zoom levels. If you use the control in combination with the [geOps Maps API](https://developer.geops.io/apis/maps/), you may want to use the optimal level of generalizations: "[['gen4', 0, 8], ['gen3', 8, 9], ['gen2', 9, 11], ['gen1', 11, 13], ['osm', 13, 99]]".
|
|
78
|
+
* @param {string} [options.mot="bus"] Mean of transport to be used for routing.
|
|
79
|
+
* @param {function} options.onRouteError Callback on request errors.
|
|
80
|
+
* @param {VectorLayer} [options.routingLayer=new VectorLayer()] Vector layer for adding route features.
|
|
81
|
+
* @param {boolean} [options.snapToClosestStation=false] If true, the routing will snap the coordinate to the closest station. Default to false.
|
|
82
|
+
* @param {StyleLike} options.style Style of the default vector layer.
|
|
83
|
+
* @param {boolean} [options.useRawViaPoints=fale] Experimental property. If true, it allows the user to add via points using different kind of string. See "via" parameter defined by the [geOps Routing API](https://developer.geops.io/apis/routing/). Default to false, only array of coordinates and station's id are supported as via points.
|
|
84
|
+
* @param {string} [options.url='https://api.geops.io/routing/v1/'] [geOps Realtime API](https://developer.geops.io/apis/realtime/) url.
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
82
87
|
constructor(options = {}) {
|
|
83
88
|
super(options);
|
|
84
89
|
this.abortControllers = {};
|
|
@@ -95,36 +100,23 @@ class RoutingControl extends Control {
|
|
|
95
100
|
}
|
|
96
101
|
/** True if the control is requesting the backend. */
|
|
97
102
|
this.loading = false;
|
|
98
|
-
/** @private */
|
|
99
103
|
this.active = options.active || true;
|
|
100
|
-
/** @private */
|
|
101
104
|
this.graphs = options.graphs || [['osm', 0, 99]];
|
|
102
|
-
/** @private */
|
|
103
105
|
this.mot = options.mot || 'bus';
|
|
104
|
-
/** @private */
|
|
105
106
|
this.modify = options.modify !== false;
|
|
106
|
-
|
|
107
|
-
this.routingApiParams = options.routingApiParams;
|
|
108
|
-
/** @private */
|
|
107
|
+
this.apiParams = options.apiParams;
|
|
109
108
|
this.useRawViaPoints = options.useRawViaPoints || false;
|
|
110
|
-
/** @private */
|
|
111
109
|
this.snapToClosestStation = options.snapToClosestStation || false;
|
|
112
|
-
/** @private */
|
|
113
110
|
this.apiKey = options.apiKey;
|
|
114
|
-
/** @private */
|
|
115
111
|
this.stopsApiKey = options.stopsApiKey || this.apiKey;
|
|
116
|
-
/** @private */
|
|
117
112
|
this.stopsApiUrl = options.stopsApiUrl || 'https://api.geops.io/stops/v1/';
|
|
118
|
-
/** @private */
|
|
119
113
|
this.api = new RoutingAPI(Object.assign({}, options));
|
|
120
|
-
/** @private */
|
|
121
114
|
this.routingLayer =
|
|
122
115
|
options.routingLayer ||
|
|
123
116
|
new VectorLayer({
|
|
124
117
|
source: new VectorSource(),
|
|
125
118
|
style: options.style,
|
|
126
119
|
});
|
|
127
|
-
/** @private */
|
|
128
120
|
this.onRouteError =
|
|
129
121
|
options.onRouteError ||
|
|
130
122
|
((error) => {
|
|
@@ -133,13 +125,9 @@ class RoutingControl extends Control {
|
|
|
133
125
|
// eslint-disable-next-line no-console
|
|
134
126
|
console.error(error);
|
|
135
127
|
});
|
|
136
|
-
/** @private */
|
|
137
128
|
this.onMapClick = this.onMapClick.bind(this);
|
|
138
|
-
/** @private */
|
|
139
129
|
this.onModifyEnd = this.onModifyEnd.bind(this);
|
|
140
|
-
/** @private */
|
|
141
130
|
this.onModifyStart = this.onModifyStart.bind(this);
|
|
142
|
-
/** @private */
|
|
143
131
|
this.createModifyInteraction();
|
|
144
132
|
this.on('propertychange', (evt) => {
|
|
145
133
|
if (evt.key === 'active') {
|
|
@@ -188,11 +176,9 @@ class RoutingControl extends Control {
|
|
|
188
176
|
var _a;
|
|
189
177
|
const map = this.getMap();
|
|
190
178
|
if (map) {
|
|
191
|
-
/** @private */
|
|
192
179
|
this.format = new GeoJSON({
|
|
193
180
|
featureProjection: map.getView().getProjection(),
|
|
194
181
|
});
|
|
195
|
-
/** @private */
|
|
196
182
|
this.graphsResolutions = RoutingControl.getGraphsResolutions(this.graphs, map);
|
|
197
183
|
// Clean the modifyInteraction if present
|
|
198
184
|
if (this.modifyInteraction) {
|
|
@@ -217,7 +203,6 @@ class RoutingControl extends Control {
|
|
|
217
203
|
return;
|
|
218
204
|
}
|
|
219
205
|
this.removeListeners();
|
|
220
|
-
/** @private */
|
|
221
206
|
this.onMapClickKey = (_a = this.getMap()) === null || _a === void 0 ? void 0 : _a.on('singleclick', this.onMapClick);
|
|
222
207
|
}
|
|
223
208
|
/**
|
|
@@ -226,7 +211,7 @@ class RoutingControl extends Control {
|
|
|
226
211
|
* If an index is passed a viaPoint is added at the specified index.
|
|
227
212
|
* If an index is passed and overwrite x is > 0, x viaPoints at the specified
|
|
228
213
|
* index are replaced with a single new viaPoint.
|
|
229
|
-
* @param {
|
|
214
|
+
* @param {string | Coordinate} coordinatesOrString Array of coordinates or a string representing a station
|
|
230
215
|
* @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.
|
|
231
216
|
* @param {number} [overwrite=0] Marks the number of viaPoints that are removed at the specified index on add.
|
|
232
217
|
* @public
|
|
@@ -243,7 +228,6 @@ class RoutingControl extends Control {
|
|
|
243
228
|
* @private
|
|
244
229
|
*/
|
|
245
230
|
createDefaultElement() {
|
|
246
|
-
/** @private */
|
|
247
231
|
this.element = document.createElement('button');
|
|
248
232
|
this.element.id = 'ol-toggle-routing';
|
|
249
233
|
this.element.innerHTML = 'Toggle Route Control';
|
|
@@ -269,9 +253,9 @@ class RoutingControl extends Control {
|
|
|
269
253
|
// hitDetection: this.routingLayer, // Create a bug, the first point is always selected even if the mous eis far away
|
|
270
254
|
deleteCondition: (e) => {
|
|
271
255
|
var _a;
|
|
272
|
-
const feats = (_a = e.target) === null || _a === void 0 ? void 0 : _a.getFeaturesAtPixel(e.pixel, {
|
|
256
|
+
const feats = ((_a = e.target) === null || _a === void 0 ? void 0 : _a.getFeaturesAtPixel(e.pixel, {
|
|
273
257
|
hitTolerance: 5,
|
|
274
|
-
} || []
|
|
258
|
+
})) || [];
|
|
275
259
|
const viaPoint = feats.find((feat) => { var _a; return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === 'Point' && feat.get('index'); });
|
|
276
260
|
if (click(e) && viaPoint) {
|
|
277
261
|
// Remove node & viaPoint if an existing viaPoint was clicked
|
|
@@ -332,7 +316,9 @@ class RoutingControl extends Control {
|
|
|
332
316
|
});
|
|
333
317
|
this.loading = true;
|
|
334
318
|
// Create point features for the viaPoints
|
|
335
|
-
this.viaPoints.forEach((viaPoint, idx) =>
|
|
319
|
+
this.viaPoints.forEach((viaPoint, idx) => {
|
|
320
|
+
this.drawViaPoint(viaPoint, idx, this.abortControllers[STOP_FETCH_ABORT_CONTROLLER_KEY]);
|
|
321
|
+
});
|
|
336
322
|
return Promise.all(this.graphs.map(([graph], index) => {
|
|
337
323
|
const { signal } = this.abortControllers[graph];
|
|
338
324
|
if (!this.api) {
|
|
@@ -341,7 +327,7 @@ class RoutingControl extends Control {
|
|
|
341
327
|
return this.api
|
|
342
328
|
.route(Object.assign({ 'coord-punish': 1000.0, 'coord-radius': 100.0,
|
|
343
329
|
// @ts-expect-error missing property in swagger
|
|
344
|
-
elevation: false, graph, mot: this.mot, 'resolve-hops': false, via: `${formattedViaPoints.join('|')}` }, (this.
|
|
330
|
+
elevation: false, graph, mot: this.mot, 'resolve-hops': false, via: `${formattedViaPoints.join('|')}` }, (this.apiParams || {})), { signal })
|
|
345
331
|
.then((featureCollection) => {
|
|
346
332
|
var _a, _b, _c;
|
|
347
333
|
this.segments = this.format.readFeatures(featureCollection);
|
|
@@ -575,7 +561,7 @@ class RoutingControl extends Control {
|
|
|
575
561
|
if ((route === null || route === void 0 ? void 0 : route.getGeometry()) && evt.mapBrowserEvent.coordinate) {
|
|
576
562
|
// We use a buff extent to fix floating issues , see https://github.com/openlayers/openlayers/issues/7130#issuecomment-535856422
|
|
577
563
|
const closestExtent = buffer(new Point(
|
|
578
|
-
// @ts-expect-error
|
|
564
|
+
// @ts-expect-error bad def
|
|
579
565
|
(_a = route.getGeometry()) === null || _a === void 0 ? void 0 : _a.getClosestPoint(evt.mapBrowserEvent.coordinate)).getExtent(), 0.001);
|
|
580
566
|
segmentIndex = this.segments.findIndex((segment) => { var _a; return (_a = segment.getGeometry()) === null || _a === void 0 ? void 0 : _a.intersectsExtent(closestExtent); });
|
|
581
567
|
}
|
|
@@ -585,9 +571,8 @@ class RoutingControl extends Control {
|
|
|
585
571
|
.filter((feat) => { var _a; return ((_a = feat.getGeometry()) === null || _a === void 0 ? void 0 : _a.getType()) === 'Point'; }) ||
|
|
586
572
|
[])[0];
|
|
587
573
|
// Write object with modify info
|
|
588
|
-
/** @private */
|
|
589
574
|
this.initialRouteDrag = {
|
|
590
|
-
oldRoute: route
|
|
575
|
+
oldRoute: route === null || route === void 0 ? void 0 : route.clone(),
|
|
591
576
|
segmentIndex,
|
|
592
577
|
viaPoint,
|
|
593
578
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Feature } from 'geojson';
|
|
2
2
|
import Control, { Options } from 'ol/control/Control';
|
|
3
3
|
import StopFinderControlCommon from '../../common/controls/StopFinderControlCommon';
|
|
4
|
-
export type StopFinderControlOptions =
|
|
4
|
+
export type StopFinderControlOptions = {
|
|
5
5
|
className?: string;
|
|
6
|
-
};
|
|
6
|
+
} & Options & StopFinderControlCommon;
|
|
7
7
|
/**
|
|
8
8
|
* This OpenLayers control allows to search stations from the [geOps Stops API](https://developer.geops.io/apis/stops/).
|
|
9
9
|
*
|
|
@@ -23,15 +23,34 @@ export type StopFinderControlOptions = Options & StopFinderControlCommon & {
|
|
|
23
23
|
*
|
|
24
24
|
*
|
|
25
25
|
* @see <a href="/example/ol-search">Openlayers search example</a>
|
|
26
|
+
*
|
|
27
|
+
* @extends {ol/control/Control~Control}
|
|
28
|
+
*
|
|
26
29
|
* @public
|
|
27
30
|
*/
|
|
28
31
|
declare class StopFinderControl extends Control {
|
|
29
32
|
controller: StopFinderControlCommon;
|
|
30
|
-
constructor(options: StopFinderControlOptions);
|
|
31
33
|
/**
|
|
32
|
-
*
|
|
34
|
+
* Constructor.
|
|
35
|
+
*
|
|
36
|
+
* @param {Object} options
|
|
37
|
+
* @param {HTMLElement} options.element HTML element where to attach input and suggestions.
|
|
38
|
+
* @param {string} options.apiKey Access key for [geOps APIs](https://developer.geops.io/).
|
|
39
|
+
* @param {StopsSearchParams} [options.apiParams={ limit: 20 }] Request parameters. See [geOps Stops API documentation](https://developer.geops.io/apis/5dcbd702a256d90001cf1361/).
|
|
40
|
+
* @param {string} [options.placeholder='Search for a stop...'] Input field placeholder.
|
|
41
|
+
* @param {string} [options.url='https://api.geops.io/stops/v1/'] [geOps Stops API](https://developer.geops.io/apis/stops/) url.
|
|
42
|
+
* @public
|
|
33
43
|
*/
|
|
44
|
+
constructor(options: StopFinderControlOptions);
|
|
34
45
|
onSuggestionClick(suggestion: Feature): void;
|
|
46
|
+
/**
|
|
47
|
+
* Search for stations using a query.
|
|
48
|
+
*
|
|
49
|
+
* @param {string} q Query used to search stops.
|
|
50
|
+
* @param {AbortController} abortController Abort controller used to abort requests.
|
|
51
|
+
* @returns {Promise<Array<GeoJSONFeature>>}
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
35
54
|
search(q: string, abortController: AbortController): Promise<void>;
|
|
36
55
|
}
|
|
37
56
|
export default StopFinderControl;
|
|
@@ -21,9 +21,23 @@ import createDefaultStopFinderElement from '../../common/utils/createDefaultStop
|
|
|
21
21
|
*
|
|
22
22
|
*
|
|
23
23
|
* @see <a href="/example/ol-search">Openlayers search example</a>
|
|
24
|
+
*
|
|
25
|
+
* @extends {ol/control/Control~Control}
|
|
26
|
+
*
|
|
24
27
|
* @public
|
|
25
28
|
*/
|
|
26
29
|
class StopFinderControl extends Control {
|
|
30
|
+
/**
|
|
31
|
+
* Constructor.
|
|
32
|
+
*
|
|
33
|
+
* @param {Object} options
|
|
34
|
+
* @param {HTMLElement} options.element HTML element where to attach input and suggestions.
|
|
35
|
+
* @param {string} options.apiKey Access key for [geOps APIs](https://developer.geops.io/).
|
|
36
|
+
* @param {StopsSearchParams} [options.apiParams={ limit: 20 }] Request parameters. See [geOps Stops API documentation](https://developer.geops.io/apis/5dcbd702a256d90001cf1361/).
|
|
37
|
+
* @param {string} [options.placeholder='Search for a stop...'] Input field placeholder.
|
|
38
|
+
* @param {string} [options.url='https://api.geops.io/stops/v1/'] [geOps Stops API](https://developer.geops.io/apis/stops/) url.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
27
41
|
constructor(options) {
|
|
28
42
|
const element = createDefaultStopFinderElement();
|
|
29
43
|
element.className = (options === null || options === void 0 ? void 0 : options.className) || 'mbt-stop-finder';
|
|
@@ -31,14 +45,19 @@ class StopFinderControl extends Control {
|
|
|
31
45
|
super(opt);
|
|
32
46
|
this.controller = new StopFinderControlCommon(Object.assign({ onSuggestionClick: this.onSuggestionClick.bind(this) }, opt));
|
|
33
47
|
}
|
|
34
|
-
/**
|
|
35
|
-
* @private
|
|
36
|
-
*/
|
|
37
48
|
onSuggestionClick(suggestion) {
|
|
38
49
|
var _a;
|
|
39
50
|
const coord = fromLonLat(suggestion.geometry.coordinates);
|
|
40
51
|
(_a = this.getMap()) === null || _a === void 0 ? void 0 : _a.getView().setCenter(coord);
|
|
41
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Search for stations using a query.
|
|
55
|
+
*
|
|
56
|
+
* @param {string} q Query used to search stops.
|
|
57
|
+
* @param {AbortController} abortController Abort controller used to abort requests.
|
|
58
|
+
* @returns {Promise<Array<GeoJSONFeature>>}
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
42
61
|
search(q, abortController) {
|
|
43
62
|
return this.controller.search(q, abortController);
|
|
44
63
|
}
|
|
@@ -124,31 +124,38 @@ declare const MaplibreLayer_base: {
|
|
|
124
124
|
* });
|
|
125
125
|
*
|
|
126
126
|
* @classproperty {maplibregl.Map} mapLibreMap - The Maplibre map object. Readonly.
|
|
127
|
-
* @classproperty {string} style - geOps Maps
|
|
127
|
+
* @classproperty {string} style - The [geOps Maps API](https://developer.geops.io/apis/maps) style.
|
|
128
|
+
*
|
|
129
|
+
*
|
|
130
|
+
* @see <a href="/example/ol-maplibre-layer">OpenLayers Maplibre layer example</a>
|
|
131
|
+
*
|
|
128
132
|
* @extends {ol/layer/Layer~Layer}
|
|
133
|
+
* @extends {geoblocks/ol-maplibre-layer/MapLibreLayer}
|
|
129
134
|
* @public
|
|
130
135
|
*/
|
|
131
136
|
declare class MaplibreLayer extends MaplibreLayer_base {
|
|
132
137
|
/**
|
|
133
138
|
* Constructor.
|
|
134
139
|
*
|
|
135
|
-
* @param {
|
|
136
|
-
* @param {string} options.apiKey
|
|
137
|
-
* @param {string} [options.apiKeyName="key"] The geOps Maps API key name.
|
|
138
|
-
* @param {maplibregl.MapOptions} [options.mapLibreOptions={ interactive: false, trackResize: false, attributionControl: false }]
|
|
139
|
-
* @param {string} [options.style="travic_v2"] The geOps Maps API style.
|
|
140
|
-
* @param {string} [options.url="https://maps.geops.io"] The geOps Maps API url.
|
|
140
|
+
* @param {Object} options
|
|
141
|
+
* @param {string} options.apiKey Accesss key for [geOps APIs](https://developer.geops.io/).
|
|
142
|
+
* @param {string} [options.apiKeyName="key"] The [geOps Maps API](https://developer.geops.io/apis/maps) key name.
|
|
143
|
+
* @param {maplibregl.MapOptions} [options.mapLibreOptions={ interactive: false, trackResize: false, attributionControl: false }] MapLibre map options.
|
|
144
|
+
* @param {string} [options.style="travic_v2"] The [geOps Maps API](https://developer.geops.io/apis/maps) style.
|
|
145
|
+
* @param {string} [options.url="https://maps.geops.io"] The [geOps Maps API](https://developer.geops.io/apis/maps) url.
|
|
141
146
|
*/
|
|
142
147
|
constructor(options: MaplibreLayerOptions);
|
|
143
148
|
/**
|
|
144
149
|
* Initialize the layer and listen to feature clicks.
|
|
145
|
-
* @param {ol/Map~Map} map
|
|
150
|
+
* @param {ol/Map~Map} map An OpenLayers map.
|
|
146
151
|
*/
|
|
147
152
|
attachToMap(map: OlMap): void;
|
|
148
153
|
/**
|
|
149
154
|
* Create a copy of the MaplibreLayer.
|
|
150
|
-
*
|
|
155
|
+
*
|
|
156
|
+
* @param {Object} newOptions Options to override. See constructor.
|
|
151
157
|
* @return {MaplibreLayer} A MaplibreLayer layer
|
|
158
|
+
* @public
|
|
152
159
|
*/
|
|
153
160
|
clone(newOptions: MaplibreLayerOptions): MaplibreLayer;
|
|
154
161
|
getStyle(): string;
|
|
@@ -157,7 +164,13 @@ declare class MaplibreLayer extends MaplibreLayer_base {
|
|
|
157
164
|
get apiKey(): string;
|
|
158
165
|
set apiKeyName(newValue: string);
|
|
159
166
|
get apiKeyName(): string;
|
|
167
|
+
/**
|
|
168
|
+
* @deprecated Use layer.mapLibreMap.
|
|
169
|
+
*/
|
|
160
170
|
get maplibreMap(): maplibregl.Map | undefined;
|
|
171
|
+
/**
|
|
172
|
+
* @deprecated Use layer.mapLibreMap.
|
|
173
|
+
*/
|
|
161
174
|
get mbMap(): maplibregl.Map | undefined;
|
|
162
175
|
get style(): string;
|
|
163
176
|
set style(newValue: string);
|
|
@@ -37,20 +37,25 @@ if (typeof window !== 'undefined' &&
|
|
|
37
37
|
* });
|
|
38
38
|
*
|
|
39
39
|
* @classproperty {maplibregl.Map} mapLibreMap - The Maplibre map object. Readonly.
|
|
40
|
-
* @classproperty {string} style - geOps Maps
|
|
40
|
+
* @classproperty {string} style - The [geOps Maps API](https://developer.geops.io/apis/maps) style.
|
|
41
|
+
*
|
|
42
|
+
*
|
|
43
|
+
* @see <a href="/example/ol-maplibre-layer">OpenLayers Maplibre layer example</a>
|
|
44
|
+
*
|
|
41
45
|
* @extends {ol/layer/Layer~Layer}
|
|
46
|
+
* @extends {geoblocks/ol-maplibre-layer/MapLibreLayer}
|
|
42
47
|
* @public
|
|
43
48
|
*/
|
|
44
49
|
class MaplibreLayer extends MobilityLayerMixin(MapLibreLayer) {
|
|
45
50
|
/**
|
|
46
51
|
* Constructor.
|
|
47
52
|
*
|
|
48
|
-
* @param {
|
|
49
|
-
* @param {string} options.apiKey
|
|
50
|
-
* @param {string} [options.apiKeyName="key"] The geOps Maps API key name.
|
|
51
|
-
* @param {maplibregl.MapOptions} [options.mapLibreOptions={ interactive: false, trackResize: false, attributionControl: false }]
|
|
52
|
-
* @param {string} [options.style="travic_v2"] The geOps Maps API style.
|
|
53
|
-
* @param {string} [options.url="https://maps.geops.io"] The geOps Maps API url.
|
|
53
|
+
* @param {Object} options
|
|
54
|
+
* @param {string} options.apiKey Accesss key for [geOps APIs](https://developer.geops.io/).
|
|
55
|
+
* @param {string} [options.apiKeyName="key"] The [geOps Maps API](https://developer.geops.io/apis/maps) key name.
|
|
56
|
+
* @param {maplibregl.MapOptions} [options.mapLibreOptions={ interactive: false, trackResize: false, attributionControl: false }] MapLibre map options.
|
|
57
|
+
* @param {string} [options.style="travic_v2"] The [geOps Maps API](https://developer.geops.io/apis/maps) style.
|
|
58
|
+
* @param {string} [options.url="https://maps.geops.io"] The [geOps Maps API](https://developer.geops.io/apis/maps) url.
|
|
54
59
|
*/
|
|
55
60
|
constructor(options) {
|
|
56
61
|
var _a;
|
|
@@ -69,7 +74,7 @@ class MaplibreLayer extends MobilityLayerMixin(MapLibreLayer) {
|
|
|
69
74
|
}
|
|
70
75
|
/**
|
|
71
76
|
* Initialize the layer and listen to feature clicks.
|
|
72
|
-
* @param {ol/Map~Map} map
|
|
77
|
+
* @param {ol/Map~Map} map An OpenLayers map.
|
|
73
78
|
*/
|
|
74
79
|
attachToMap(map) {
|
|
75
80
|
super.attachToMap(map);
|
|
@@ -91,8 +96,10 @@ class MaplibreLayer extends MobilityLayerMixin(MapLibreLayer) {
|
|
|
91
96
|
// }
|
|
92
97
|
/**
|
|
93
98
|
* Create a copy of the MaplibreLayer.
|
|
94
|
-
*
|
|
99
|
+
*
|
|
100
|
+
* @param {Object} newOptions Options to override. See constructor.
|
|
95
101
|
* @return {MaplibreLayer} A MaplibreLayer layer
|
|
102
|
+
* @public
|
|
96
103
|
*/
|
|
97
104
|
clone(newOptions) {
|
|
98
105
|
return new MaplibreLayer(Object.assign(Object.assign({}, (this.options || {})), (newOptions || {})));
|
|
@@ -134,10 +141,16 @@ class MaplibreLayer extends MobilityLayerMixin(MapLibreLayer) {
|
|
|
134
141
|
get apiKeyName() {
|
|
135
142
|
return this.get('apiKeyName');
|
|
136
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* @deprecated Use layer.mapLibreMap.
|
|
146
|
+
*/
|
|
137
147
|
get maplibreMap() {
|
|
138
148
|
deprecated('MaplibreLayer.maplibreMap is deprecated. Use layer.mapLibreMap.');
|
|
139
149
|
return this.mapLibreMap;
|
|
140
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* @deprecated Use layer.mapLibreMap.
|
|
153
|
+
*/
|
|
141
154
|
get mbMap() {
|
|
142
155
|
deprecated('MaplibreLayer.mbMap is deprecated. Use layer.maplibreMap.');
|
|
143
156
|
return this.maplibreMap;
|