mobility-toolbox-js 3.0.0-beta.33 → 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/RealtimeAPI.d.ts +2 -2
- package/api/RealtimeAPI.js +3 -3
- package/common/controls/StopFinderControlCommon.d.ts +1 -1
- package/common/controls/StopFinderControlCommon.js +1 -1
- package/common/utils/RealtimeEngine.d.ts +0 -10
- package/common/utils/RealtimeEngine.js +0 -10
- 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 +4 -2
- package/maplibre/layers/RealtimeLayer.js +26 -11
- package/maplibre/utils/getSourceCoordinates.d.ts +1 -0
- package/maplibre/utils/getSourceCoordinates.js +5 -4
- package/mbt.js +239 -200
- package/mbt.js.map +3 -3
- package/mbt.min.js +13 -13
- 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 +25 -15
- package/ol/controls/RoutingControl.js +31 -19
- package/ol/controls/StopFinderControl.d.ts +22 -0
- package/ol/controls/StopFinderControl.js +22 -0
- package/ol/layers/MaplibreLayer.d.ts +6 -1
- package/ol/layers/MaplibreLayer.js +6 -1
- package/ol/layers/MaplibreStyleLayer.d.ts +5 -9
- package/ol/layers/MaplibreStyleLayer.js +5 -3
- package/ol/layers/RealtimeLayer.d.ts +4 -1
- package/ol/layers/RealtimeLayer.js +4 -1
- package/package.json +21 -20
package/api/RealtimeAPI.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export declare const RealtimeModes: {
|
|
|
55
55
|
* });
|
|
56
56
|
*
|
|
57
57
|
* // Close the websocket connection
|
|
58
|
-
*
|
|
58
|
+
* api.close();
|
|
59
59
|
*
|
|
60
60
|
* @public
|
|
61
61
|
*/
|
|
@@ -350,7 +350,7 @@ declare class RealtimeAPI {
|
|
|
350
350
|
* @param {function(data: { content: RealtimeDeparture[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
351
351
|
* @public
|
|
352
352
|
*/
|
|
353
|
-
|
|
353
|
+
unsubscribeTimetable(stationId: RealtimeStationId, onMessage?: WebSocketAPIMessageCallback<RealtimeDeparture>): void;
|
|
354
354
|
/**
|
|
355
355
|
* Unsubscribe to trajectory channels.
|
|
356
356
|
* @param {function(data: { content: RealtimeTrajectory })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
package/api/RealtimeAPI.js
CHANGED
|
@@ -39,7 +39,7 @@ export const RealtimeModes = {
|
|
|
39
39
|
* });
|
|
40
40
|
*
|
|
41
41
|
* // Close the websocket connection
|
|
42
|
-
*
|
|
42
|
+
* api.close();
|
|
43
43
|
*
|
|
44
44
|
* @public
|
|
45
45
|
*/
|
|
@@ -422,7 +422,7 @@ class RealtimeAPI {
|
|
|
422
422
|
* @deprecated Use RealtimeAPI.unsubscribeTimetabe instead.
|
|
423
423
|
*/
|
|
424
424
|
unsubscribeDepartures(stationId, onMessage) {
|
|
425
|
-
this.
|
|
425
|
+
this.unsubscribeTimetable(stationId, onMessage);
|
|
426
426
|
}
|
|
427
427
|
/**
|
|
428
428
|
* Unsubscribe disruptions.
|
|
@@ -490,7 +490,7 @@ class RealtimeAPI {
|
|
|
490
490
|
* @param {function(data: { content: RealtimeDeparture[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
491
491
|
* @public
|
|
492
492
|
*/
|
|
493
|
-
|
|
493
|
+
unsubscribeTimetable(stationId, onMessage) {
|
|
494
494
|
this.unsubscribe(`timetable_${stationId}`, '', onMessage);
|
|
495
495
|
}
|
|
496
496
|
/**
|
|
@@ -30,7 +30,7 @@ declare class StopFinderControlCommon {
|
|
|
30
30
|
* @param {Object} options Options
|
|
31
31
|
* @param {HTMLElement} options.element HTML element where to attach input and suggestions.
|
|
32
32
|
* @param {string} options.apiKey Access key for [geOps services](https://developer.geops.io/). See StopsAPI.
|
|
33
|
-
* @param {string} [options.url='https://api.geops.io/
|
|
33
|
+
* @param {string} [options.url='https://api.geops.io/stops/v1/'] Stops service url. See StopsAPI.
|
|
34
34
|
* @param {string} [options.placeholder='Search for a stop...'] Input field placeholder.
|
|
35
35
|
* @param {StopsSearchParams} [options.apiParams={ limit: 20 }] Request parameters. See [Stops service documentation](https://developer.geops.io/apis/5dcbd702a256d90001cf1361/).
|
|
36
36
|
*/
|
|
@@ -13,7 +13,7 @@ class StopFinderControlCommon {
|
|
|
13
13
|
* @param {Object} options Options
|
|
14
14
|
* @param {HTMLElement} options.element HTML element where to attach input and suggestions.
|
|
15
15
|
* @param {string} options.apiKey Access key for [geOps services](https://developer.geops.io/). See StopsAPI.
|
|
16
|
-
* @param {string} [options.url='https://api.geops.io/
|
|
16
|
+
* @param {string} [options.url='https://api.geops.io/stops/v1/'] Stops service url. See StopsAPI.
|
|
17
17
|
* @param {string} [options.placeholder='Search for a stop...'] Input field placeholder.
|
|
18
18
|
* @param {StopsSearchParams} [options.apiParams={ limit: 20 }] Request parameters. See [Stops service documentation](https://developer.geops.io/apis/5dcbd702a256d90001cf1361/).
|
|
19
19
|
*/
|
|
@@ -108,7 +108,6 @@ declare class RealtimeEngine {
|
|
|
108
108
|
* Get the duration before the next update depending on zoom level.
|
|
109
109
|
*
|
|
110
110
|
* @private
|
|
111
|
-
* @param {number} zoom
|
|
112
111
|
*/
|
|
113
112
|
getRefreshTimeInMs(): number;
|
|
114
113
|
/**
|
|
@@ -146,7 +145,6 @@ declare class RealtimeEngine {
|
|
|
146
145
|
/**
|
|
147
146
|
* On zoomend we adjust the time interval of the update of vehicles positions.
|
|
148
147
|
*
|
|
149
|
-
* @param evt Event that triggered the function.
|
|
150
148
|
* @private
|
|
151
149
|
*/
|
|
152
150
|
onZoomEnd(): void;
|
|
@@ -161,8 +159,6 @@ declare class RealtimeEngine {
|
|
|
161
159
|
* - that aren't in the MOT list.
|
|
162
160
|
*
|
|
163
161
|
* @param {RealtimeTrajectory} trajectory
|
|
164
|
-
* @param {Array<number>} extent
|
|
165
|
-
* @param {number} zoom
|
|
166
162
|
* @return {boolean} if the trajectory must be displayed or not.
|
|
167
163
|
* @private
|
|
168
164
|
*/
|
|
@@ -172,12 +168,6 @@ declare class RealtimeEngine {
|
|
|
172
168
|
* Render the trajectories requesting an animation frame and cancelling the previous one.
|
|
173
169
|
* This function must be overrided by children to provide the correct parameters.
|
|
174
170
|
*
|
|
175
|
-
* @param {object} viewState The view state of the map.
|
|
176
|
-
* @param {number[2]} viewState.center Center coordinate of the map in mercator coordinate.
|
|
177
|
-
* @param {number[4]} viewState.extent Extent of the map in mercator coordinates.
|
|
178
|
-
* @param {number[2]} viewState.size Size ([width, height]) of the canvas to render.
|
|
179
|
-
* @param {number} [viewState.rotation = 0] Rotation of the map to render.
|
|
180
|
-
* @param {number} viewState.resolution Resolution of the map to render.
|
|
181
171
|
* @param {boolean} noInterpolate If true trajectories are not interpolated but
|
|
182
172
|
* drawn at the last known coordinate. Use this for performance optimization
|
|
183
173
|
* during map navigation.
|
|
@@ -143,7 +143,6 @@ class RealtimeEngine {
|
|
|
143
143
|
* Get the duration before the next update depending on zoom level.
|
|
144
144
|
*
|
|
145
145
|
* @private
|
|
146
|
-
* @param {number} zoom
|
|
147
146
|
*/
|
|
148
147
|
getRefreshTimeInMs() {
|
|
149
148
|
var _a;
|
|
@@ -279,7 +278,6 @@ class RealtimeEngine {
|
|
|
279
278
|
/**
|
|
280
279
|
* On zoomend we adjust the time interval of the update of vehicles positions.
|
|
281
280
|
*
|
|
282
|
-
* @param evt Event that triggered the function.
|
|
283
281
|
* @private
|
|
284
282
|
*/
|
|
285
283
|
onZoomEnd() {
|
|
@@ -307,8 +305,6 @@ class RealtimeEngine {
|
|
|
307
305
|
* - that aren't in the MOT list.
|
|
308
306
|
*
|
|
309
307
|
* @param {RealtimeTrajectory} trajectory
|
|
310
|
-
* @param {Array<number>} extent
|
|
311
|
-
* @param {number} zoom
|
|
312
308
|
* @return {boolean} if the trajectory must be displayed or not.
|
|
313
309
|
* @private
|
|
314
310
|
*/
|
|
@@ -340,12 +336,6 @@ class RealtimeEngine {
|
|
|
340
336
|
* Render the trajectories requesting an animation frame and cancelling the previous one.
|
|
341
337
|
* This function must be overrided by children to provide the correct parameters.
|
|
342
338
|
*
|
|
343
|
-
* @param {object} viewState The view state of the map.
|
|
344
|
-
* @param {number[2]} viewState.center Center coordinate of the map in mercator coordinate.
|
|
345
|
-
* @param {number[4]} viewState.extent Extent of the map in mercator coordinates.
|
|
346
|
-
* @param {number[2]} viewState.size Size ([width, height]) of the canvas to render.
|
|
347
|
-
* @param {number} [viewState.rotation = 0] Rotation of the map to render.
|
|
348
|
-
* @param {number} viewState.resolution Resolution of the map to render.
|
|
349
339
|
* @param {boolean} noInterpolate If true trajectories are not interpolated but
|
|
350
340
|
* drawn at the last known coordinate. Use this for performance optimization
|
|
351
341
|
* during map navigation.
|
|
@@ -5,6 +5,7 @@ import { AnyCanvas, RealtimeRenderState, RealtimeStyleFunction, RealtimeStyleOpt
|
|
|
5
5
|
* @param {ViewState} trajectories An array of trajectories.
|
|
6
6
|
* @param {Function} style A function that returns a canvas representing a vehicle of a specific trajectory.
|
|
7
7
|
* @param {ViewState} viewState The view state of the map.
|
|
8
|
+
* @param {Object} options The options.
|
|
8
9
|
* @param {boolean} options.hoverVehicleId The id of the vehicle to highlight.
|
|
9
10
|
* @param {boolean} options.selectedVehicleId The id of the vehicle to select.
|
|
10
11
|
* @param {boolean} options.noInterpolate If true trajectories are not interpolated but
|
|
@@ -6,6 +6,7 @@ import getVehiclePosition from './getVehiclePosition';
|
|
|
6
6
|
* @param {ViewState} trajectories An array of trajectories.
|
|
7
7
|
* @param {Function} style A function that returns a canvas representing a vehicle of a specific trajectory.
|
|
8
8
|
* @param {ViewState} viewState The view state of the map.
|
|
9
|
+
* @param {Object} options The options.
|
|
9
10
|
* @param {boolean} options.hoverVehicleId The id of the vehicle to highlight.
|
|
10
11
|
* @param {boolean} options.selectedVehicleId The id of the vehicle to select.
|
|
11
12
|
* @param {boolean} options.noInterpolate If true trajectories are not interpolated but
|
|
@@ -8,6 +8,7 @@ import type { RealtimeDepartureExtended } from '../../types';
|
|
|
8
8
|
*
|
|
9
9
|
* @param {Object} depObject The object containing departures by id.
|
|
10
10
|
* @param {boolean} [sortByMinArrivalTime=false] If true sort departures by arrival time.
|
|
11
|
+
* @param {number} [maxDepartureAge=30] The maximum departure age in minutes.
|
|
11
12
|
* @return {RealtimeDeparture[]} Return departures array.
|
|
12
13
|
* @private
|
|
13
14
|
*/
|
|
@@ -7,6 +7,7 @@ import compareDepartures from './compareDepartures';
|
|
|
7
7
|
*
|
|
8
8
|
* @param {Object} depObject The object containing departures by id.
|
|
9
9
|
* @param {boolean} [sortByMinArrivalTime=false] If true sort departures by arrival time.
|
|
10
|
+
* @param {number} [maxDepartureAge=30] The maximum departure age in minutes.
|
|
10
11
|
* @return {RealtimeDeparture[]} Return departures array.
|
|
11
12
|
* @private
|
|
12
13
|
*/
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ControlPosition, IControl } from 'maplibre-gl';
|
|
2
2
|
/**
|
|
3
|
-
* Display layer's
|
|
3
|
+
* Display layer's attributions trying to remove duplicated ones.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
|
-
* import { Map } from '
|
|
7
|
-
* import { CopyrightControl } from 'mobility-toolbox-js/
|
|
6
|
+
* import { Map } from 'maplibre-gl';
|
|
7
|
+
* import { CopyrightControl } from 'mobility-toolbox-js/maplibre';
|
|
8
8
|
*
|
|
9
9
|
* const map = new Map({
|
|
10
10
|
* container: 'map',
|
|
@@ -15,21 +15,24 @@ import { ControlPosition, IControl } from 'maplibre-gl';
|
|
|
15
15
|
* map.addControl(control);
|
|
16
16
|
*
|
|
17
17
|
*
|
|
18
|
-
* @see <a href="/example/mb-
|
|
18
|
+
* @see <a href="/example/mb-realtime>MapLibre Realtime layer example</a>
|
|
19
19
|
*
|
|
20
|
+
* @implements {maplibregl.IControl}
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
20
23
|
*/
|
|
21
24
|
declare class CopyrightControl implements IControl {
|
|
22
|
-
map?: maplibregl.Map;
|
|
23
25
|
container?: HTMLElement;
|
|
24
26
|
content?: string;
|
|
27
|
+
map?: maplibregl.Map;
|
|
25
28
|
options?: {
|
|
26
29
|
customAttribution?: string | string[];
|
|
27
30
|
separator?: string;
|
|
28
31
|
};
|
|
29
32
|
constructor(options?: {});
|
|
33
|
+
getDefaultPosition(): ControlPosition;
|
|
30
34
|
onAdd(map: maplibregl.Map): HTMLElement;
|
|
31
35
|
onRemove(): HTMLElement | undefined;
|
|
32
|
-
getDefaultPosition(): ControlPosition;
|
|
33
36
|
render(): void;
|
|
34
37
|
}
|
|
35
38
|
export default CopyrightControl;
|
|
@@ -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) {
|
|
@@ -26,7 +26,7 @@ export type RealtimeLayerOptions = LayerOptions & RealtimeEngineOptions;
|
|
|
26
26
|
*
|
|
27
27
|
*
|
|
28
28
|
* @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
|
|
29
|
-
* @see <a href="/example/mb-realtime>
|
|
29
|
+
* @see <a href="/example/mb-realtime>MapLibre Realtime layer example</a>
|
|
30
30
|
*
|
|
31
31
|
* @implements {maplibregl.CustomLayerInterface}
|
|
32
32
|
* @extends {maplibregl.Evented}
|
|
@@ -40,9 +40,11 @@ export type RealtimeLayerOptions = LayerOptions & RealtimeEngineOptions;
|
|
|
40
40
|
* @public
|
|
41
41
|
*/
|
|
42
42
|
declare class RealtimeLayer extends Layer {
|
|
43
|
+
#private;
|
|
43
44
|
engine: RealtimeEngine;
|
|
44
45
|
layer: LayerSpecification;
|
|
45
46
|
source: CanvasSourceSpecification;
|
|
47
|
+
sourceId: string;
|
|
46
48
|
/**
|
|
47
49
|
* Constructor.
|
|
48
50
|
*
|
|
@@ -57,7 +59,7 @@ declare class RealtimeLayer extends Layer {
|
|
|
57
59
|
* @param {RealtimeTenant} options.tenant Filter trains by its tenant. It filters trains on backend side.
|
|
58
60
|
* @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps Realtime API url.
|
|
59
61
|
*/
|
|
60
|
-
constructor(options?:
|
|
62
|
+
constructor(options?: RealtimeLayerOptions);
|
|
61
63
|
/**
|
|
62
64
|
* Return the current view state. Used by the RealtimeEngine.
|
|
63
65
|
* @private
|
|
@@ -1,3 +1,15 @@
|
|
|
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;
|
|
1
13
|
import { point } from '@turf/helpers';
|
|
2
14
|
import transformRotate from '@turf/transform-rotate';
|
|
3
15
|
import { getHeight, getWidth } from 'ol/extent';
|
|
@@ -28,7 +40,7 @@ import Layer from './Layer';
|
|
|
28
40
|
*
|
|
29
41
|
*
|
|
30
42
|
* @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
|
|
31
|
-
* @see <a href="/example/mb-realtime>
|
|
43
|
+
* @see <a href="/example/mb-realtime>MapLibre Realtime layer example</a>
|
|
32
44
|
*
|
|
33
45
|
* @implements {maplibregl.CustomLayerInterface}
|
|
34
46
|
* @extends {maplibregl.Evented}
|
|
@@ -58,8 +70,12 @@ class RealtimeLayer extends Layer {
|
|
|
58
70
|
*/
|
|
59
71
|
constructor(options = {}) {
|
|
60
72
|
var _a;
|
|
61
|
-
|
|
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");
|
|
62
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");
|
|
63
79
|
this.source = {
|
|
64
80
|
// Set to true if the canvas source is animated. If the canvas is static, animate should be set to false to improve performance.
|
|
65
81
|
animate: true,
|
|
@@ -73,12 +89,11 @@ class RealtimeLayer extends Layer {
|
|
|
73
89
|
[2, 2],
|
|
74
90
|
[0, 0],
|
|
75
91
|
],
|
|
76
|
-
id: this.id,
|
|
77
92
|
loaded: true,
|
|
78
93
|
type: 'canvas',
|
|
79
94
|
};
|
|
80
95
|
this.layer = {
|
|
81
|
-
id:
|
|
96
|
+
id: __classPrivateFieldGet(this, _RealtimeLayer_internalId, "f"),
|
|
82
97
|
layout: {
|
|
83
98
|
visibility: 'visible',
|
|
84
99
|
},
|
|
@@ -87,7 +102,7 @@ class RealtimeLayer extends Layer {
|
|
|
87
102
|
'raster-opacity': 1,
|
|
88
103
|
'raster-resampling': 'nearest', // important otherwise it looks blurry
|
|
89
104
|
},
|
|
90
|
-
source: this.
|
|
105
|
+
source: this.sourceId,
|
|
91
106
|
type: 'raster',
|
|
92
107
|
};
|
|
93
108
|
this.onLoad = this.onLoad.bind(this);
|
|
@@ -100,7 +115,6 @@ class RealtimeLayer extends Layer {
|
|
|
100
115
|
* @private
|
|
101
116
|
*/
|
|
102
117
|
getViewState() {
|
|
103
|
-
console.log(this);
|
|
104
118
|
if (!this.map) {
|
|
105
119
|
return {};
|
|
106
120
|
}
|
|
@@ -155,8 +169,8 @@ class RealtimeLayer extends Layer {
|
|
|
155
169
|
}
|
|
156
170
|
onLoad() {
|
|
157
171
|
var _a, _b, _c, _d;
|
|
158
|
-
if (!((_a = this.map) === null || _a === void 0 ? void 0 : _a.getSource(this.
|
|
159
|
-
(_b = this.map) === null || _b === void 0 ? void 0 : _b.addSource(this.
|
|
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);
|
|
160
174
|
}
|
|
161
175
|
if (!((_c = this.map) === null || _c === void 0 ? void 0 : _c.getLayer(this.layer.id))) {
|
|
162
176
|
(_d = this.map) === null || _d === void 0 ? void 0 : _d.addLayer(this.layer, this.id);
|
|
@@ -185,7 +199,7 @@ class RealtimeLayer extends Layer {
|
|
|
185
199
|
var _a;
|
|
186
200
|
if ((_a = this.map) === null || _a === void 0 ? void 0 : _a.style) {
|
|
187
201
|
const extent = getSourceCoordinates(this.map, this.pixelRatio);
|
|
188
|
-
const source = this.map.getSource(this.
|
|
202
|
+
const source = this.map.getSource(this.sourceId);
|
|
189
203
|
if (source) {
|
|
190
204
|
// @ts-expect-error bad type definition
|
|
191
205
|
source.setCoordinates(extent);
|
|
@@ -202,8 +216,8 @@ class RealtimeLayer extends Layer {
|
|
|
202
216
|
if (map.getLayer(this.layer.id)) {
|
|
203
217
|
map.removeLayer(this.layer.id);
|
|
204
218
|
}
|
|
205
|
-
if (map.getSource(this.
|
|
206
|
-
map.removeSource(this.
|
|
219
|
+
if (map.getSource(this.sourceId)) {
|
|
220
|
+
map.removeSource(this.sourceId);
|
|
207
221
|
}
|
|
208
222
|
super.onRemove(map, gl);
|
|
209
223
|
}
|
|
@@ -244,4 +258,5 @@ class RealtimeLayer extends Layer {
|
|
|
244
258
|
this.engine.pixelRatio = pixelRatio || 1;
|
|
245
259
|
}
|
|
246
260
|
}
|
|
261
|
+
_RealtimeLayer_internalId = new WeakMap();
|
|
247
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],
|