mobility-toolbox-js 3.0.1-beta.0 → 3.0.1-beta.2
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.js +1 -3
- package/api/RealtimeAPI.d.ts +47 -47
- package/api/RealtimeAPI.js +74 -74
- 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/typedefs.d.ts +0 -117
- package/common/typedefs.js +0 -31
- package/common/utils/RealtimeEngine.d.ts +214 -0
- package/common/utils/RealtimeEngine.js +554 -0
- package/common/utils/getLayersAsFlatArray.d.ts +0 -1
- package/common/utils/getLayersAsFlatArray.js +0 -1
- package/common/utils/getVehiclePosition.js +1 -4
- 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 +6960 -14605
- 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 +29 -18
- package/ol/controls/RoutingControl.js +44 -56
- package/ol/controls/StopFinderControl.d.ts +21 -2
- package/ol/controls/StopFinderControl.js +22 -3
- package/ol/index.d.ts +0 -1
- package/ol/index.js +0 -1
- package/ol/layers/Layer.d.ts +17 -92
- package/ol/layers/Layer.js +17 -3
- package/ol/layers/MaplibreLayer.d.ts +47 -114
- package/ol/layers/MaplibreLayer.js +102 -46
- package/ol/layers/MaplibreStyleLayer.d.ts +67 -147
- package/ol/layers/MaplibreStyleLayer.js +170 -123
- package/ol/layers/RealtimeLayer.d.ts +85 -218
- package/ol/layers/RealtimeLayer.js +170 -181
- package/ol/layers/VectorLayer.d.ts +1 -2
- package/ol/layers/VectorLayer.js +7 -6
- package/ol/renderers/MaplibreLayerRenderer.d.ts +9 -0
- package/ol/renderers/MaplibreLayerRenderer.js +35 -137
- package/ol/renderers/MaplibreStyleLayerRenderer.js +2 -2
- package/ol/renderers/RealtimeLayerRenderer.d.ts +1 -1
- 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 +13 -10
- package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
- package/ol/utils/defineDeprecatedProperties.js +180 -0
- package/package.json +40 -39
- package/setupTests.js +14 -0
- package/types/common.d.ts +4 -27
- package/types/realtime.d.ts +7 -2
- package/common/mixins/RealtimeLayerMixin.d.ts +0 -267
- package/common/mixins/RealtimeLayerMixin.js +0 -751
- package/ol/mixins/MobilityLayerMixin.d.ts +0 -96
- package/ol/mixins/MobilityLayerMixin.js +0 -6
- package/ol/mixins/PropertiesLayerMixin.d.ts +0 -136
- package/ol/mixins/PropertiesLayerMixin.js +0 -178
- package/ol/mixins/index.d.ts +0 -1
- package/ol/mixins/index.js +0 -2
|
@@ -4,11 +4,11 @@ import { getMapGlCopyrights } from '../../common/utils';
|
|
|
4
4
|
*/
|
|
5
5
|
const DEFAULT_SEPARATOR = ' | ';
|
|
6
6
|
/**
|
|
7
|
-
* Display layer's
|
|
7
|
+
* Display layer's attributions trying to remove duplicated ones.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
|
-
* import { Map } from '
|
|
11
|
-
* import { CopyrightControl } from 'mobility-toolbox-js/
|
|
10
|
+
* import { Map } from 'maplibre-gl';
|
|
11
|
+
* import { CopyrightControl } from 'mobility-toolbox-js/maplibre';
|
|
12
12
|
*
|
|
13
13
|
* const map = new Map({
|
|
14
14
|
* container: 'map',
|
|
@@ -19,13 +19,20 @@ const DEFAULT_SEPARATOR = ' | ';
|
|
|
19
19
|
* map.addControl(control);
|
|
20
20
|
*
|
|
21
21
|
*
|
|
22
|
-
* @see <a href="/example/mb-
|
|
22
|
+
* @see <a href="/example/mb-realtime>MapLibre Realtime layer example</a>
|
|
23
23
|
*
|
|
24
|
+
* @implements {maplibregl.IControl}
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
24
27
|
*/
|
|
25
28
|
class CopyrightControl {
|
|
26
29
|
constructor(options = {}) {
|
|
27
30
|
this.options = options;
|
|
28
31
|
}
|
|
32
|
+
// eslint-disable-next-line class-methods-use-this
|
|
33
|
+
getDefaultPosition() {
|
|
34
|
+
return 'bottom-right';
|
|
35
|
+
}
|
|
29
36
|
onAdd(map) {
|
|
30
37
|
this.map = map;
|
|
31
38
|
if (!this.container) {
|
|
@@ -51,10 +58,6 @@ class CopyrightControl {
|
|
|
51
58
|
this.map = undefined;
|
|
52
59
|
return this.container;
|
|
53
60
|
}
|
|
54
|
-
// eslint-disable-next-line class-methods-use-this
|
|
55
|
-
getDefaultPosition() {
|
|
56
|
-
return 'bottom-right';
|
|
57
|
-
}
|
|
58
61
|
render() {
|
|
59
62
|
var _a, _b;
|
|
60
63
|
if (this.map && this.container) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CustomLayerInterface, Evented } from 'maplibre-gl';
|
|
2
2
|
import type { AnyMapGlMap } from '../../types';
|
|
3
|
-
export
|
|
3
|
+
export interface LayerOptions {
|
|
4
4
|
id?: string;
|
|
5
|
-
}
|
|
5
|
+
}
|
|
6
|
+
export type CUSTOM = 'custom';
|
|
6
7
|
/**
|
|
7
8
|
* A class representing a layer to display on an Maplibre map.
|
|
8
9
|
*
|
|
@@ -19,10 +20,10 @@ declare class Layer extends Evented implements CustomLayerInterface {
|
|
|
19
20
|
id: string;
|
|
20
21
|
map: AnyMapGlMap | undefined;
|
|
21
22
|
options: LayerOptions;
|
|
22
|
-
type:
|
|
23
|
+
type: CUSTOM;
|
|
23
24
|
constructor(options?: LayerOptions);
|
|
24
|
-
onAdd(map: AnyMapGlMap, gl:
|
|
25
|
-
onRemove(map: AnyMapGlMap, gl:
|
|
26
|
-
render(gl:
|
|
25
|
+
onAdd(map: AnyMapGlMap, gl: WebGL2RenderingContext | WebGLRenderingContext): void;
|
|
26
|
+
onRemove(map: AnyMapGlMap, gl: WebGL2RenderingContext | WebGLRenderingContext): void;
|
|
27
|
+
render(gl: WebGL2RenderingContext | WebGLRenderingContext): void;
|
|
27
28
|
}
|
|
28
29
|
export default Layer;
|
package/maplibre/layers/Layer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { v4 as uuid } from 'uuid';
|
|
2
1
|
import { Evented } from 'maplibre-gl';
|
|
2
|
+
import { v4 as uuid } from 'uuid';
|
|
3
3
|
/**
|
|
4
4
|
* A class representing a layer to display on an Maplibre map.
|
|
5
5
|
*
|
|
@@ -19,7 +19,6 @@ class Layer extends Evented {
|
|
|
19
19
|
this.type = 'custom';
|
|
20
20
|
this.options = options;
|
|
21
21
|
this.id = options.id || uuid();
|
|
22
|
-
this.type = 'custom';
|
|
23
22
|
}
|
|
24
23
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
25
24
|
onAdd(map, gl) {
|
|
@@ -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
|
*
|
|
@@ -100,7 +26,7 @@ declare const RealtimeLayer_base: {
|
|
|
100
26
|
*
|
|
101
27
|
*
|
|
102
28
|
* @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
|
|
103
|
-
* @see <a href="/example/mb-realtime>
|
|
29
|
+
* @see <a href="/example/mb-realtime>MapLibre Realtime layer example</a>
|
|
104
30
|
*
|
|
105
31
|
* @implements {maplibregl.CustomLayerInterface}
|
|
106
32
|
* @extends {maplibregl.Evented}
|
|
@@ -113,7 +39,12 @@ declare const RealtimeLayer_base: {
|
|
|
113
39
|
s
|
|
114
40
|
* @public
|
|
115
41
|
*/
|
|
116
|
-
declare class RealtimeLayer extends
|
|
42
|
+
declare class RealtimeLayer extends Layer {
|
|
43
|
+
#private;
|
|
44
|
+
engine: RealtimeEngine;
|
|
45
|
+
layer: LayerSpecification;
|
|
46
|
+
source: CanvasSourceSpecification;
|
|
47
|
+
sourceId: string;
|
|
117
48
|
/**
|
|
118
49
|
* Constructor.
|
|
119
50
|
*
|
|
@@ -128,16 +59,52 @@ declare class RealtimeLayer extends RealtimeLayer_base {
|
|
|
128
59
|
* @param {RealtimeTenant} options.tenant Filter trains by its tenant. It filters trains on backend side.
|
|
129
60
|
* @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps Realtime API url.
|
|
130
61
|
*/
|
|
131
|
-
constructor(options?:
|
|
62
|
+
constructor(options?: RealtimeLayerOptions);
|
|
63
|
+
/**
|
|
64
|
+
* Return the current view state. Used by the RealtimeEngine.
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
getViewState(): {
|
|
68
|
+
center?: undefined;
|
|
69
|
+
extent?: undefined;
|
|
70
|
+
pixelRatio?: undefined;
|
|
71
|
+
resolution?: undefined;
|
|
72
|
+
rotation?: undefined;
|
|
73
|
+
size?: undefined;
|
|
74
|
+
visible?: undefined;
|
|
75
|
+
zoom?: undefined;
|
|
76
|
+
} | {
|
|
77
|
+
center: import("ol/coordinate").Coordinate;
|
|
78
|
+
extent: number[];
|
|
79
|
+
pixelRatio: number;
|
|
80
|
+
resolution: number;
|
|
81
|
+
rotation: number;
|
|
82
|
+
size: number[];
|
|
83
|
+
visible: boolean;
|
|
84
|
+
zoom: number;
|
|
85
|
+
};
|
|
132
86
|
/**
|
|
133
87
|
* Add sources, layers and listeners to the map.
|
|
134
88
|
*/
|
|
135
|
-
onAdd(map: AnyMapGlMap, gl:
|
|
89
|
+
onAdd(map: AnyMapGlMap, gl: WebGL2RenderingContext | WebGLRenderingContext): void;
|
|
90
|
+
onLoad(): void;
|
|
91
|
+
/**
|
|
92
|
+
* Callback on 'move' event.
|
|
93
|
+
*/
|
|
94
|
+
onMove(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Callback on 'moveend' event.
|
|
97
|
+
*/
|
|
98
|
+
onMoveEnd(): void;
|
|
99
|
+
/**
|
|
100
|
+
* Callback when the RealtimeEngine has rendered successfully.
|
|
101
|
+
*/
|
|
102
|
+
onRealtimeEngineRender(): void;
|
|
136
103
|
/**
|
|
137
104
|
* Remove source, layers and listeners from the map.
|
|
138
105
|
*/
|
|
139
|
-
onRemove(map: AnyMapGlMap, gl:
|
|
140
|
-
|
|
106
|
+
onRemove(map: AnyMapGlMap, gl: WebGL2RenderingContext | WebGLRenderingContext): void;
|
|
107
|
+
onZoomEnd(): void;
|
|
141
108
|
/**
|
|
142
109
|
* Start updating vehicles position.
|
|
143
110
|
*
|
|
@@ -150,32 +117,8 @@ declare class RealtimeLayer extends RealtimeLayer_base {
|
|
|
150
117
|
* @public
|
|
151
118
|
*/
|
|
152
119
|
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;
|
|
120
|
+
get canvas(): AnyCanvas | undefined;
|
|
121
|
+
get pixelRatio(): number | undefined;
|
|
122
|
+
set pixelRatio(pixelRatio: number | undefined);
|
|
180
123
|
}
|
|
181
124
|
export default RealtimeLayer;
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _RealtimeLayer_internalId;
|
|
5
13
|
import { point } from '@turf/helpers';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
14
|
+
import transformRotate from '@turf/transform-rotate';
|
|
15
|
+
import { getHeight, getWidth } from 'ol/extent';
|
|
16
|
+
import { fromLonLat } from 'ol/proj';
|
|
17
|
+
import RealtimeEngine from '../../common/utils/RealtimeEngine';
|
|
8
18
|
import { getSourceCoordinates } from '../utils';
|
|
9
|
-
import
|
|
19
|
+
import Layer from './Layer';
|
|
10
20
|
/**
|
|
11
21
|
* A Maplibre layer able to display data from the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
|
|
12
22
|
*
|
|
@@ -30,7 +40,7 @@ import toMercatorExtent from '../../common/utils/toMercatorExtent';
|
|
|
30
40
|
*
|
|
31
41
|
*
|
|
32
42
|
* @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
|
|
33
|
-
* @see <a href="/example/mb-realtime>
|
|
43
|
+
* @see <a href="/example/mb-realtime>MapLibre Realtime layer example</a>
|
|
34
44
|
*
|
|
35
45
|
* @implements {maplibregl.CustomLayerInterface}
|
|
36
46
|
* @extends {maplibregl.Evented}
|
|
@@ -43,7 +53,7 @@ import toMercatorExtent from '../../common/utils/toMercatorExtent';
|
|
|
43
53
|
s
|
|
44
54
|
* @public
|
|
45
55
|
*/
|
|
46
|
-
class RealtimeLayer extends
|
|
56
|
+
class RealtimeLayer extends Layer {
|
|
47
57
|
/**
|
|
48
58
|
* Constructor.
|
|
49
59
|
*
|
|
@@ -60,12 +70,17 @@ class RealtimeLayer extends RealtimeLayerMixin(Layer) {
|
|
|
60
70
|
*/
|
|
61
71
|
constructor(options = {}) {
|
|
62
72
|
var _a;
|
|
63
|
-
const
|
|
64
|
-
super(Object.assign({
|
|
65
|
-
|
|
73
|
+
const id = (options === null || options === void 0 ? void 0 : options.id) || 'realtime';
|
|
74
|
+
super(Object.assign(Object.assign({}, options), { id: 'realtime-custom-' + id }));
|
|
75
|
+
_RealtimeLayer_internalId.set(this, void 0);
|
|
76
|
+
__classPrivateFieldSet(this, _RealtimeLayer_internalId, id, "f");
|
|
77
|
+
this.engine = new RealtimeEngine(Object.assign({ getViewState: this.getViewState.bind(this), onRender: this.onRealtimeEngineRender.bind(this) }, options));
|
|
78
|
+
this.sourceId = __classPrivateFieldGet(this, _RealtimeLayer_internalId, "f");
|
|
66
79
|
this.source = {
|
|
67
|
-
|
|
68
|
-
|
|
80
|
+
// Set to true if the canvas source is animated. If the canvas is static, animate should be set to false to improve performance.
|
|
81
|
+
animate: true,
|
|
82
|
+
// @ts-expect-error bad type definition
|
|
83
|
+
attribution: (_a = options.attribution) === null || _a === void 0 ? void 0 : _a.join(', '),
|
|
69
84
|
canvas: this.canvas,
|
|
70
85
|
// Set a default coordinates, it will be overrides on next data update
|
|
71
86
|
coordinates: [
|
|
@@ -74,108 +89,47 @@ class RealtimeLayer extends RealtimeLayerMixin(Layer) {
|
|
|
74
89
|
[2, 2],
|
|
75
90
|
[0, 0],
|
|
76
91
|
],
|
|
77
|
-
// Set to true if the canvas source is animated. If the canvas is static, animate should be set to false to improve performance.
|
|
78
|
-
animate: true,
|
|
79
|
-
attribution: (_a = options.attribution) === null || _a === void 0 ? void 0 : _a.join(', '),
|
|
80
92
|
loaded: true,
|
|
93
|
+
type: 'canvas',
|
|
81
94
|
};
|
|
82
|
-
/** @private */
|
|
83
95
|
this.layer = {
|
|
84
|
-
id:
|
|
85
|
-
type: 'raster',
|
|
86
|
-
source: this.id,
|
|
96
|
+
id: __classPrivateFieldGet(this, _RealtimeLayer_internalId, "f"),
|
|
87
97
|
layout: {
|
|
88
98
|
visibility: 'visible',
|
|
89
99
|
},
|
|
90
100
|
paint: {
|
|
91
|
-
'raster-opacity': 1,
|
|
92
101
|
'raster-fade-duration': 0,
|
|
102
|
+
'raster-opacity': 1,
|
|
93
103
|
'raster-resampling': 'nearest', // important otherwise it looks blurry
|
|
94
104
|
},
|
|
105
|
+
source: this.sourceId,
|
|
106
|
+
type: 'raster',
|
|
95
107
|
};
|
|
96
|
-
/** @private */
|
|
97
108
|
this.onLoad = this.onLoad.bind(this);
|
|
98
|
-
/** @private */
|
|
99
109
|
this.onMove = this.onMove.bind(this);
|
|
100
|
-
/** @private */
|
|
101
110
|
this.onMoveEnd = this.onMoveEnd.bind(this);
|
|
102
|
-
/** @private */
|
|
103
111
|
this.onZoomEnd = this.onZoomEnd.bind(this);
|
|
104
112
|
}
|
|
105
113
|
/**
|
|
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.
|
|
114
|
+
* Return the current view state. Used by the RealtimeEngine.
|
|
163
115
|
* @private
|
|
164
116
|
*/
|
|
165
|
-
|
|
117
|
+
getViewState() {
|
|
166
118
|
if (!this.map) {
|
|
167
|
-
return;
|
|
119
|
+
return {};
|
|
168
120
|
}
|
|
169
121
|
if (!this.pixelRatio) {
|
|
170
122
|
this.pixelRatio = 1;
|
|
171
123
|
}
|
|
172
|
-
const {
|
|
124
|
+
const { height, width } = this.map.getCanvas();
|
|
173
125
|
const center = this.map.getCenter();
|
|
174
126
|
// We use turf here to have good transform.
|
|
127
|
+
// @ts-expect-error bad type definition
|
|
175
128
|
const leftBottom = this.map.unproject({
|
|
176
129
|
x: 0,
|
|
177
130
|
y: height / this.pixelRatio,
|
|
178
131
|
}); // southWest
|
|
132
|
+
// @ts-expect-error bad type definition
|
|
179
133
|
const rightTop = this.map.unproject({
|
|
180
134
|
x: width / this.pixelRatio,
|
|
181
135
|
y: 0,
|
|
@@ -191,60 +145,118 @@ class RealtimeLayer extends RealtimeLayerMixin(Layer) {
|
|
|
191
145
|
const yResolution = getHeight(bounds) / (height / this.pixelRatio);
|
|
192
146
|
const res = Math.max(xResolution, yResolution);
|
|
193
147
|
// 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],
|
|
148
|
+
return {
|
|
196
149
|
center: fromLonLat([center.lng, center.lat]),
|
|
197
150
|
extent: bounds,
|
|
151
|
+
pixelRatio: this.pixelRatio,
|
|
198
152
|
resolution: res,
|
|
199
|
-
zoom: this.map.getZoom() - 1,
|
|
200
153
|
rotation: -(this.map.getBearing() * Math.PI) / 180,
|
|
201
|
-
|
|
154
|
+
size: [width / this.pixelRatio, height / this.pixelRatio],
|
|
155
|
+
visible: true,
|
|
156
|
+
zoom: this.map.getZoom() - 1,
|
|
202
157
|
};
|
|
203
|
-
super.renderTrajectories(viewState, noInterpolate);
|
|
204
158
|
}
|
|
205
159
|
/**
|
|
206
|
-
*
|
|
160
|
+
* Add sources, layers and listeners to the map.
|
|
207
161
|
*/
|
|
208
|
-
|
|
209
|
-
|
|
162
|
+
onAdd(map, gl) {
|
|
163
|
+
super.onAdd(map, gl);
|
|
164
|
+
this.engine.attachToMap();
|
|
165
|
+
if (map.isStyleLoaded()) {
|
|
166
|
+
this.onLoad();
|
|
167
|
+
}
|
|
168
|
+
map.on('load', this.onLoad);
|
|
169
|
+
}
|
|
170
|
+
onLoad() {
|
|
171
|
+
var _a, _b, _c, _d;
|
|
172
|
+
if (!((_a = this.map) === null || _a === void 0 ? void 0 : _a.getSource(this.sourceId))) {
|
|
173
|
+
(_b = this.map) === null || _b === void 0 ? void 0 : _b.addSource(this.sourceId, this.source);
|
|
174
|
+
}
|
|
175
|
+
if (!((_c = this.map) === null || _c === void 0 ? void 0 : _c.getLayer(this.layer.id))) {
|
|
176
|
+
(_d = this.map) === null || _d === void 0 ? void 0 : _d.addLayer(this.layer, this.id);
|
|
177
|
+
}
|
|
178
|
+
this.start();
|
|
210
179
|
}
|
|
211
180
|
/**
|
|
212
|
-
*
|
|
181
|
+
* Callback on 'move' event.
|
|
213
182
|
*/
|
|
214
|
-
|
|
215
|
-
|
|
183
|
+
onMove() {
|
|
184
|
+
this.engine.renderTrajectories();
|
|
216
185
|
}
|
|
217
186
|
/**
|
|
218
|
-
*
|
|
187
|
+
* Callback on 'moveend' event.
|
|
219
188
|
*/
|
|
220
|
-
|
|
221
|
-
|
|
189
|
+
onMoveEnd() {
|
|
190
|
+
this.engine.renderTrajectories();
|
|
191
|
+
if (this.engine.isUpdateBboxOnMoveEnd) {
|
|
192
|
+
this.engine.setBbox();
|
|
193
|
+
}
|
|
222
194
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Callback when the RealtimeEngine has rendered successfully.
|
|
197
|
+
*/
|
|
198
|
+
onRealtimeEngineRender() {
|
|
199
|
+
var _a;
|
|
200
|
+
if ((_a = this.map) === null || _a === void 0 ? void 0 : _a.style) {
|
|
226
201
|
const extent = getSourceCoordinates(this.map, this.pixelRatio);
|
|
227
|
-
const source = this.map.getSource(this.
|
|
202
|
+
const source = this.map.getSource(this.sourceId);
|
|
228
203
|
if (source) {
|
|
204
|
+
// @ts-expect-error bad type definition
|
|
229
205
|
source.setCoordinates(extent);
|
|
230
206
|
}
|
|
231
207
|
}
|
|
232
|
-
return render;
|
|
233
208
|
}
|
|
234
209
|
/**
|
|
235
|
-
*
|
|
210
|
+
* Remove source, layers and listeners from the map.
|
|
236
211
|
*/
|
|
237
|
-
|
|
238
|
-
this.
|
|
212
|
+
onRemove(map, gl) {
|
|
213
|
+
this.engine.detachFromMap();
|
|
214
|
+
this.stop();
|
|
215
|
+
map.off('load', this.onLoad);
|
|
216
|
+
if (map.getLayer(this.layer.id)) {
|
|
217
|
+
map.removeLayer(this.layer.id);
|
|
218
|
+
}
|
|
219
|
+
if (map.getSource(this.sourceId)) {
|
|
220
|
+
map.removeSource(this.sourceId);
|
|
221
|
+
}
|
|
222
|
+
super.onRemove(map, gl);
|
|
223
|
+
}
|
|
224
|
+
onZoomEnd() {
|
|
225
|
+
this.engine.onZoomEnd();
|
|
239
226
|
}
|
|
240
227
|
/**
|
|
241
|
-
*
|
|
228
|
+
* Start updating vehicles position.
|
|
229
|
+
*
|
|
230
|
+
* @public
|
|
242
231
|
*/
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
232
|
+
start() {
|
|
233
|
+
var _a, _b, _c;
|
|
234
|
+
this.engine.start();
|
|
235
|
+
(_a = this.map) === null || _a === void 0 ? void 0 : _a.on('move', this.onMove);
|
|
236
|
+
(_b = this.map) === null || _b === void 0 ? void 0 : _b.on('moveend', this.onMoveEnd);
|
|
237
|
+
(_c = this.map) === null || _c === void 0 ? void 0 : _c.on('zoomend', this.onZoomEnd);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Stop updating vehicles position.
|
|
241
|
+
*
|
|
242
|
+
* @public
|
|
243
|
+
*/
|
|
244
|
+
stop() {
|
|
245
|
+
var _a, _b, _c;
|
|
246
|
+
this.engine.stop();
|
|
247
|
+
(_a = this.map) === null || _a === void 0 ? void 0 : _a.off('move', this.onMove);
|
|
248
|
+
(_b = this.map) === null || _b === void 0 ? void 0 : _b.off('moveend', this.onMoveEnd);
|
|
249
|
+
(_c = this.map) === null || _c === void 0 ? void 0 : _c.off('zoomend', this.onZoomEnd);
|
|
250
|
+
}
|
|
251
|
+
get canvas() {
|
|
252
|
+
return this.engine.canvas;
|
|
253
|
+
}
|
|
254
|
+
get pixelRatio() {
|
|
255
|
+
return this.engine.pixelRatio || 1;
|
|
256
|
+
}
|
|
257
|
+
set pixelRatio(pixelRatio) {
|
|
258
|
+
this.engine.pixelRatio = pixelRatio || 1;
|
|
248
259
|
}
|
|
249
260
|
}
|
|
261
|
+
_RealtimeLayer_internalId = new WeakMap();
|
|
250
262
|
export default RealtimeLayer;
|
|
@@ -2,6 +2,7 @@ import { AnyMapGlMap } from '../../types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Get the canvas source coordinates of the current map's extent.
|
|
4
4
|
* @param {maplibregl.Map} map A map object.
|
|
5
|
+
* @param {number} [pixelRatio=1] The pixel ratio.
|
|
5
6
|
*/
|
|
6
7
|
export declare const getSourceCoordinates: (map: AnyMapGlMap, pixelRatio?: number) => number[][];
|
|
7
8
|
export default getSourceCoordinates;
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Get the canvas source coordinates of the current map's extent.
|
|
3
3
|
* @param {maplibregl.Map} map A map object.
|
|
4
|
+
* @param {number} [pixelRatio=1] The pixel ratio.
|
|
4
5
|
*/
|
|
5
6
|
export const getSourceCoordinates = (map, pixelRatio = 1) => {
|
|
6
7
|
// Requesting getBounds is not enough when we rotate the map, so we request manually each corner.
|
|
7
8
|
const { height, width } = map.getCanvas();
|
|
8
|
-
// @ts-expect-error
|
|
9
|
+
// @ts-expect-error - to fix
|
|
9
10
|
const leftTop = map.unproject({ x: 0, y: 0 });
|
|
10
|
-
// @ts-expect-error
|
|
11
|
+
// @ts-expect-error - to fix
|
|
11
12
|
const leftBottom = map.unproject({ x: 0, y: height / pixelRatio }); // southWest
|
|
12
|
-
// @ts-expect-error
|
|
13
|
+
// @ts-expect-error - to fix
|
|
13
14
|
const rightBottom = map.unproject({
|
|
14
15
|
x: width / pixelRatio,
|
|
15
16
|
y: height / pixelRatio,
|
|
16
17
|
});
|
|
17
|
-
// @ts-expect-error
|
|
18
|
+
// @ts-expect-error - to fix
|
|
18
19
|
const rightTop = map.unproject({ x: width / pixelRatio, y: 0 }); // north east
|
|
19
20
|
return [
|
|
20
21
|
[leftTop.lng, leftTop.lat],
|