mobility-toolbox-js 3.0.0-beta.10 → 3.0.0-beta.12
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 +30 -24
- package/api/RealtimeAPI.js +25 -18
- package/api/RoutingAPI.d.ts +17 -7
- package/api/RoutingAPI.js +17 -7
- package/api/StopsAPI.d.ts +4 -4
- package/api/StopsAPI.js +4 -4
- package/api/WebSocketAPI.d.ts +2 -2
- package/api/WebSocketAPI.js +2 -2
- package/api/typedefs.d.ts +0 -102
- package/api/typedefs.js +27 -42
- package/common/controls/StopFinderControlCommon.d.ts +1 -1
- package/common/controls/StopFinderControlCommon.js +1 -1
- package/common/mixins/RealtimeLayerMixin.d.ts +10 -11
- package/common/mixins/RealtimeLayerMixin.js +17 -9
- package/common/typedefs.d.ts +7 -0
- package/common/typedefs.js +6 -0
- package/common/utils/compareDepartures.d.ts +2 -2
- package/common/utils/compareDepartures.js +2 -2
- package/common/utils/debounceWebsocketMessages.d.ts +1 -1
- package/common/utils/getRealtimeModeSuffix.d.ts +1 -0
- package/common/utils/getRealtimeModeSuffix.js +1 -0
- package/common/utils/getVehiclePosition.d.ts +3 -2
- package/common/utils/getVehiclePosition.js +9 -3
- package/common/utils/renderTrajectories.d.ts +1 -1
- package/common/utils/renderTrajectories.js +1 -1
- package/common/utils/sortAndFilterDepartures.d.ts +1 -1
- package/common/utils/sortAndFilterDepartures.js +1 -1
- package/common/utils/sortByDelay.d.ts +2 -2
- package/common/utils/sortByDelay.js +5 -1
- package/maplibre/layers/Layer.d.ts +1 -1
- package/maplibre/layers/Layer.js +1 -1
- package/maplibre/layers/RealtimeLayer.d.ts +43 -14
- package/maplibre/layers/RealtimeLayer.js +30 -6
- package/mbt.js +5500 -6796
- package/mbt.js.map +4 -4
- package/mbt.min.js +67 -67
- package/mbt.min.js.map +4 -4
- package/ol/controls/RoutingControl.d.ts +1 -1
- package/ol/controls/RoutingControl.js +1 -1
- package/ol/controls/StopFinderControl.d.ts +1 -1
- package/ol/controls/StopFinderControl.js +1 -1
- package/ol/layers/{MapGlLayer.d.ts → Layer.d.ts} +23 -66
- package/ol/layers/Layer.js +17 -0
- package/ol/layers/MaplibreLayer.d.ts +133 -13
- package/ol/layers/MaplibreLayer.js +136 -13
- package/ol/layers/MaplibreStyleLayer.d.ts +8 -2
- package/ol/layers/MaplibreStyleLayer.js +37 -22
- package/ol/layers/RealtimeLayer.d.ts +17 -14
- package/ol/layers/RealtimeLayer.js +2 -2
- package/ol/layers/index.d.ts +1 -0
- package/ol/layers/index.js +1 -0
- package/ol/renderers/RealtimeLayerRenderer.js +4 -1
- package/package.json +14 -15
- package/ol/layers/MapGlLayer.js +0 -144
|
@@ -268,6 +268,34 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
268
268
|
this.disabled = !styles.length;
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Set the feature state of the features.
|
|
273
|
+
* @param {Array<ol/Feature~Feature>} features
|
|
274
|
+
* @param {{[key:string]:boolean}} state The feature state
|
|
275
|
+
* @public
|
|
276
|
+
*/
|
|
277
|
+
setFeatureState(features, state) {
|
|
278
|
+
var _a;
|
|
279
|
+
if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !features.length) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const { maplibreMap } = this.maplibreLayer;
|
|
283
|
+
features.forEach((feature) => {
|
|
284
|
+
const { source, sourceLayer } = feature.get(VECTOR_TILE_FEATURE_PROPERTY) || {};
|
|
285
|
+
if ((!source && !sourceLayer) || !feature.getId()) {
|
|
286
|
+
if (!feature.getId()) {
|
|
287
|
+
// eslint-disable-next-line no-console
|
|
288
|
+
console.warn("No feature's id found. To use the feature state functionnality, tiles must be generated with --generate-ids. See https://github.com/Maplibre/tippecanoe#adding-calculated-attributes.", feature.getId(), feature.getProperties());
|
|
289
|
+
}
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
maplibreMap.setFeatureState({
|
|
293
|
+
id: feature.getId(),
|
|
294
|
+
source,
|
|
295
|
+
sourceLayer,
|
|
296
|
+
}, state);
|
|
297
|
+
});
|
|
298
|
+
}
|
|
271
299
|
/**
|
|
272
300
|
* Request feature information for a given coordinate.
|
|
273
301
|
* @param {ol/coordinate~Coordinate} coordinate Coordinate to request the information at.
|
|
@@ -275,6 +303,8 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
275
303
|
*/
|
|
276
304
|
getFeatureInfoAtCoordinate(coordinate) {
|
|
277
305
|
var _a;
|
|
306
|
+
// eslint-disable-next-line no-console
|
|
307
|
+
console.warn(`Deprecated. getFeatureInfoAtCoordinate([layer], coordinate) from ol package instead.`);
|
|
278
308
|
if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap)) {
|
|
279
309
|
return Promise.resolve({ coordinate, features: [], layer: this });
|
|
280
310
|
}
|
|
@@ -342,26 +372,9 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
342
372
|
* @private
|
|
343
373
|
*/
|
|
344
374
|
setHoverState(features, state) {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
const { maplibreMap } = this.maplibreLayer;
|
|
350
|
-
features.forEach((feature) => {
|
|
351
|
-
const { source, sourceLayer } = feature.get(VECTOR_TILE_FEATURE_PROPERTY) || {};
|
|
352
|
-
if ((!source && !sourceLayer) || !feature.getId()) {
|
|
353
|
-
if (!feature.getId()) {
|
|
354
|
-
// eslint-disable-next-line no-console
|
|
355
|
-
console.warn("No feature's id found. To use the feature state functionnality, tiles must be generated with --generate-ids. See https://github.com/Maplibre/tippecanoe#adding-calculated-attributes.", feature.getId(), feature.getProperties());
|
|
356
|
-
}
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
maplibreMap.setFeatureState({
|
|
360
|
-
id: feature.getId(),
|
|
361
|
-
source,
|
|
362
|
-
sourceLayer,
|
|
363
|
-
}, { hover: state });
|
|
364
|
-
});
|
|
375
|
+
// eslint-disable-next-line no-console
|
|
376
|
+
console.warn(`Deprecated. Use layer.setFeatureState(features, {hover: ${state}}) instead.`);
|
|
377
|
+
this.setFeatureState(features, { hover: state });
|
|
365
378
|
}
|
|
366
379
|
/**
|
|
367
380
|
* Select a list of features.
|
|
@@ -369,6 +382,8 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
369
382
|
* @private
|
|
370
383
|
*/
|
|
371
384
|
select(features = []) {
|
|
385
|
+
// eslint-disable-next-line no-console
|
|
386
|
+
console.warn(`Deprecated. Use layer.setFeatureState(features, {selected: true}) instead.`);
|
|
372
387
|
this.setHoverState(this.selectedFeatures || [], false);
|
|
373
388
|
this.selectedFeatures = features;
|
|
374
389
|
this.setHoverState(this.selectedFeatures || [], true);
|
|
@@ -380,6 +395,8 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
380
395
|
*/
|
|
381
396
|
highlight(features = []) {
|
|
382
397
|
var _a;
|
|
398
|
+
// eslint-disable-next-line no-console
|
|
399
|
+
console.warn(`Deprecated. Use layer.setFeatureState(features, {highlighted: true}) instead.`);
|
|
383
400
|
// Filter out selected features
|
|
384
401
|
const filtered = ((_a = this.highlightedFeatures) === null || _a === void 0 ? void 0 : _a.filter((feature) => !(this.selectedFeatures || [])
|
|
385
402
|
.map((feat) => feat.getId())
|
|
@@ -392,8 +409,6 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
392
409
|
}
|
|
393
410
|
/**
|
|
394
411
|
* Apply visibility to style layers that fits the styleLayersFilter function.
|
|
395
|
-
*
|
|
396
|
-
* @private
|
|
397
412
|
*/
|
|
398
413
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
399
414
|
applyLayoutVisibility(evt) {
|
|
@@ -5,8 +5,7 @@ import { Map, MapEvent } from 'ol';
|
|
|
5
5
|
import { ObjectEvent } from 'ol/Object';
|
|
6
6
|
import Layer from 'ol/layer/Layer';
|
|
7
7
|
import { RealtimeLayerMixinOptions } from '../../common/mixins/RealtimeLayerMixin';
|
|
8
|
-
import { RealtimeFullTrajectory, RealtimeTrainId, ViewState } from '../../types';
|
|
9
|
-
import { RealtimeTrajectory } from '../../api/typedefs';
|
|
8
|
+
import { RealtimeFullTrajectory, RealtimeTrainId, RealtimeTrajectory, ViewState } from '../../types';
|
|
10
9
|
import { WebSocketAPIMessageEventData } from '../../api/WebSocketAPI';
|
|
11
10
|
import RealtimeLayerRenderer from '../renderers/RealtimeLayerRenderer';
|
|
12
11
|
export type RealtimeLayerOptions = RealtimeLayerMixinOptions & {
|
|
@@ -18,7 +17,7 @@ declare const RealtimeLayer_base: {
|
|
|
18
17
|
[x: string]: any;
|
|
19
18
|
debug: boolean;
|
|
20
19
|
trajectories?: {
|
|
21
|
-
[key: string]:
|
|
20
|
+
[key: string]: RealtimeTrajectory;
|
|
22
21
|
} | undefined;
|
|
23
22
|
canvas?: import("../../types").AnyCanvas | undefined;
|
|
24
23
|
mode: import("../../types").RealtimeMode;
|
|
@@ -26,7 +25,7 @@ declare const RealtimeLayer_base: {
|
|
|
26
25
|
tenant: string;
|
|
27
26
|
bboxParameters?: {
|
|
28
27
|
[index: string]: string | number | boolean | string[] | number[] | boolean[];
|
|
29
|
-
} | undefined;
|
|
28
|
+
} | undefined; /** @private */
|
|
30
29
|
time?: Date | undefined;
|
|
31
30
|
live?: boolean | undefined;
|
|
32
31
|
speed?: number | undefined;
|
|
@@ -48,12 +47,16 @@ declare const RealtimeLayer_base: {
|
|
|
48
47
|
generalizationLevel?: import("../../types").RealtimeGeneralizationLevel | undefined;
|
|
49
48
|
generalizationLevelByZoom: import("../../types").RealtimeGeneralizationLevel[];
|
|
50
49
|
renderTimeIntervalByZoom: number[];
|
|
50
|
+
/**
|
|
51
|
+
* Destroy the container of the tracker.
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
51
54
|
format: GeoJSON<typeof Feature>;
|
|
52
55
|
requestId?: number | undefined;
|
|
53
56
|
updateTimeInterval?: number | undefined;
|
|
54
57
|
updateTimeDelay?: number | undefined;
|
|
55
58
|
visibilityRef: import("ol/events").EventsKey;
|
|
56
|
-
selectedVehicle:
|
|
59
|
+
selectedVehicle: RealtimeTrajectory;
|
|
57
60
|
getMotsByZoom: (zoom: number) => import("../../types").RealtimeMot[];
|
|
58
61
|
getGeneralizationLevelByZoom: (zoom: number) => import("../../types").RealtimeGeneralizationLevel;
|
|
59
62
|
getRenderTimeIntervalByZoom: (zoom: number) => number;
|
|
@@ -72,19 +75,19 @@ declare const RealtimeLayer_base: {
|
|
|
72
75
|
renderTrajectories(viewState: ViewState | undefined, noInterpolate: boolean | undefined): void;
|
|
73
76
|
setBbox(extent: [number, number, number, number], zoom: number): void;
|
|
74
77
|
getRefreshTimeInMs(zoom?: number | undefined): number;
|
|
75
|
-
getVehicle(filterFc: Function):
|
|
78
|
+
getVehicle(filterFc: Function): RealtimeTrajectory[];
|
|
76
79
|
getFeatureInfoAtCoordinate(coordinate: import("ol/coordinate").Coordinate, options: import("../../types").LayerGetFeatureInfoOptions): Promise<import("../../types").LayerGetFeatureInfoResponse>;
|
|
77
80
|
getTrajectoryInfos(id: string): Promise<{
|
|
78
|
-
stopSequence: WebSocketAPIMessageEventData<RealtimeFullTrajectory> | WebSocketAPIMessageEventData<
|
|
79
|
-
fullTrajectory: WebSocketAPIMessageEventData<RealtimeFullTrajectory> | WebSocketAPIMessageEventData<
|
|
81
|
+
stopSequence: WebSocketAPIMessageEventData<RealtimeFullTrajectory> | WebSocketAPIMessageEventData<import("../../types").RealtimeStopSequence[]>;
|
|
82
|
+
fullTrajectory: WebSocketAPIMessageEventData<RealtimeFullTrajectory> | WebSocketAPIMessageEventData<import("../../types").RealtimeStopSequence[]>;
|
|
80
83
|
}>;
|
|
81
84
|
purgeOutOfDateTrajectories(): void;
|
|
82
|
-
purgeTrajectory(trajectory:
|
|
83
|
-
addTrajectory(trajectory:
|
|
84
|
-
removeTrajectory(trajectoryOrId:
|
|
85
|
+
purgeTrajectory(trajectory: RealtimeTrajectory, extent: [number, number, number, number], zoom: number): boolean;
|
|
86
|
+
addTrajectory(trajectory: RealtimeTrajectory): void;
|
|
87
|
+
removeTrajectory(trajectoryOrId: string | RealtimeTrajectory): void;
|
|
85
88
|
onZoomEnd(): void;
|
|
86
89
|
onDocumentVisibilityChange(): void;
|
|
87
|
-
onTrajectoryMessage(data: WebSocketAPIMessageEventData<
|
|
90
|
+
onTrajectoryMessage(data: WebSocketAPIMessageEventData<RealtimeTrajectory>): void;
|
|
88
91
|
onDeleteTrajectoryMessage(data: WebSocketAPIMessageEventData<string>): void;
|
|
89
92
|
highlightVehicle(id: string): void;
|
|
90
93
|
selectVehicle(id: string): void;
|
|
@@ -180,7 +183,7 @@ declare const RealtimeLayer_base: {
|
|
|
180
183
|
};
|
|
181
184
|
} & typeof Layer;
|
|
182
185
|
/**
|
|
183
|
-
*
|
|
186
|
+
* An OpenLayers layer able to display data from the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
|
|
184
187
|
*
|
|
185
188
|
* @example
|
|
186
189
|
* import { RealtimeLayer } from 'mobility-toolbox-js/ol';
|
|
@@ -208,7 +211,7 @@ declare class RealtimeLayer extends RealtimeLayer_base {
|
|
|
208
211
|
* @param {RealtimeLayerOptions} options
|
|
209
212
|
* @param {boolean} [options.allowRenderWhenAnimating=false] Allow rendering of the layer when the map is animating.
|
|
210
213
|
* @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
|
|
211
|
-
* @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps
|
|
214
|
+
* @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps Realtime API url.
|
|
212
215
|
*
|
|
213
216
|
*/
|
|
214
217
|
constructor(options: RealtimeLayerOptions);
|
|
@@ -11,7 +11,7 @@ import RealtimeLayerRenderer from '../renderers/RealtimeLayerRenderer';
|
|
|
11
11
|
/** @private */
|
|
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';
|
|
@@ -38,7 +38,7 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
|
|
|
38
38
|
* @param {RealtimeLayerOptions} options
|
|
39
39
|
* @param {boolean} [options.allowRenderWhenAnimating=false] Allow rendering of the layer when the map is animating.
|
|
40
40
|
* @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
|
|
41
|
-
* @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps
|
|
41
|
+
* @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps Realtime API url.
|
|
42
42
|
*
|
|
43
43
|
*/
|
|
44
44
|
constructor(options) {
|
package/ol/layers/index.d.ts
CHANGED
package/ol/layers/index.js
CHANGED
|
@@ -100,7 +100,10 @@ export default class RealtimeLayerRenderer extends CanvasLayerRenderer {
|
|
|
100
100
|
const vehicles = [];
|
|
101
101
|
for (let i = 0; i < trajectories.length; i += 1) {
|
|
102
102
|
const trajectory = trajectories[i];
|
|
103
|
-
if (
|
|
103
|
+
if (
|
|
104
|
+
// @ts-expect-error coordinate is added by the RealtimeLayer
|
|
105
|
+
trajectory.properties.coordinate &&
|
|
106
|
+
// @ts-expect-error coordinate is added by the RealtimeLayer
|
|
104
107
|
containsCoordinate(ext, trajectory.properties.coordinate)) {
|
|
105
108
|
vehicles.push(trajectories[i]);
|
|
106
109
|
}
|
package/package.json
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
"name": "mobility-toolbox-js",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"description": "Toolbox for JavaScript applications in the domains of mobility and logistics.",
|
|
5
|
-
"version": "3.0.0-beta.
|
|
5
|
+
"version": "3.0.0-beta.12",
|
|
6
6
|
"homepage": "https://mobility-toolbox-js.geops.io/",
|
|
7
|
-
"module": "index.js",
|
|
8
7
|
"exports": {
|
|
9
8
|
".": "./index.js",
|
|
10
9
|
"./api": "./api/index.js",
|
|
@@ -24,10 +23,10 @@
|
|
|
24
23
|
"ol": ">=7"
|
|
25
24
|
},
|
|
26
25
|
"devDependencies": {
|
|
27
|
-
"@babel/preset-env": "^7.24.
|
|
26
|
+
"@babel/preset-env": "^7.24.5",
|
|
28
27
|
"@babel/preset-typescript": "^7.24.1",
|
|
29
|
-
"@commitlint/cli": "19.
|
|
30
|
-
"@commitlint/config-conventional": "19.
|
|
28
|
+
"@commitlint/cli": "19.3.0",
|
|
29
|
+
"@commitlint/config-conventional": "19.2.2",
|
|
31
30
|
"@types/geojson": "7946.0.14",
|
|
32
31
|
"@types/lodash.debounce": "4.0.9",
|
|
33
32
|
"@types/lodash.throttle": "4.1.9",
|
|
@@ -35,10 +34,10 @@
|
|
|
35
34
|
"@types/offscreencanvas": "2019.7.3",
|
|
36
35
|
"@types/topojson": "3.2.6",
|
|
37
36
|
"@types/uuid": "9.0.8",
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "7.
|
|
39
|
-
"@typescript-eslint/parser": "7.
|
|
40
|
-
"cypress": "13.
|
|
41
|
-
"esbuild": "0.
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "7.8.0",
|
|
38
|
+
"@typescript-eslint/parser": "7.8.0",
|
|
39
|
+
"cypress": "13.8.1",
|
|
40
|
+
"esbuild": "0.21.1",
|
|
42
41
|
"esdoc": "1.1.0",
|
|
43
42
|
"esdoc-ecmascript-proposal-plugin": "1.0.0",
|
|
44
43
|
"esdoc-publish-html-plugin": "1.1.2",
|
|
@@ -48,7 +47,7 @@
|
|
|
48
47
|
"eslint-config-airbnb": "19.0.4",
|
|
49
48
|
"eslint-config-airbnb-typescript": "18.0.0",
|
|
50
49
|
"eslint-config-prettier": "9.1.0",
|
|
51
|
-
"eslint-plugin-cypress": "2.
|
|
50
|
+
"eslint-plugin-cypress": "3.2.0",
|
|
52
51
|
"eslint-plugin-import": "2.29.1",
|
|
53
52
|
"eslint-plugin-jsx-a11y": "6.8.0",
|
|
54
53
|
"eslint-plugin-prettier": "5.1.3",
|
|
@@ -64,9 +63,9 @@
|
|
|
64
63
|
"jest-transformer-svg": "2.0.2",
|
|
65
64
|
"jest-websocket-mock": "2.5.0",
|
|
66
65
|
"lint-staged": "15.2.2",
|
|
67
|
-
"maplibre-gl": "4.
|
|
66
|
+
"maplibre-gl": "4.2.0",
|
|
68
67
|
"mock-socket": "9.3.1",
|
|
69
|
-
"next": "14.
|
|
68
|
+
"next": "14.2.3",
|
|
70
69
|
"next-transpile-modules": "10.0.1",
|
|
71
70
|
"ol": "9.1.0",
|
|
72
71
|
"openapi-typescript": "6.7.5",
|
|
@@ -75,11 +74,11 @@
|
|
|
75
74
|
"sort-json": "2.0.1",
|
|
76
75
|
"standard-version": "9.5.0",
|
|
77
76
|
"start-server-and-test": "2.0.3",
|
|
78
|
-
"stylelint": "16.
|
|
77
|
+
"stylelint": "16.5.0",
|
|
79
78
|
"stylelint-config-recommended-scss": "14.0.0",
|
|
80
79
|
"stylelint-config-standard": "36.0.0",
|
|
81
|
-
"stylelint-scss": "6.
|
|
82
|
-
"typescript": "5.4.
|
|
80
|
+
"stylelint-scss": "6.3.0",
|
|
81
|
+
"typescript": "5.4.5"
|
|
83
82
|
},
|
|
84
83
|
"scripts": {
|
|
85
84
|
"apidoc": "esdoc && cp apidoc/index.json doc/src/components/Esdoc",
|
package/ol/layers/MapGlLayer.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import Source from 'ol/source/Source';
|
|
2
|
-
import BaseEvent from 'ol/events/Event';
|
|
3
|
-
import Layer from 'ol/layer/Layer';
|
|
4
|
-
import debounce from 'lodash.debounce';
|
|
5
|
-
import { getUrlWithParams, getMapGlCopyrights } from '../../common/utils';
|
|
6
|
-
import MobilityLayerMixin from '../mixins/MobilityLayerMixin';
|
|
7
|
-
/**
|
|
8
|
-
* Common class for Maplibre and Maplibre and potential other fork from Maplibre.
|
|
9
|
-
* It's used to share code between Maplibre and Maplibre layers without importing both libs.
|
|
10
|
-
* @private
|
|
11
|
-
*/
|
|
12
|
-
class MapGlLayer extends MobilityLayerMixin(Layer) {
|
|
13
|
-
get apiKey() {
|
|
14
|
-
return this.get('apiKey');
|
|
15
|
-
}
|
|
16
|
-
set apiKey(newValue) {
|
|
17
|
-
this.set('apiKey', newValue);
|
|
18
|
-
}
|
|
19
|
-
get apiKeyName() {
|
|
20
|
-
return this.get('apiKeyName');
|
|
21
|
-
}
|
|
22
|
-
set apiKeyName(newValue) {
|
|
23
|
-
this.set('apiKeyName', newValue);
|
|
24
|
-
}
|
|
25
|
-
get style() {
|
|
26
|
-
return this.get('style');
|
|
27
|
-
}
|
|
28
|
-
set style(newValue) {
|
|
29
|
-
this.set('style', newValue);
|
|
30
|
-
}
|
|
31
|
-
get url() {
|
|
32
|
-
return this.get('url');
|
|
33
|
-
}
|
|
34
|
-
set url(newValue) {
|
|
35
|
-
this.set('url', newValue);
|
|
36
|
-
}
|
|
37
|
-
get queryRenderedFeaturesOptions() {
|
|
38
|
-
return this.get('queryRenderedFeaturesOptions');
|
|
39
|
-
}
|
|
40
|
-
set queryRenderedFeaturesOptions(newValue) {
|
|
41
|
-
this.set('queryRenderedFeaturesOptions', newValue);
|
|
42
|
-
}
|
|
43
|
-
constructor(options) {
|
|
44
|
-
super(Object.assign(Object.assign({ source: new Source({
|
|
45
|
-
attributions: () => {
|
|
46
|
-
return (this.mbMap && getMapGlCopyrights(this.mbMap)) || [];
|
|
47
|
-
},
|
|
48
|
-
}), apiKeyName: 'key', style: 'travic_v2', url: 'https://maps.geops.io' }, (options || {})), {
|
|
49
|
-
// @ts-expect-error mapOptions must be saved by the mixin in this.options
|
|
50
|
-
mapOptions: Object.assign({ interactive: false, trackResize: false, attributionControl: false }, ((options === null || options === void 0 ? void 0 : options.mapOptions) || {})), queryRenderedFeaturesOptions: Object.assign({}, ((options === null || options === void 0 ? void 0 : options.queryRenderedFeaturesOptions) || {})) }));
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Initialize the layer and listen to feature clicks.
|
|
54
|
-
* @param {ol/Map~Map} map
|
|
55
|
-
*/
|
|
56
|
-
attachToMap(map) {
|
|
57
|
-
super.attachToMap(map);
|
|
58
|
-
this.loadMbMap();
|
|
59
|
-
const updateMbMapDebounced = debounce(this.updateMbMap.bind(this), 150);
|
|
60
|
-
this.olListenersKeys.push(this.on('propertychange', (evt) => {
|
|
61
|
-
if (/(apiKey|apiKeyName|url|style)/.test(evt.key)) {
|
|
62
|
-
updateMbMapDebounced();
|
|
63
|
-
}
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Terminate what was initialized in init function. Remove layer, events...
|
|
68
|
-
*/
|
|
69
|
-
detachFromMap() {
|
|
70
|
-
if (this.mbMap) {
|
|
71
|
-
// Some asynchrone repaints are triggered even if the mbMap has been removed,
|
|
72
|
-
// to avoid display of errors we set an empty function.
|
|
73
|
-
this.mbMap.triggerRepaint = () => { };
|
|
74
|
-
this.mbMap.remove();
|
|
75
|
-
this.mbMap = undefined;
|
|
76
|
-
}
|
|
77
|
-
this.loaded = false;
|
|
78
|
-
super.detachFromMap();
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Create the Maplibre map.
|
|
82
|
-
* @private
|
|
83
|
-
*/
|
|
84
|
-
loadMbMap() {
|
|
85
|
-
var _a, _b, _c;
|
|
86
|
-
this.loaded = false;
|
|
87
|
-
this.olListenersKeys.push(
|
|
88
|
-
// @ts-ignore
|
|
89
|
-
(_a = this.map) === null || _a === void 0 ? void 0 : _a.on('change:target', this.loadMbMap.bind(this)));
|
|
90
|
-
if (!((_b = this.map) === null || _b === void 0 ? void 0 : _b.getTargetElement())) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
if (!this.visible) {
|
|
94
|
-
// On next change of visibility we load the map
|
|
95
|
-
this.olListenersKeys.push(
|
|
96
|
-
// @ts-ignore
|
|
97
|
-
this.once('change:visible', this.loadMbMap.bind(this)));
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const container = document.createElement('div');
|
|
101
|
-
container.style.position = 'absolute';
|
|
102
|
-
container.style.width = '100%';
|
|
103
|
-
container.style.height = '100%';
|
|
104
|
-
/**
|
|
105
|
-
* A Maplibre map
|
|
106
|
-
* @type {maplibregl.Map}
|
|
107
|
-
*/
|
|
108
|
-
this.mbMap = this.createMap(Object.assign({ style: this.getStyle(), container }, (((_c = this.options) === null || _c === void 0 ? void 0 : _c.mapOptions) || {})));
|
|
109
|
-
this.mbMap.on('sourcedata', () => {
|
|
110
|
-
var _a;
|
|
111
|
-
(_a = this.getSource()) === null || _a === void 0 ? void 0 : _a.refresh(); // Refresh attribution
|
|
112
|
-
});
|
|
113
|
-
this.mbMap.once('load', () => {
|
|
114
|
-
this.loaded = true;
|
|
115
|
-
this.dispatchEvent(new BaseEvent('load'));
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
getStyle() {
|
|
119
|
-
// If the style is a complete style object, use it directly.
|
|
120
|
-
if (this.style &&
|
|
121
|
-
typeof this.style === 'object' &&
|
|
122
|
-
this.style.name &&
|
|
123
|
-
this.style.version) {
|
|
124
|
-
return this.style;
|
|
125
|
-
}
|
|
126
|
-
// If the url set is already a complete style url, use it directly.
|
|
127
|
-
if (this.url.includes('style.json')) {
|
|
128
|
-
return this.url;
|
|
129
|
-
}
|
|
130
|
-
/// Otherwise build the complete style url.
|
|
131
|
-
return getUrlWithParams(`${this.url}/styles/${this.style}/style.json`, {
|
|
132
|
-
[this.apiKeyName]: this.apiKey,
|
|
133
|
-
}).toString();
|
|
134
|
-
}
|
|
135
|
-
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
|
|
136
|
-
createMap(options) {
|
|
137
|
-
throw new Error('createMap must be implemented in child class');
|
|
138
|
-
}
|
|
139
|
-
updateMbMap() {
|
|
140
|
-
var _a;
|
|
141
|
-
(_a = this.mbMap) === null || _a === void 0 ? void 0 : _a.setStyle(this.getStyle(), { diff: false });
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
export default MapGlLayer;
|