mobility-toolbox-js 3.0.0-beta.31 → 3.0.0-beta.33
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 +3 -3
- package/api/WebSocketAPI.js +0 -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 +224 -0
- package/common/utils/RealtimeEngine.js +565 -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/maplibre/layers/RealtimeLayer.d.ts +50 -109
- package/maplibre/layers/RealtimeLayer.js +108 -111
- package/mbt.js +5122 -13362
- package/mbt.js.map +4 -4
- package/mbt.min.js +67 -70
- package/mbt.min.js.map +4 -4
- package/ol/controls/RoutingControl.d.ts +5 -4
- package/ol/controls/RoutingControl.js +2 -29
- package/ol/controls/StopFinderControl.d.ts +2 -5
- package/ol/controls/StopFinderControl.js +0 -3
- package/ol/layers/MaplibreLayer.d.ts +29 -18
- package/ol/layers/MaplibreLayer.js +18 -10
- package/ol/layers/MaplibreStyleLayer.d.ts +39 -27
- package/ol/layers/MaplibreStyleLayer.js +33 -28
- package/ol/layers/RealtimeLayer.d.ts +72 -124
- package/ol/layers/RealtimeLayer.js +130 -168
- 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 +31 -30
- package/types/common.d.ts +2 -1
- package/common/mixins/RealtimeLayerMixin.d.ts +0 -267
- package/common/mixins/RealtimeLayerMixin.js +0 -751
|
@@ -1,82 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CanvasSourceSpecification, LayerSpecification } from 'maplibre-gl';
|
|
2
|
+
import RealtimeEngine, { RealtimeEngineOptions } from '../../common/utils/RealtimeEngine';
|
|
2
3
|
import Layer, { LayerOptions } from './Layer';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
export type RealtimeLayerOptions = LayerOptions & RealtimeLayerMixinOptions;
|
|
6
|
-
declare const RealtimeLayer_base: {
|
|
7
|
-
new (options: RealtimeLayerMixinOptions): {
|
|
8
|
-
[x: string]: any;
|
|
9
|
-
[x: symbol]: any;
|
|
10
|
-
api: import("..").RealtimeAPI;
|
|
11
|
-
bboxParameters?: Record<string, boolean | boolean[] | number | number[] | string | string[]>;
|
|
12
|
-
canvas?: import("../../types").AnyCanvas;
|
|
13
|
-
debounceRenderTrajectories: (viewState: ViewState, noInterpolate?: boolean) => void;
|
|
14
|
-
debug: boolean;
|
|
15
|
-
filter?: import("../../common/typedefs").FilterFunction;
|
|
16
|
-
format: import("ol/format").GeoJSON;
|
|
17
|
-
generalizationLevel?: import("../../types").RealtimeGeneralizationLevel;
|
|
18
|
-
generalizationLevelByZoom: import("../../types").RealtimeGeneralizationLevel[];
|
|
19
|
-
getGeneralizationLevelByZoom: (zoom: number) => import("../../types").RealtimeGeneralizationLevel;
|
|
20
|
-
getMotsByZoom: (zoom: number) => import("../../types").RealtimeMot[];
|
|
21
|
-
getRenderTimeIntervalByZoom: (zoom: number) => number;
|
|
22
|
-
hoverVehicleId?: import("../../types").RealtimeTrainId;
|
|
23
|
-
isUpdateBboxOnMoveEnd: boolean;
|
|
24
|
-
live?: boolean;
|
|
25
|
-
minZoomInterpolation: number;
|
|
26
|
-
mode: import("../../types").RealtimeMode;
|
|
27
|
-
mots?: import("../../types").RealtimeMot[];
|
|
28
|
-
motsByZoom: import("../../types").RealtimeMot[][];
|
|
29
|
-
onStart?: ((realtimeLayer: import("../../types").AnyLayer) => void) | undefined;
|
|
30
|
-
onStop?: ((realtimeLayer: import("../../types").AnyLayer) => void) | undefined;
|
|
31
|
-
pixelRatio?: number;
|
|
32
|
-
renderState?: import("../../types").RealtimeRenderState;
|
|
33
|
-
renderTimeIntervalByZoom: number[];
|
|
34
|
-
requestId?: number;
|
|
35
|
-
selectedVehicle: import("../../types").RealtimeTrajectory;
|
|
36
|
-
selectedVehicleId?: import("../../types").RealtimeTrainId;
|
|
37
|
-
sort?: import("../../common/typedefs").SortFunction;
|
|
38
|
-
speed?: number;
|
|
39
|
-
style?: import("../../types").RealtimeStyleFunction;
|
|
40
|
-
styleOptions?: import("../../types").RealtimeStyleOptions;
|
|
41
|
-
tenant: import("../../types").RealtimeTenant;
|
|
42
|
-
throttleRenderTrajectories: (viewState: ViewState, noInterpolate?: boolean) => void;
|
|
43
|
-
time?: Date;
|
|
44
|
-
trajectories?: Record<import("../../types").RealtimeTrainId, import("../../types").RealtimeTrajectory>;
|
|
45
|
-
updateTimeDelay?: number;
|
|
46
|
-
updateTimeInterval?: number;
|
|
47
|
-
useDebounce?: boolean;
|
|
48
|
-
useRequestAnimationFrame?: boolean;
|
|
49
|
-
useThrottle?: boolean;
|
|
50
|
-
visibilityRef: import("ol/events").EventsKey;
|
|
51
|
-
addTrajectory(trajectory: import("../../types").RealtimeTrajectory): void;
|
|
52
|
-
attachToMap(map: import("../../types").AnyMap): void;
|
|
53
|
-
defineProperties(options: RealtimeLayerMixinOptions): void;
|
|
54
|
-
detachFromMap(): void;
|
|
55
|
-
getFeatureInfoAtCoordinate(coordinate: import("ol/coordinate").Coordinate, options: import("../../types").LayerGetFeatureInfoOptions): Promise<import("../../types").LayerGetFeatureInfoResponse>;
|
|
56
|
-
getRefreshTimeInMs(zoom?: number | undefined): number;
|
|
57
|
-
getTrajectoryInfos(id: import("../../types").RealtimeTrainId): Promise<{
|
|
58
|
-
fullTrajectory: import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeStopSequence[]> | import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeFullTrajectory>;
|
|
59
|
-
stopSequence: import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeStopSequence[]> | import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeFullTrajectory>;
|
|
60
|
-
}>;
|
|
61
|
-
getVehicle(filterFc: import("../../common/typedefs").FilterFunction): import("../../types").RealtimeTrajectory[];
|
|
62
|
-
highlightVehicle(id: import("../../types").RealtimeTrainId): void;
|
|
63
|
-
onDeleteTrajectoryMessage(data: import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeTrainId>): void;
|
|
64
|
-
onDocumentVisibilityChange(): void;
|
|
65
|
-
onTrajectoryMessage(data: import("../../api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeTrajectory>): void;
|
|
66
|
-
onZoomEnd(): void;
|
|
67
|
-
purgeOutOfDateTrajectories(): void;
|
|
68
|
-
purgeTrajectory(trajectory: import("../../types").RealtimeTrajectory, extent: [number, number, number, number], zoom: number): boolean;
|
|
69
|
-
removeTrajectory(trajectoryOrId: import("../../types").RealtimeTrainId | import("../../types").RealtimeTrajectory): void;
|
|
70
|
-
renderTrajectories(viewState: undefined | ViewState, noInterpolate: boolean | undefined): void;
|
|
71
|
-
renderTrajectoriesInternal(viewState: ViewState, noInterpolate?: boolean): boolean;
|
|
72
|
-
selectVehicle(id: import("../../types").RealtimeTrainId): void;
|
|
73
|
-
setBbox(extent: [number, number, number, number], zoom: number): void;
|
|
74
|
-
start(): void;
|
|
75
|
-
startUpdateTime(): void;
|
|
76
|
-
stop(): void;
|
|
77
|
-
stopUpdateTime(): void;
|
|
78
|
-
};
|
|
79
|
-
} & typeof Layer;
|
|
4
|
+
import type { AnyCanvas, AnyMapGlMap } from '../../types';
|
|
5
|
+
export type RealtimeLayerOptions = LayerOptions & RealtimeEngineOptions;
|
|
80
6
|
/**
|
|
81
7
|
* A Maplibre layer able to display data from the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
|
|
82
8
|
*
|
|
@@ -113,7 +39,10 @@ declare const RealtimeLayer_base: {
|
|
|
113
39
|
s
|
|
114
40
|
* @public
|
|
115
41
|
*/
|
|
116
|
-
declare class RealtimeLayer extends
|
|
42
|
+
declare class RealtimeLayer extends Layer {
|
|
43
|
+
engine: RealtimeEngine;
|
|
44
|
+
layer: LayerSpecification;
|
|
45
|
+
source: CanvasSourceSpecification;
|
|
117
46
|
/**
|
|
118
47
|
* Constructor.
|
|
119
48
|
*
|
|
@@ -129,15 +58,51 @@ declare class RealtimeLayer extends RealtimeLayer_base {
|
|
|
129
58
|
* @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps Realtime API url.
|
|
130
59
|
*/
|
|
131
60
|
constructor(options?: {});
|
|
61
|
+
/**
|
|
62
|
+
* Return the current view state. Used by the RealtimeEngine.
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
getViewState(): {
|
|
66
|
+
center?: undefined;
|
|
67
|
+
extent?: undefined;
|
|
68
|
+
pixelRatio?: undefined;
|
|
69
|
+
resolution?: undefined;
|
|
70
|
+
rotation?: undefined;
|
|
71
|
+
size?: undefined;
|
|
72
|
+
visible?: undefined;
|
|
73
|
+
zoom?: undefined;
|
|
74
|
+
} | {
|
|
75
|
+
center: import("ol/coordinate").Coordinate;
|
|
76
|
+
extent: number[];
|
|
77
|
+
pixelRatio: number;
|
|
78
|
+
resolution: number;
|
|
79
|
+
rotation: number;
|
|
80
|
+
size: number[];
|
|
81
|
+
visible: boolean;
|
|
82
|
+
zoom: number;
|
|
83
|
+
};
|
|
132
84
|
/**
|
|
133
85
|
* Add sources, layers and listeners to the map.
|
|
134
86
|
*/
|
|
135
|
-
onAdd(map: AnyMapGlMap, gl:
|
|
87
|
+
onAdd(map: AnyMapGlMap, gl: WebGL2RenderingContext | WebGLRenderingContext): void;
|
|
88
|
+
onLoad(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Callback on 'move' event.
|
|
91
|
+
*/
|
|
92
|
+
onMove(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Callback on 'moveend' event.
|
|
95
|
+
*/
|
|
96
|
+
onMoveEnd(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Callback when the RealtimeEngine has rendered successfully.
|
|
99
|
+
*/
|
|
100
|
+
onRealtimeEngineRender(): void;
|
|
136
101
|
/**
|
|
137
102
|
* Remove source, layers and listeners from the map.
|
|
138
103
|
*/
|
|
139
|
-
onRemove(map: AnyMapGlMap, gl:
|
|
140
|
-
|
|
104
|
+
onRemove(map: AnyMapGlMap, gl: WebGL2RenderingContext | WebGLRenderingContext): void;
|
|
105
|
+
onZoomEnd(): void;
|
|
141
106
|
/**
|
|
142
107
|
* Start updating vehicles position.
|
|
143
108
|
*
|
|
@@ -150,32 +115,8 @@ declare class RealtimeLayer extends RealtimeLayer_base {
|
|
|
150
115
|
* @public
|
|
151
116
|
*/
|
|
152
117
|
stop(): void;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
* @private
|
|
157
|
-
*/
|
|
158
|
-
renderTrajectories(noInterpolate?: boolean): void;
|
|
159
|
-
/**
|
|
160
|
-
* Return the delay in ms before the next rendering.
|
|
161
|
-
*/
|
|
162
|
-
getRefreshTimeInMs(): number;
|
|
163
|
-
/**
|
|
164
|
-
* Remove the trajectory form the list if necessary.
|
|
165
|
-
*/
|
|
166
|
-
purgeTrajectory(trajectory: RealtimeTrajectory, extent: [number, number, number, number], zoom: number): boolean;
|
|
167
|
-
/**
|
|
168
|
-
* Send the current bbox to the websocket
|
|
169
|
-
*/
|
|
170
|
-
setBbox(extent?: [number, number, number, number], zoom?: number): void;
|
|
171
|
-
renderTrajectoriesInternal(viewState: ViewState, noInterpolate?: boolean): boolean;
|
|
172
|
-
/**
|
|
173
|
-
* Callback on 'move' event.
|
|
174
|
-
*/
|
|
175
|
-
onMove(): void;
|
|
176
|
-
/**
|
|
177
|
-
* Callback on 'moveend' event.
|
|
178
|
-
*/
|
|
179
|
-
onMoveEnd(): void;
|
|
118
|
+
get canvas(): AnyCanvas | undefined;
|
|
119
|
+
get pixelRatio(): number | undefined;
|
|
120
|
+
set pixelRatio(pixelRatio: number | undefined);
|
|
180
121
|
}
|
|
181
122
|
export default RealtimeLayer;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import { fromLonLat } from 'ol/proj';
|
|
3
|
-
import { getWidth, getHeight } from 'ol/extent';
|
|
4
|
-
import transformRotate from '@turf/transform-rotate';
|
|
5
1
|
import { point } from '@turf/helpers';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
2
|
+
import transformRotate from '@turf/transform-rotate';
|
|
3
|
+
import { getHeight, getWidth } from 'ol/extent';
|
|
4
|
+
import { fromLonLat } from 'ol/proj';
|
|
5
|
+
import RealtimeEngine from '../../common/utils/RealtimeEngine';
|
|
8
6
|
import { getSourceCoordinates } from '../utils';
|
|
9
|
-
import
|
|
7
|
+
import Layer from './Layer';
|
|
10
8
|
/**
|
|
11
9
|
* A Maplibre layer able to display data from the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
|
|
12
10
|
*
|
|
@@ -43,7 +41,7 @@ import toMercatorExtent from '../../common/utils/toMercatorExtent';
|
|
|
43
41
|
s
|
|
44
42
|
* @public
|
|
45
43
|
*/
|
|
46
|
-
class RealtimeLayer extends
|
|
44
|
+
class RealtimeLayer extends Layer {
|
|
47
45
|
/**
|
|
48
46
|
* Constructor.
|
|
49
47
|
*
|
|
@@ -60,12 +58,13 @@ class RealtimeLayer extends RealtimeLayerMixin(Layer) {
|
|
|
60
58
|
*/
|
|
61
59
|
constructor(options = {}) {
|
|
62
60
|
var _a;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
/** @private */
|
|
61
|
+
super(Object.assign({ id: 'realtime' }, options));
|
|
62
|
+
this.engine = new RealtimeEngine(Object.assign({ getViewState: this.getViewState.bind(this), onRender: this.onRealtimeEngineRender.bind(this) }, options));
|
|
66
63
|
this.source = {
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
// Set to true if the canvas source is animated. If the canvas is static, animate should be set to false to improve performance.
|
|
65
|
+
animate: true,
|
|
66
|
+
// @ts-expect-error bad type definition
|
|
67
|
+
attribution: (_a = options.attribution) === null || _a === void 0 ? void 0 : _a.join(', '),
|
|
69
68
|
canvas: this.canvas,
|
|
70
69
|
// Set a default coordinates, it will be overrides on next data update
|
|
71
70
|
coordinates: [
|
|
@@ -74,108 +73,49 @@ class RealtimeLayer extends RealtimeLayerMixin(Layer) {
|
|
|
74
73
|
[2, 2],
|
|
75
74
|
[0, 0],
|
|
76
75
|
],
|
|
77
|
-
|
|
78
|
-
animate: true,
|
|
79
|
-
attribution: (_a = options.attribution) === null || _a === void 0 ? void 0 : _a.join(', '),
|
|
76
|
+
id: this.id,
|
|
80
77
|
loaded: true,
|
|
78
|
+
type: 'canvas',
|
|
81
79
|
};
|
|
82
|
-
/** @private */
|
|
83
80
|
this.layer = {
|
|
84
81
|
id: `${this.id}-raster`,
|
|
85
|
-
type: 'raster',
|
|
86
|
-
source: this.id,
|
|
87
82
|
layout: {
|
|
88
83
|
visibility: 'visible',
|
|
89
84
|
},
|
|
90
85
|
paint: {
|
|
91
|
-
'raster-opacity': 1,
|
|
92
86
|
'raster-fade-duration': 0,
|
|
87
|
+
'raster-opacity': 1,
|
|
93
88
|
'raster-resampling': 'nearest', // important otherwise it looks blurry
|
|
94
89
|
},
|
|
90
|
+
source: this.id,
|
|
91
|
+
type: 'raster',
|
|
95
92
|
};
|
|
96
|
-
/** @private */
|
|
97
93
|
this.onLoad = this.onLoad.bind(this);
|
|
98
|
-
/** @private */
|
|
99
94
|
this.onMove = this.onMove.bind(this);
|
|
100
|
-
/** @private */
|
|
101
95
|
this.onMoveEnd = this.onMoveEnd.bind(this);
|
|
102
|
-
/** @private */
|
|
103
96
|
this.onZoomEnd = this.onZoomEnd.bind(this);
|
|
104
97
|
}
|
|
105
98
|
/**
|
|
106
|
-
*
|
|
107
|
-
*/
|
|
108
|
-
onAdd(map, gl) {
|
|
109
|
-
super.onAdd(map, gl);
|
|
110
|
-
if (map.isStyleLoaded()) {
|
|
111
|
-
this.onLoad();
|
|
112
|
-
}
|
|
113
|
-
map.on('load', this.onLoad);
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Remove source, layers and listeners from the map.
|
|
117
|
-
*/
|
|
118
|
-
onRemove(map, gl) {
|
|
119
|
-
map.off('load', this.onLoad);
|
|
120
|
-
if (map.getLayer(this.layer.id)) {
|
|
121
|
-
map.removeLayer(this.layer.id);
|
|
122
|
-
}
|
|
123
|
-
if (map.getSource(this.id)) {
|
|
124
|
-
map.removeSource(this.id);
|
|
125
|
-
}
|
|
126
|
-
super.onRemove(map, gl);
|
|
127
|
-
}
|
|
128
|
-
onLoad() {
|
|
129
|
-
if (!this.map.getSource(this.id)) {
|
|
130
|
-
this.map.addSource(this.id, this.source);
|
|
131
|
-
}
|
|
132
|
-
if (!this.map.getLayer(this.layer.id)) {
|
|
133
|
-
this.map.addLayer(this.layer, this.id);
|
|
134
|
-
}
|
|
135
|
-
this.start();
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Start updating vehicles position.
|
|
139
|
-
*
|
|
140
|
-
* @public
|
|
141
|
-
*/
|
|
142
|
-
start() {
|
|
143
|
-
super.start();
|
|
144
|
-
this.map.on('move', this.onMove);
|
|
145
|
-
this.map.on('moveend', this.onMoveEnd);
|
|
146
|
-
this.map.on('zoomend', this.onZoomEnd);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Stop updating vehicles position.
|
|
150
|
-
*
|
|
151
|
-
* @public
|
|
152
|
-
*/
|
|
153
|
-
stop() {
|
|
154
|
-
var _a, _b, _c;
|
|
155
|
-
super.stop();
|
|
156
|
-
(_a = this.map) === null || _a === void 0 ? void 0 : _a.off('move', this.onMove);
|
|
157
|
-
(_b = this.map) === null || _b === void 0 ? void 0 : _b.off('moveend', this.onMoveEnd);
|
|
158
|
-
(_c = this.map) === null || _c === void 0 ? void 0 : _c.off('zoomend', this.onZoomEnd);
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Render the trajectories using current map's size, resolution and rotation.
|
|
162
|
-
* @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
|
|
99
|
+
* Return the current view state. Used by the RealtimeEngine.
|
|
163
100
|
* @private
|
|
164
101
|
*/
|
|
165
|
-
|
|
102
|
+
getViewState() {
|
|
103
|
+
console.log(this);
|
|
166
104
|
if (!this.map) {
|
|
167
|
-
return;
|
|
105
|
+
return {};
|
|
168
106
|
}
|
|
169
107
|
if (!this.pixelRatio) {
|
|
170
108
|
this.pixelRatio = 1;
|
|
171
109
|
}
|
|
172
|
-
const {
|
|
110
|
+
const { height, width } = this.map.getCanvas();
|
|
173
111
|
const center = this.map.getCenter();
|
|
174
112
|
// We use turf here to have good transform.
|
|
113
|
+
// @ts-expect-error bad type definition
|
|
175
114
|
const leftBottom = this.map.unproject({
|
|
176
115
|
x: 0,
|
|
177
116
|
y: height / this.pixelRatio,
|
|
178
117
|
}); // southWest
|
|
118
|
+
// @ts-expect-error bad type definition
|
|
179
119
|
const rightTop = this.map.unproject({
|
|
180
120
|
x: width / this.pixelRatio,
|
|
181
121
|
y: 0,
|
|
@@ -191,60 +131,117 @@ class RealtimeLayer extends RealtimeLayerMixin(Layer) {
|
|
|
191
131
|
const yResolution = getHeight(bounds) / (height / this.pixelRatio);
|
|
192
132
|
const res = Math.max(xResolution, yResolution);
|
|
193
133
|
// Coordinate of trajectories are in mercator so we have to pass the proper resolution and center in mercator.
|
|
194
|
-
|
|
195
|
-
size: [width / this.pixelRatio, height / this.pixelRatio],
|
|
134
|
+
return {
|
|
196
135
|
center: fromLonLat([center.lng, center.lat]),
|
|
197
136
|
extent: bounds,
|
|
137
|
+
pixelRatio: this.pixelRatio,
|
|
198
138
|
resolution: res,
|
|
199
|
-
zoom: this.map.getZoom() - 1,
|
|
200
139
|
rotation: -(this.map.getBearing() * Math.PI) / 180,
|
|
201
|
-
|
|
140
|
+
size: [width / this.pixelRatio, height / this.pixelRatio],
|
|
141
|
+
visible: true,
|
|
142
|
+
zoom: this.map.getZoom() - 1,
|
|
202
143
|
};
|
|
203
|
-
super.renderTrajectories(viewState, noInterpolate);
|
|
204
144
|
}
|
|
205
145
|
/**
|
|
206
|
-
*
|
|
146
|
+
* Add sources, layers and listeners to the map.
|
|
207
147
|
*/
|
|
208
|
-
|
|
209
|
-
|
|
148
|
+
onAdd(map, gl) {
|
|
149
|
+
super.onAdd(map, gl);
|
|
150
|
+
this.engine.attachToMap();
|
|
151
|
+
if (map.isStyleLoaded()) {
|
|
152
|
+
this.onLoad();
|
|
153
|
+
}
|
|
154
|
+
map.on('load', this.onLoad);
|
|
155
|
+
}
|
|
156
|
+
onLoad() {
|
|
157
|
+
var _a, _b, _c, _d;
|
|
158
|
+
if (!((_a = this.map) === null || _a === void 0 ? void 0 : _a.getSource(this.id))) {
|
|
159
|
+
(_b = this.map) === null || _b === void 0 ? void 0 : _b.addSource(this.id, this.source);
|
|
160
|
+
}
|
|
161
|
+
if (!((_c = this.map) === null || _c === void 0 ? void 0 : _c.getLayer(this.layer.id))) {
|
|
162
|
+
(_d = this.map) === null || _d === void 0 ? void 0 : _d.addLayer(this.layer, this.id);
|
|
163
|
+
}
|
|
164
|
+
this.start();
|
|
210
165
|
}
|
|
211
166
|
/**
|
|
212
|
-
*
|
|
167
|
+
* Callback on 'move' event.
|
|
213
168
|
*/
|
|
214
|
-
|
|
215
|
-
|
|
169
|
+
onMove() {
|
|
170
|
+
this.engine.renderTrajectories();
|
|
216
171
|
}
|
|
217
172
|
/**
|
|
218
|
-
*
|
|
173
|
+
* Callback on 'moveend' event.
|
|
219
174
|
*/
|
|
220
|
-
|
|
221
|
-
|
|
175
|
+
onMoveEnd() {
|
|
176
|
+
this.engine.renderTrajectories();
|
|
177
|
+
if (this.engine.isUpdateBboxOnMoveEnd) {
|
|
178
|
+
this.engine.setBbox();
|
|
179
|
+
}
|
|
222
180
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
181
|
+
/**
|
|
182
|
+
* Callback when the RealtimeEngine has rendered successfully.
|
|
183
|
+
*/
|
|
184
|
+
onRealtimeEngineRender() {
|
|
185
|
+
var _a;
|
|
186
|
+
if ((_a = this.map) === null || _a === void 0 ? void 0 : _a.style) {
|
|
226
187
|
const extent = getSourceCoordinates(this.map, this.pixelRatio);
|
|
227
188
|
const source = this.map.getSource(this.id);
|
|
228
189
|
if (source) {
|
|
190
|
+
// @ts-expect-error bad type definition
|
|
229
191
|
source.setCoordinates(extent);
|
|
230
192
|
}
|
|
231
193
|
}
|
|
232
|
-
return render;
|
|
233
194
|
}
|
|
234
195
|
/**
|
|
235
|
-
*
|
|
196
|
+
* Remove source, layers and listeners from the map.
|
|
236
197
|
*/
|
|
237
|
-
|
|
238
|
-
this.
|
|
198
|
+
onRemove(map, gl) {
|
|
199
|
+
this.engine.detachFromMap();
|
|
200
|
+
this.stop();
|
|
201
|
+
map.off('load', this.onLoad);
|
|
202
|
+
if (map.getLayer(this.layer.id)) {
|
|
203
|
+
map.removeLayer(this.layer.id);
|
|
204
|
+
}
|
|
205
|
+
if (map.getSource(this.id)) {
|
|
206
|
+
map.removeSource(this.id);
|
|
207
|
+
}
|
|
208
|
+
super.onRemove(map, gl);
|
|
209
|
+
}
|
|
210
|
+
onZoomEnd() {
|
|
211
|
+
this.engine.onZoomEnd();
|
|
239
212
|
}
|
|
240
213
|
/**
|
|
241
|
-
*
|
|
214
|
+
* Start updating vehicles position.
|
|
215
|
+
*
|
|
216
|
+
* @public
|
|
242
217
|
*/
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
218
|
+
start() {
|
|
219
|
+
var _a, _b, _c;
|
|
220
|
+
this.engine.start();
|
|
221
|
+
(_a = this.map) === null || _a === void 0 ? void 0 : _a.on('move', this.onMove);
|
|
222
|
+
(_b = this.map) === null || _b === void 0 ? void 0 : _b.on('moveend', this.onMoveEnd);
|
|
223
|
+
(_c = this.map) === null || _c === void 0 ? void 0 : _c.on('zoomend', this.onZoomEnd);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Stop updating vehicles position.
|
|
227
|
+
*
|
|
228
|
+
* @public
|
|
229
|
+
*/
|
|
230
|
+
stop() {
|
|
231
|
+
var _a, _b, _c;
|
|
232
|
+
this.engine.stop();
|
|
233
|
+
(_a = this.map) === null || _a === void 0 ? void 0 : _a.off('move', this.onMove);
|
|
234
|
+
(_b = this.map) === null || _b === void 0 ? void 0 : _b.off('moveend', this.onMoveEnd);
|
|
235
|
+
(_c = this.map) === null || _c === void 0 ? void 0 : _c.off('zoomend', this.onZoomEnd);
|
|
236
|
+
}
|
|
237
|
+
get canvas() {
|
|
238
|
+
return this.engine.canvas;
|
|
239
|
+
}
|
|
240
|
+
get pixelRatio() {
|
|
241
|
+
return this.engine.pixelRatio || 1;
|
|
242
|
+
}
|
|
243
|
+
set pixelRatio(pixelRatio) {
|
|
244
|
+
this.engine.pixelRatio = pixelRatio || 1;
|
|
248
245
|
}
|
|
249
246
|
}
|
|
250
247
|
export default RealtimeLayer;
|