mobility-toolbox-js 3.0.0-beta.8 → 3.0.0
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 +11 -3
- package/api/HttpAPI.d.ts +20 -0
- package/api/HttpAPI.js +1 -14
- package/api/RealtimeAPI.d.ts +404 -0
- package/api/RealtimeAPI.js +265 -206
- package/api/RoutingAPI.d.ts +47 -0
- package/api/RoutingAPI.js +17 -7
- package/api/StopsAPI.d.ts +44 -0
- package/api/StopsAPI.js +17 -11
- package/api/WebSocketAPI.d.ts +147 -0
- package/api/WebSocketAPI.js +164 -165
- package/api/index.d.ts +3 -0
- package/api/index.js +1 -1
- package/api/typedefs.d.ts +76 -0
- package/api/typedefs.js +27 -42
- package/common/controls/StopFinderControlCommon.d.ts +53 -0
- package/common/controls/StopFinderControlCommon.js +32 -32
- package/common/index.d.ts +2 -0
- package/common/index.js +1 -1
- package/common/styles/index.d.ts +4 -0
- package/common/styles/realtimeDefaultStyle.d.ts +36 -0
- package/common/styles/realtimeDefaultStyle.js +6 -11
- package/common/styles/realtimeDelayStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.js +5 -10
- package/common/styles/realtimeSimpleStyle.d.ts +3 -0
- package/common/styles/realtimeSimpleStyle.js +0 -1
- package/common/typedefs.d.ts +102 -0
- package/common/typedefs.js +6 -31
- package/common/utils/RealtimeEngine.d.ts +214 -0
- package/common/utils/RealtimeEngine.js +554 -0
- package/common/utils/compareDepartures.d.ts +10 -0
- package/common/utils/compareDepartures.js +2 -2
- package/common/utils/constants.d.ts +5 -0
- package/common/utils/createCanvas.d.ts +10 -0
- package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
- package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
- package/common/utils/createRealtimeFilters.d.ts +12 -0
- package/common/utils/debounceDeparturesMessages.d.ts +12 -0
- package/common/utils/debounceWebsocketMessages.d.ts +11 -0
- package/common/utils/getLayersAsFlatArray.d.ts +2 -0
- package/common/utils/getLayersAsFlatArray.js +0 -1
- package/common/utils/getMapGlCopyrights.d.ts +17 -0
- package/common/utils/getMapGlCopyrights.js +3 -3
- package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
- package/common/utils/getRealtimeModeSuffix.js +1 -0
- package/common/utils/getUrlWithParams.d.ts +8 -0
- package/common/utils/getVehiclePosition.d.ts +17 -0
- package/common/utils/getVehiclePosition.js +6 -3
- package/common/utils/index.d.ts +16 -0
- package/common/utils/realtimeConfig.d.ts +64 -0
- package/common/utils/realtimeConfig.js +0 -1
- package/common/utils/removeDuplicate.d.ts +9 -0
- package/common/utils/renderTrajectories.d.ts +17 -0
- package/common/utils/renderTrajectories.js +7 -6
- package/common/utils/sortAndFilterDepartures.d.ts +16 -0
- package/common/utils/sortAndFilterDepartures.js +2 -1
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.js +5 -1
- package/common/utils/timeUtils.d.ts +23 -0
- package/common/utils/toMercatorExtent.d.ts +5 -0
- package/iife.d.ts +2 -0
- package/index.d.ts +9 -0
- package/maplibre/controls/CopyrightControl.d.ts +38 -0
- package/maplibre/controls/CopyrightControl.js +11 -8
- package/maplibre/controls/index.d.ts +1 -0
- package/maplibre/index.d.ts +5 -0
- package/maplibre/layers/Layer.d.ts +29 -0
- package/maplibre/layers/Layer.js +2 -3
- package/maplibre/layers/RealtimeLayer.d.ts +124 -0
- package/maplibre/layers/RealtimeLayer.js +154 -118
- package/maplibre/layers/index.d.ts +2 -0
- package/maplibre/utils/getMercatorResolution.d.ts +7 -0
- package/maplibre/utils/getSourceCoordinates.d.ts +8 -0
- package/maplibre/utils/getSourceCoordinates.js +6 -5
- package/maplibre/utils/index.d.ts +2 -0
- package/mbt.js +14585 -14557
- package/mbt.js.map +4 -4
- package/mbt.min.js +75 -75
- package/mbt.min.js.map +4 -4
- package/ol/controls/CopyrightControl.d.ts +39 -0
- package/ol/controls/CopyrightControl.js +13 -5
- package/ol/controls/RoutingControl.d.ts +213 -0
- package/ol/controls/RoutingControl.js +250 -264
- package/ol/controls/StopFinderControl.d.ts +56 -0
- package/ol/controls/StopFinderControl.js +24 -5
- package/ol/controls/index.d.ts +3 -0
- package/ol/index.d.ts +6 -0
- package/ol/layers/Layer.d.ts +26 -0
- package/ol/layers/Layer.js +39 -0
- package/ol/layers/MaplibreLayer.d.ts +91 -0
- package/ol/layers/MaplibreLayer.js +154 -31
- package/ol/layers/MaplibreStyleLayer.d.ts +157 -0
- package/ol/layers/MaplibreStyleLayer.js +281 -210
- package/ol/layers/RealtimeLayer.d.ts +150 -0
- package/ol/layers/RealtimeLayer.js +210 -206
- package/ol/layers/VectorLayer.d.ts +17 -0
- package/ol/layers/VectorLayer.js +33 -0
- package/ol/layers/index.d.ts +5 -0
- package/ol/layers/index.js +3 -0
- package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
- package/ol/renderers/MaplibreLayerRenderer.js +142 -114
- package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
- package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
- package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
- package/ol/renderers/RealtimeLayerRenderer.js +50 -70
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
- package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryStyle.js +5 -7
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/routingStyle.d.ts +3 -0
- package/ol/styles/routingStyle.js +13 -10
- package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
- package/ol/utils/defineDeprecatedProperties.js +180 -0
- package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
- package/ol/utils/getFeatureInfoAtCoordinate.js +11 -17
- package/ol/utils/index.d.ts +1 -0
- package/package.json +44 -44
- package/setupTests.d.ts +1 -0
- package/setupTests.js +17 -4
- package/types/common.d.ts +53 -69
- package/types/index.d.ts +1 -1
- package/types/realtime.d.ts +98 -95
- package/types/routing.d.ts +60 -60
- package/types/stops.d.ts +62 -62
- package/common/mixins/RealtimeLayerMixin.js +0 -743
- package/ol/layers/MapGlLayer.js +0 -142
- package/ol/mixins/MobilityLayerMixin.js +0 -9
- package/ol/mixins/PropertiesLayerMixin.js +0 -142
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { DebouncedFunc } from 'lodash';
|
|
2
|
+
import { Map, MapEvent } from 'ol';
|
|
3
|
+
import { EventsKey } from 'ol/events';
|
|
4
|
+
import Feature, { FeatureLike } from 'ol/Feature';
|
|
5
|
+
import Layer from 'ol/layer/Layer';
|
|
6
|
+
import VectorLayer from 'ol/layer/Vector';
|
|
7
|
+
import { ObjectEvent } from 'ol/Object';
|
|
8
|
+
import { Vector as VectorSource } from 'ol/source';
|
|
9
|
+
import { State } from 'ol/View';
|
|
10
|
+
import { WebSocketAPIMessageEventData } from '../../api/WebSocketAPI';
|
|
11
|
+
import { FilterFunction, SortFunction } from '../../common/typedefs';
|
|
12
|
+
import RealtimeEngine, { RealtimeEngineOptions } from '../../common/utils/RealtimeEngine';
|
|
13
|
+
import { RealtimeAPI } from '../../maplibre';
|
|
14
|
+
import { RealtimeFullTrajectory, RealtimeMode, RealtimeRenderState, RealtimeTrainId, ViewState } from '../../types';
|
|
15
|
+
import RealtimeLayerRenderer from '../renderers/RealtimeLayerRenderer';
|
|
16
|
+
export type RealtimeLayerOptions = {
|
|
17
|
+
allowRenderWhenAnimating?: boolean;
|
|
18
|
+
fullTrajectoryStyle?: (feature: FeatureLike, resolution: number, options: any) => void;
|
|
19
|
+
maxNbFeaturesRequested?: number;
|
|
20
|
+
} & RealtimeEngineOptions;
|
|
21
|
+
/**
|
|
22
|
+
* An OpenLayers layer able to display data from the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* import { RealtimeLayer } from 'mobility-toolbox-js/ol';
|
|
26
|
+
*
|
|
27
|
+
* const layer = new RealtimeLayer({
|
|
28
|
+
* apiKey: "yourApiKey"
|
|
29
|
+
* // allowRenderWhenAnimating: false,
|
|
30
|
+
* // url: "wss://api.geops.io/tracker-ws/v1/",
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
*
|
|
34
|
+
* @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
|
|
35
|
+
* @see <a href="/example/ol-realtime">OpenLayers Realtime layer example</a>
|
|
36
|
+
*
|
|
37
|
+
*
|
|
38
|
+
* @extends {ol/layer/Layer~Layer}
|
|
39
|
+
*
|
|
40
|
+
*
|
|
41
|
+
* @classproperty {boolean} allowRenderWhenAnimating - Allow rendering of the layer when the map is animating.
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
declare class RealtimeLayer extends Layer {
|
|
45
|
+
allowRenderWhenAnimating?: boolean;
|
|
46
|
+
currentZoom?: number;
|
|
47
|
+
engine: RealtimeEngine;
|
|
48
|
+
maxNbFeaturesRequested: number;
|
|
49
|
+
olEventsKeys: EventsKey[];
|
|
50
|
+
onMoveEndDebounced: DebouncedFunc<(evt: MapEvent | ObjectEvent) => void>;
|
|
51
|
+
onZoomEndDebounced: DebouncedFunc<(evt: MapEvent | ObjectEvent) => void>;
|
|
52
|
+
renderedViewState: State | undefined;
|
|
53
|
+
vectorLayer: VectorLayer<VectorSource>;
|
|
54
|
+
get api(): RealtimeAPI;
|
|
55
|
+
set api(api: RealtimeAPI);
|
|
56
|
+
get canvas(): import("../../types").AnyCanvas | undefined;
|
|
57
|
+
get filter(): FilterFunction | undefined;
|
|
58
|
+
set filter(filter: FilterFunction);
|
|
59
|
+
get hoverVehicleId(): RealtimeTrainId | undefined;
|
|
60
|
+
set hoverVehicleId(id: RealtimeTrainId);
|
|
61
|
+
get mode(): RealtimeMode;
|
|
62
|
+
set mode(mode: RealtimeMode);
|
|
63
|
+
get pixelRatio(): number | undefined;
|
|
64
|
+
get selectedVehicleId(): RealtimeTrainId | undefined;
|
|
65
|
+
set selectedVehicleId(id: RealtimeTrainId);
|
|
66
|
+
get sort(): SortFunction | undefined;
|
|
67
|
+
set sort(sort: SortFunction);
|
|
68
|
+
get trajectories(): Record<string, import("../../types").RealtimeTrajectory> | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Constructor.
|
|
71
|
+
*
|
|
72
|
+
* @param {RealtimeLayerOptions} options
|
|
73
|
+
* @param {boolean} [options.allowRenderWhenAnimating=false] Allow rendering of the layer when the map is animating.
|
|
74
|
+
* @param {string} options.apiKey Access key for [geOps APIs](https://developer.geops.io/).
|
|
75
|
+
* @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The [geOps Realtime API](https://developer.geops.io/apis/realtime/) url.
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
constructor(options: RealtimeLayerOptions);
|
|
79
|
+
attachToMap(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Create a copy of the RealtimeLayer.
|
|
82
|
+
*
|
|
83
|
+
* @param {Object} newOptions Options to override. See constructor.
|
|
84
|
+
* @return {RealtimeLayer} A RealtimeLayer
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
clone(newOptions: RealtimeLayerOptions): RealtimeLayer;
|
|
88
|
+
createRenderer(): RealtimeLayerRenderer;
|
|
89
|
+
/**
|
|
90
|
+
* Destroy the container of the tracker.
|
|
91
|
+
*/
|
|
92
|
+
detachFromMap(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Get some informations about a trajectory.
|
|
95
|
+
*
|
|
96
|
+
* @param {RealtimeTrainId} id A vehicle's id.
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
getTrajectoryInfos(id: RealtimeTrainId): Promise<{
|
|
100
|
+
fullTrajectory: WebSocketAPIMessageEventData<RealtimeFullTrajectory> | WebSocketAPIMessageEventData<import("../../types").RealtimeStopSequence[]>;
|
|
101
|
+
stopSequence: WebSocketAPIMessageEventData<RealtimeFullTrajectory> | WebSocketAPIMessageEventData<import("../../types").RealtimeStopSequence[]>;
|
|
102
|
+
}>;
|
|
103
|
+
getVehicles(filterFunc: FilterFunction): import("../../types").RealtimeTrajectory[];
|
|
104
|
+
getViewState(): {
|
|
105
|
+
center?: undefined;
|
|
106
|
+
extent?: undefined;
|
|
107
|
+
pixelRatio?: undefined;
|
|
108
|
+
resolution?: undefined;
|
|
109
|
+
rotation?: undefined;
|
|
110
|
+
size?: undefined;
|
|
111
|
+
visible?: undefined;
|
|
112
|
+
zoom?: undefined;
|
|
113
|
+
} | {
|
|
114
|
+
center: import("ol/coordinate").Coordinate | undefined;
|
|
115
|
+
extent: import("ol/extent").Extent;
|
|
116
|
+
pixelRatio: number | undefined;
|
|
117
|
+
resolution: number | undefined;
|
|
118
|
+
rotation: number;
|
|
119
|
+
size: import("ol/size").Size | undefined;
|
|
120
|
+
visible: boolean;
|
|
121
|
+
zoom: number | undefined;
|
|
122
|
+
};
|
|
123
|
+
highlight(feature: Feature): void;
|
|
124
|
+
/**
|
|
125
|
+
* Highlight the trajectory of journey.
|
|
126
|
+
*/
|
|
127
|
+
highlightTrajectory(id: RealtimeTrainId): Promise<Feature[] | undefined>;
|
|
128
|
+
onMoveEnd(): void;
|
|
129
|
+
/**
|
|
130
|
+
* Callback when the RealtimeEngine has rendered successfully.
|
|
131
|
+
*/
|
|
132
|
+
onRealtimeEngineRender(renderState: RealtimeRenderState, viewState: ViewState): void;
|
|
133
|
+
onZoomEnd(): void;
|
|
134
|
+
select(feature: Feature): void;
|
|
135
|
+
setMapInternal(map: Map): void;
|
|
136
|
+
shouldRender(): boolean | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* Start the rendering.
|
|
139
|
+
*
|
|
140
|
+
* @public
|
|
141
|
+
*/
|
|
142
|
+
start(): void;
|
|
143
|
+
/**
|
|
144
|
+
* Stop the rendering.
|
|
145
|
+
*
|
|
146
|
+
* @public
|
|
147
|
+
*/
|
|
148
|
+
stop(): void;
|
|
149
|
+
}
|
|
150
|
+
export default RealtimeLayer;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import GeoJSON from 'ol/format/GeoJSON';
|
|
2
|
-
import { Vector as VectorLayer } from 'ol/layer';
|
|
3
|
-
import Source from 'ol/source/Source';
|
|
4
|
-
import { Vector as VectorSource } from 'ol/source';
|
|
5
1
|
import debounce from 'lodash.debounce';
|
|
2
|
+
import GeoJSON from 'ol/format/GeoJSON';
|
|
6
3
|
import Layer from 'ol/layer/Layer';
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
4
|
+
import VectorLayer from 'ol/layer/Vector';
|
|
5
|
+
import { unByKey } from 'ol/Observable';
|
|
6
|
+
import { Vector as VectorSource } from 'ol/source';
|
|
7
|
+
import Source from 'ol/source/Source';
|
|
8
|
+
import RealtimeEngine from '../../common/utils/RealtimeEngine';
|
|
10
9
|
import RealtimeLayerRenderer from '../renderers/RealtimeLayerRenderer';
|
|
11
|
-
|
|
10
|
+
import { fullTrajectoryStyle } from '../styles';
|
|
11
|
+
import defineDeprecatedProperties from '../utils/defineDeprecatedProperties';
|
|
12
12
|
const format = new GeoJSON();
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* An OpenLayers layer able to display data from the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* import { RealtimeLayer } from 'mobility-toolbox-js/ol';
|
|
@@ -24,73 +24,108 @@ const format = new GeoJSON();
|
|
|
24
24
|
*
|
|
25
25
|
*
|
|
26
26
|
* @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
|
|
27
|
+
* @see <a href="/example/ol-realtime">OpenLayers Realtime layer example</a>
|
|
28
|
+
*
|
|
27
29
|
*
|
|
28
30
|
* @extends {ol/layer/Layer~Layer}
|
|
29
31
|
*
|
|
32
|
+
*
|
|
30
33
|
* @classproperty {boolean} allowRenderWhenAnimating - Allow rendering of the layer when the map is animating.
|
|
31
34
|
* @public
|
|
32
35
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
class RealtimeLayer extends Layer {
|
|
37
|
+
get api() {
|
|
38
|
+
return this.engine.api;
|
|
39
|
+
}
|
|
40
|
+
set api(api) {
|
|
41
|
+
this.engine.api = api;
|
|
42
|
+
}
|
|
43
|
+
get canvas() {
|
|
44
|
+
return this.engine.canvas;
|
|
45
|
+
}
|
|
46
|
+
get filter() {
|
|
47
|
+
return this.engine.filter;
|
|
48
|
+
}
|
|
49
|
+
set filter(filter) {
|
|
50
|
+
this.engine.filter = filter;
|
|
51
|
+
}
|
|
52
|
+
get hoverVehicleId() {
|
|
53
|
+
return this.engine.hoverVehicleId;
|
|
54
|
+
}
|
|
55
|
+
set hoverVehicleId(id) {
|
|
56
|
+
this.engine.hoverVehicleId = id;
|
|
57
|
+
}
|
|
58
|
+
get mode() {
|
|
59
|
+
return this.engine.mode;
|
|
60
|
+
}
|
|
61
|
+
set mode(mode) {
|
|
62
|
+
this.engine.mode = mode;
|
|
63
|
+
}
|
|
64
|
+
get pixelRatio() {
|
|
65
|
+
return this.engine.pixelRatio;
|
|
66
|
+
}
|
|
67
|
+
get selectedVehicleId() {
|
|
68
|
+
return this.engine.selectedVehicleId;
|
|
69
|
+
}
|
|
70
|
+
set selectedVehicleId(id) {
|
|
71
|
+
this.engine.selectedVehicleId = id;
|
|
72
|
+
}
|
|
73
|
+
get sort() {
|
|
74
|
+
return this.engine.sort;
|
|
75
|
+
}
|
|
76
|
+
set sort(sort) {
|
|
77
|
+
this.engine.sort = sort;
|
|
78
|
+
}
|
|
79
|
+
get trajectories() {
|
|
80
|
+
return this.engine.trajectories;
|
|
81
|
+
}
|
|
35
82
|
/**
|
|
36
83
|
* Constructor.
|
|
37
84
|
*
|
|
38
85
|
* @param {RealtimeLayerOptions} options
|
|
39
86
|
* @param {boolean} [options.allowRenderWhenAnimating=false] Allow rendering of the layer when the map is animating.
|
|
40
|
-
* @param {string} options.apiKey Access key for [geOps
|
|
41
|
-
* @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps
|
|
42
|
-
*
|
|
87
|
+
* @param {string} options.apiKey Access key for [geOps APIs](https://developer.geops.io/).
|
|
88
|
+
* @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The [geOps Realtime API](https://developer.geops.io/apis/realtime/) url.
|
|
89
|
+
* @public
|
|
43
90
|
*/
|
|
44
91
|
constructor(options) {
|
|
45
92
|
// We use a group to be able to add custom vector layer in extended class.
|
|
46
93
|
// For example TrajservLayer use a vectorLayer to display the complete trajectory.
|
|
47
94
|
super(Object.assign({ source: new Source({}) }, options));
|
|
48
|
-
/** @private */
|
|
49
95
|
this.allowRenderWhenAnimating = false;
|
|
50
|
-
|
|
96
|
+
this.maxNbFeaturesRequested = 100;
|
|
97
|
+
this.olEventsKeys = [];
|
|
98
|
+
// For backward compatibility with v2
|
|
99
|
+
defineDeprecatedProperties(this, options);
|
|
100
|
+
this.engine = new RealtimeEngine(Object.assign({ getViewState: this.getViewState.bind(this), onRender: this.onRealtimeEngineRender.bind(this) }, options));
|
|
51
101
|
this.allowRenderWhenAnimating = !!options.allowRenderWhenAnimating;
|
|
52
102
|
// We store the layer used to highlight the full Trajectory
|
|
53
|
-
/** @private */
|
|
54
103
|
this.vectorLayer = new VectorLayer({
|
|
55
|
-
updateWhileAnimating: this.allowRenderWhenAnimating,
|
|
56
|
-
updateWhileInteracting: true,
|
|
57
104
|
source: new VectorSource({ features: [] }),
|
|
58
105
|
style: (feature, resolution) => {
|
|
59
|
-
return (options.fullTrajectoryStyle || fullTrajectoryStyle)(feature, resolution, this.styleOptions);
|
|
106
|
+
return (options.fullTrajectoryStyle || fullTrajectoryStyle)(feature, resolution, this.engine.styleOptions);
|
|
60
107
|
},
|
|
108
|
+
updateWhileAnimating: this.allowRenderWhenAnimating,
|
|
109
|
+
updateWhileInteracting: true,
|
|
61
110
|
});
|
|
62
|
-
// Options the last render run did happen. If something changes
|
|
63
|
-
// we have to render again
|
|
64
|
-
/** @private */
|
|
65
|
-
this.renderState = {
|
|
66
|
-
center: [0, 0],
|
|
67
|
-
zoom: undefined,
|
|
68
|
-
rotation: 0,
|
|
69
|
-
};
|
|
70
|
-
/** @private */
|
|
71
111
|
this.onZoomEndDebounced = debounce(this.onZoomEnd, 100);
|
|
72
|
-
/** @private */
|
|
73
112
|
this.onMoveEndDebounced = debounce(this.onMoveEnd, 100);
|
|
74
113
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return new RealtimeLayerRenderer(this);
|
|
80
|
-
}
|
|
81
|
-
/** @private */
|
|
82
|
-
attachToMap(map) {
|
|
83
|
-
super.attachToMap(map);
|
|
84
|
-
if (this.map) {
|
|
114
|
+
attachToMap() {
|
|
115
|
+
this.engine.attachToMap();
|
|
116
|
+
const mapInternal = this.getMapInternal();
|
|
117
|
+
if (mapInternal) {
|
|
85
118
|
// If the layer is visible we start the rendering clock
|
|
86
|
-
if (this.
|
|
87
|
-
this.start();
|
|
119
|
+
if (this.getVisible()) {
|
|
120
|
+
this.engine.start();
|
|
88
121
|
}
|
|
89
|
-
const index =
|
|
90
|
-
|
|
91
|
-
this.
|
|
122
|
+
const index = mapInternal.getLayers().getArray().indexOf(this);
|
|
123
|
+
mapInternal.getLayers().insertAt(index, this.vectorLayer);
|
|
124
|
+
this.olEventsKeys.push(...mapInternal.on(['moveend', 'change:target'],
|
|
125
|
+
// @ts-expect-error - bad ol definitions
|
|
126
|
+
(evt) => {
|
|
92
127
|
const view = (evt.map || evt.target).getView();
|
|
93
|
-
if (view.getAnimating() || view.getInteracting()) {
|
|
128
|
+
if (!view || (view === null || view === void 0 ? void 0 : view.getAnimating()) || (view === null || view === void 0 ? void 0 : view.getInteracting())) {
|
|
94
129
|
return;
|
|
95
130
|
}
|
|
96
131
|
const zoom = view.getZoom();
|
|
@@ -98,15 +133,14 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
|
|
|
98
133
|
if (this.currentZoom !== zoom) {
|
|
99
134
|
this.onZoomEndDebounced(evt);
|
|
100
135
|
}
|
|
101
|
-
/** @private */
|
|
102
136
|
this.currentZoom = zoom;
|
|
103
137
|
this.onMoveEndDebounced(evt);
|
|
104
138
|
}), this.on('change:visible', (evt) => {
|
|
105
|
-
if (evt.target.
|
|
106
|
-
this.start();
|
|
139
|
+
if (evt.target.getVisible()) {
|
|
140
|
+
this.engine.start();
|
|
107
141
|
}
|
|
108
142
|
else {
|
|
109
|
-
this.stop();
|
|
143
|
+
this.engine.stop();
|
|
110
144
|
}
|
|
111
145
|
}), this.on('propertychange', (evt) => {
|
|
112
146
|
// We apply every property change event related to visiblity to the vectorlayer
|
|
@@ -116,203 +150,173 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
|
|
|
116
150
|
}));
|
|
117
151
|
}
|
|
118
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Create a copy of the RealtimeLayer.
|
|
155
|
+
*
|
|
156
|
+
* @param {Object} newOptions Options to override. See constructor.
|
|
157
|
+
* @return {RealtimeLayer} A RealtimeLayer
|
|
158
|
+
* @public
|
|
159
|
+
*/
|
|
160
|
+
clone(newOptions) {
|
|
161
|
+
return new RealtimeLayer(Object.assign(Object.assign({}, this.get('options')), newOptions));
|
|
162
|
+
}
|
|
163
|
+
createRenderer() {
|
|
164
|
+
return new RealtimeLayerRenderer(this);
|
|
165
|
+
}
|
|
119
166
|
/**
|
|
120
167
|
* Destroy the container of the tracker.
|
|
121
|
-
* @private
|
|
122
168
|
*/
|
|
123
169
|
detachFromMap() {
|
|
124
170
|
var _a;
|
|
125
|
-
(
|
|
126
|
-
|
|
171
|
+
unByKey(this.olEventsKeys);
|
|
172
|
+
(_a = this.getMapInternal()) === null || _a === void 0 ? void 0 : _a.removeLayer(this.vectorLayer);
|
|
173
|
+
this.engine.detachFromMap();
|
|
127
174
|
}
|
|
128
175
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* @
|
|
132
|
-
* @
|
|
176
|
+
* Get some informations about a trajectory.
|
|
177
|
+
*
|
|
178
|
+
* @param {RealtimeTrainId} id A vehicle's id.
|
|
179
|
+
* @returns
|
|
133
180
|
*/
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
181
|
+
getTrajectoryInfos(id) {
|
|
182
|
+
var _a, _b;
|
|
183
|
+
// When a vehicle is selected, we request the complete stop sequence and the complete full trajectory.
|
|
184
|
+
// Then we combine them in one response and send them to inherited layers.
|
|
185
|
+
const promises = [
|
|
186
|
+
this.engine.api.getStopSequence(id),
|
|
187
|
+
this.engine.api.getFullTrajectory(id, this.engine.mode, this.engine.getGeneralizationLevelByZoom(Math.floor(((_b = (_a = this.getMapInternal()) === null || _a === void 0 ? void 0 : _a.getView()) === null || _b === void 0 ? void 0 : _b.getZoom()) || 0))),
|
|
188
|
+
];
|
|
189
|
+
return Promise.all(promises).then(([stopSequence, fullTrajectory]) => {
|
|
190
|
+
const response = {
|
|
191
|
+
fullTrajectory,
|
|
192
|
+
stopSequence,
|
|
193
|
+
};
|
|
194
|
+
return response;
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
getVehicles(filterFunc) {
|
|
198
|
+
return this.engine.getVehicles(filterFunc);
|
|
199
|
+
}
|
|
200
|
+
getViewState() {
|
|
201
|
+
const mapInternal = this.getMapInternal();
|
|
202
|
+
if (!(mapInternal === null || mapInternal === void 0 ? void 0 : mapInternal.getView())) {
|
|
203
|
+
return {};
|
|
144
204
|
}
|
|
145
|
-
|
|
146
|
-
|
|
205
|
+
const view = mapInternal.getView();
|
|
206
|
+
return {
|
|
147
207
|
center: view.getCenter(),
|
|
148
208
|
extent: view.calculateExtent(),
|
|
209
|
+
pixelRatio: this.engine.pixelRatio,
|
|
149
210
|
resolution: view.getResolution(),
|
|
150
211
|
rotation: view.getRotation(),
|
|
212
|
+
size: mapInternal.getSize(),
|
|
213
|
+
visible: this.getVisible(),
|
|
151
214
|
zoom: view.getZoom(),
|
|
152
|
-
|
|
153
|
-
}, noInterpolate);
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Launch renderTrajectories. it avoids duplicating code in renderTrajectories methhod.
|
|
157
|
-
* @private
|
|
158
|
-
* @override
|
|
159
|
-
*/
|
|
160
|
-
renderTrajectoriesInternal(viewState, noInterpolate) {
|
|
161
|
-
if (!this.map) {
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
let isRendered = false;
|
|
165
|
-
const blockRendering = this.allowRenderWhenAnimating
|
|
166
|
-
? false
|
|
167
|
-
: this.map.getView().getAnimating() ||
|
|
168
|
-
this.map.getView().getInteracting();
|
|
169
|
-
// Don't render the map when the map is animating or interacting.
|
|
170
|
-
isRendered = blockRendering
|
|
171
|
-
? false
|
|
172
|
-
: super.renderTrajectoriesInternal(viewState, noInterpolate);
|
|
173
|
-
// We update the current render state.
|
|
174
|
-
if (isRendered) {
|
|
175
|
-
/** @private */
|
|
176
|
-
this.renderedViewState = Object.assign({}, viewState);
|
|
177
|
-
if (this.getRenderer().container) {
|
|
178
|
-
this.getRenderer().container.style.transform = '';
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return isRendered;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Return the delay in ms before the next rendering.
|
|
185
|
-
* @private
|
|
186
|
-
*/
|
|
187
|
-
getRefreshTimeInMs() {
|
|
188
|
-
return super.getRefreshTimeInMs(this.map.getView().getZoom());
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* On move end we update the websocket with the new bbox.
|
|
192
|
-
*
|
|
193
|
-
* @private
|
|
194
|
-
* @override
|
|
195
|
-
*/
|
|
196
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
197
|
-
onMoveEnd(evt) {
|
|
198
|
-
if (!this.isUpdateBboxOnMoveEnd || !this.visible) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
this.setBbox();
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Function called on moveend event only when the zoom has changed.
|
|
205
|
-
*
|
|
206
|
-
* @param {ol/MapEvent~MapEvent} evt Moveend event.
|
|
207
|
-
* @private
|
|
208
|
-
* @override
|
|
209
|
-
*/
|
|
210
|
-
// eslint-disable-next-line no-unused-vars
|
|
211
|
-
onZoomEnd() {
|
|
212
|
-
super.onZoomEnd();
|
|
213
|
-
if (!this.isUpdateBboxOnMoveEnd || !this.visible) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
if (this.selectedVehicleId) {
|
|
217
|
-
this.highlightTrajectory(this.selectedVehicleId);
|
|
218
|
-
}
|
|
215
|
+
};
|
|
219
216
|
}
|
|
220
217
|
highlight(feature) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
this.highlightTrajectory(feature === null || feature === void 0 ? void 0 : feature.get('train_id'));
|
|
226
|
-
}
|
|
227
|
-
// /**
|
|
228
|
-
// * Update the cursor style when hovering a vehicle.
|
|
229
|
-
// *
|
|
230
|
-
// * @private
|
|
231
|
-
// * @override
|
|
232
|
-
// */
|
|
233
|
-
// onFeatureHover(
|
|
234
|
-
// features: Feature[],
|
|
235
|
-
// layer: RealtimeLayer,
|
|
236
|
-
// coordinate: Coordinate,
|
|
237
|
-
// ) {
|
|
238
|
-
// super.onFeatureHover(features, layer, coordinate);
|
|
239
|
-
// this.map.getTargetElement().style.cursor = features.length
|
|
240
|
-
// ? 'pointer'
|
|
241
|
-
// : 'auto';
|
|
242
|
-
// }
|
|
243
|
-
// /**
|
|
244
|
-
// * Display the complete trajectory of the vehicle.
|
|
245
|
-
// *
|
|
246
|
-
// * @private
|
|
247
|
-
// * @override
|
|
248
|
-
// */
|
|
249
|
-
// onFeatureClick(
|
|
250
|
-
// features: Feature[],
|
|
251
|
-
// layer: RealtimeLayer,
|
|
252
|
-
// coordinate: Coordinate,
|
|
253
|
-
// ) {
|
|
254
|
-
// super.onFeatureClick(features, layer, coordinate);
|
|
255
|
-
// this.highlightTrajectory(this.selectedVehicleId);
|
|
256
|
-
// }
|
|
257
|
-
/**
|
|
258
|
-
* Remove the trajectory form the list if necessary.
|
|
259
|
-
*
|
|
260
|
-
* @private
|
|
261
|
-
*/
|
|
262
|
-
purgeTrajectory(trajectory, extent, zoom) {
|
|
263
|
-
const center = this.map.getView().getCenter();
|
|
264
|
-
if (!extent && !center) {
|
|
265
|
-
// In that case the view is not zoomed yet so we can't calculate the extent of the map,
|
|
266
|
-
// it will trigger a js error on calculateExtent function.
|
|
267
|
-
return false;
|
|
218
|
+
const id = feature === null || feature === void 0 ? void 0 : feature.get('train_id');
|
|
219
|
+
if (this.hoverVehicleId !== id) {
|
|
220
|
+
this.hoverVehicleId = id;
|
|
221
|
+
this.engine.renderTrajectories(true);
|
|
268
222
|
}
|
|
269
|
-
return super.purgeTrajectory(trajectory, extent || this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom());
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Send the current bbox to the websocket
|
|
273
|
-
*
|
|
274
|
-
* @private
|
|
275
|
-
*/
|
|
276
|
-
setBbox(extent, zoom) {
|
|
277
|
-
super.setBbox(extent || this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom());
|
|
278
223
|
}
|
|
279
224
|
/**
|
|
280
225
|
* Highlight the trajectory of journey.
|
|
281
|
-
* @private
|
|
282
226
|
*/
|
|
283
227
|
highlightTrajectory(id) {
|
|
284
|
-
var _a, _b;
|
|
228
|
+
var _a, _b, _c, _d;
|
|
285
229
|
if (!id) {
|
|
286
|
-
this.vectorLayer.getSource().clear(true);
|
|
230
|
+
(_b = (_a = this.vectorLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear(true);
|
|
287
231
|
return Promise.resolve([]);
|
|
288
232
|
}
|
|
289
|
-
return this.api
|
|
290
|
-
.getFullTrajectory(id, this.mode, this.getGeneralizationLevelByZoom(Math.floor(((
|
|
233
|
+
return this.engine.api
|
|
234
|
+
.getFullTrajectory(id, this.engine.mode, this.engine.getGeneralizationLevelByZoom(Math.floor(((_d = (_c = this.getMapInternal()) === null || _c === void 0 ? void 0 : _c.getView()) === null || _d === void 0 ? void 0 : _d.getZoom()) || 0)))
|
|
291
235
|
.then((data) => {
|
|
292
|
-
var _a;
|
|
236
|
+
var _a, _b, _c, _d, _e;
|
|
293
237
|
const fullTrajectory = data.content;
|
|
294
238
|
if (!((_a = fullTrajectory === null || fullTrajectory === void 0 ? void 0 : fullTrajectory.features) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
295
239
|
return [];
|
|
296
240
|
}
|
|
297
241
|
const features = format.readFeatures(fullTrajectory);
|
|
298
|
-
this.vectorLayer.getSource().clear(true);
|
|
242
|
+
(_c = (_b = this.vectorLayer) === null || _b === void 0 ? void 0 : _b.getSource()) === null || _c === void 0 ? void 0 : _c.clear(true);
|
|
299
243
|
if (features.length) {
|
|
300
|
-
this.vectorLayer.getSource().addFeatures(features);
|
|
244
|
+
(_e = (_d = this.vectorLayer) === null || _d === void 0 ? void 0 : _d.getSource()) === null || _e === void 0 ? void 0 : _e.addFeatures(features);
|
|
301
245
|
}
|
|
302
246
|
return features;
|
|
303
247
|
})
|
|
304
248
|
.catch(() => {
|
|
305
|
-
|
|
249
|
+
var _a, _b;
|
|
250
|
+
(_b = (_a = this.vectorLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear(true);
|
|
306
251
|
return [];
|
|
307
252
|
});
|
|
308
253
|
}
|
|
254
|
+
onMoveEnd() {
|
|
255
|
+
if (!this.engine.isUpdateBboxOnMoveEnd || !this.getVisible()) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
this.engine.setBbox();
|
|
259
|
+
}
|
|
309
260
|
/**
|
|
310
|
-
*
|
|
311
|
-
* @param {Object} newOptions Options to override
|
|
312
|
-
* @return {RealtimeLayer} A RealtimeLayer
|
|
261
|
+
* Callback when the RealtimeEngine has rendered successfully.
|
|
313
262
|
*/
|
|
314
|
-
|
|
315
|
-
|
|
263
|
+
onRealtimeEngineRender(renderState, viewState) {
|
|
264
|
+
this.renderedViewState = Object.assign({}, viewState);
|
|
265
|
+
// @ts-expect-error - we are in the same class
|
|
266
|
+
const { container } = this.getRenderer();
|
|
267
|
+
if (container) {
|
|
268
|
+
container.style.transform = '';
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
onZoomEnd() {
|
|
272
|
+
this.engine.onZoomEnd();
|
|
273
|
+
if (!this.engine.isUpdateBboxOnMoveEnd || !this.getVisible()) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
if (this.selectedVehicleId) {
|
|
277
|
+
this.highlightTrajectory(this.selectedVehicleId);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
select(feature) {
|
|
281
|
+
const id = feature === null || feature === void 0 ? void 0 : feature.get('train_id');
|
|
282
|
+
if (this.selectedVehicleId !== id) {
|
|
283
|
+
this.selectedVehicleId = id;
|
|
284
|
+
this.engine.renderTrajectories(true);
|
|
285
|
+
}
|
|
286
|
+
this.highlightTrajectory(id);
|
|
287
|
+
}
|
|
288
|
+
setMapInternal(map) {
|
|
289
|
+
if (map) {
|
|
290
|
+
super.setMapInternal(map);
|
|
291
|
+
this.attachToMap();
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
this.detachFromMap();
|
|
295
|
+
super.setMapInternal(map);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
shouldRender() {
|
|
299
|
+
var _a, _b;
|
|
300
|
+
return this.allowRenderWhenAnimating
|
|
301
|
+
? false
|
|
302
|
+
: ((_a = this.getMapInternal()) === null || _a === void 0 ? void 0 : _a.getView().getAnimating()) ||
|
|
303
|
+
((_b = this.getMapInternal()) === null || _b === void 0 ? void 0 : _b.getView().getInteracting());
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Start the rendering.
|
|
307
|
+
*
|
|
308
|
+
* @public
|
|
309
|
+
*/
|
|
310
|
+
start() {
|
|
311
|
+
this.engine.start();
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Stop the rendering.
|
|
315
|
+
*
|
|
316
|
+
* @public
|
|
317
|
+
*/
|
|
318
|
+
stop() {
|
|
319
|
+
this.engine.stop();
|
|
316
320
|
}
|
|
317
321
|
}
|
|
318
322
|
export default RealtimeLayer;
|