mobility-toolbox-js 3.0.0-beta.2 → 3.0.0-beta.21
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.d.ts +20 -0
- package/api/HttpAPI.js +0 -11
- package/api/RealtimeAPI.d.ts +404 -0
- package/api/RealtimeAPI.js +342 -276
- package/api/RoutingAPI.d.ts +47 -0
- package/api/RoutingAPI.js +17 -7
- package/api/StopsAPI.d.ts +44 -0
- package/api/StopsAPI.js +16 -10
- package/api/WebSocketAPI.d.ts +147 -0
- package/api/WebSocketAPI.js +164 -164
- package/api/index.d.ts +3 -0
- package/api/index.js +1 -1
- package/api/typedefs.d.ts +76 -0
- package/api/typedefs.js +27 -42
- package/common/controls/StopFinderControlCommon.d.ts +53 -0
- package/common/controls/StopFinderControlCommon.js +31 -31
- package/common/index.d.ts +2 -0
- package/common/index.js +1 -1
- package/common/mixins/RealtimeLayerMixin.d.ts +267 -0
- package/common/mixins/RealtimeLayerMixin.js +401 -393
- package/common/styles/index.d.ts +4 -0
- package/common/styles/realtimeDefaultStyle.d.ts +36 -0
- package/common/styles/realtimeDefaultStyle.js +6 -6
- package/common/styles/realtimeDelayStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.js +5 -5
- package/common/styles/realtimeSimpleStyle.d.ts +4 -0
- package/common/typedefs.d.ts +219 -0
- package/common/typedefs.js +7 -1
- package/common/utils/compareDepartures.d.ts +10 -0
- package/common/utils/compareDepartures.js +2 -2
- package/common/utils/constants.d.ts +5 -0
- package/common/utils/createCanvas.d.ts +10 -0
- package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
- package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
- package/common/utils/createRealtimeFilters.d.ts +12 -0
- package/common/utils/debounceDeparturesMessages.d.ts +12 -0
- package/common/utils/debounceWebsocketMessages.d.ts +11 -0
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.js +5 -1
- package/common/utils/getMapGlCopyrights.d.ts +17 -0
- package/common/utils/getMapGlCopyrights.js +3 -3
- package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
- package/common/utils/getRealtimeModeSuffix.js +1 -0
- package/common/utils/getUrlWithParams.d.ts +8 -0
- package/common/utils/getVehiclePosition.d.ts +17 -0
- package/common/utils/getVehiclePosition.js +9 -3
- package/common/utils/index.d.ts +16 -0
- package/common/utils/realtimeConfig.d.ts +64 -0
- package/common/utils/removeDuplicate.d.ts +9 -0
- package/common/utils/renderTrajectories.d.ts +16 -0
- package/common/utils/renderTrajectories.js +6 -6
- package/common/utils/sortAndFilterDepartures.d.ts +15 -0
- package/common/utils/sortAndFilterDepartures.js +1 -1
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.js +5 -1
- package/common/utils/timeUtils.d.ts +23 -0
- package/common/utils/toMercatorExtent.d.ts +5 -0
- package/iife.d.ts +2 -0
- package/index.d.ts +9 -0
- package/maplibre/controls/CopyrightControl.d.ts +35 -0
- package/maplibre/controls/index.d.ts +1 -0
- package/maplibre/index.d.ts +5 -0
- package/maplibre/layers/Layer.d.ts +28 -0
- package/maplibre/layers/Layer.js +1 -1
- package/maplibre/layers/RealtimeLayer.d.ts +181 -0
- package/maplibre/layers/RealtimeLayer.js +29 -5
- package/maplibre/layers/index.d.ts +2 -0
- package/maplibre/utils/getMercatorResolution.d.ts +7 -0
- package/maplibre/utils/getSourceCoordinates.d.ts +7 -0
- package/maplibre/utils/getSourceCoordinates.js +5 -5
- package/maplibre/utils/index.d.ts +2 -0
- package/mbt.js +22103 -14430
- package/mbt.js.map +4 -4
- package/mbt.min.js +61 -58
- package/mbt.min.js.map +4 -4
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.js +18 -8
- package/ol/controls/RoutingControl.d.ts +202 -0
- package/ol/controls/RoutingControl.js +220 -219
- package/ol/controls/StopFinderControl.d.ts +37 -0
- package/ol/controls/StopFinderControl.js +4 -1
- package/ol/controls/index.d.ts +3 -0
- package/ol/index.d.ts +7 -0
- package/ol/index.js +1 -0
- package/ol/layers/Layer.d.ts +101 -0
- package/ol/layers/Layer.js +25 -0
- package/ol/layers/MaplibreLayer.d.ts +160 -0
- package/ol/layers/MaplibreLayer.js +97 -27
- package/ol/layers/MaplibreStyleLayer.d.ts +237 -0
- package/ol/layers/MaplibreStyleLayer.js +291 -267
- package/ol/layers/RealtimeLayer.d.ts +283 -0
- package/ol/layers/RealtimeLayer.js +143 -128
- package/ol/layers/VectorLayer.d.ts +18 -0
- package/ol/layers/VectorLayer.js +31 -0
- package/ol/layers/index.d.ts +5 -0
- package/ol/layers/index.js +3 -0
- package/ol/mixins/MobilityLayerMixin.d.ts +96 -0
- package/ol/mixins/MobilityLayerMixin.js +1 -4
- package/ol/mixins/PropertiesLayerMixin.d.ts +135 -0
- package/ol/mixins/PropertiesLayerMixin.js +112 -140
- package/ol/mixins/index.d.ts +1 -0
- package/ol/mixins/index.js +2 -0
- package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
- package/ol/renderers/MaplibreLayerRenderer.js +142 -114
- package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
- package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
- package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
- package/ol/renderers/RealtimeLayerRenderer.js +58 -53
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
- package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/routingStyle.d.ts +4 -0
- package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
- package/ol/utils/getFeatureInfoAtCoordinate.js +12 -18
- package/ol/utils/index.d.ts +1 -0
- package/package.json +31 -31
- package/setupTests.d.ts +1 -0
- package/setupTests.js +3 -4
- package/types/common.d.ts +55 -48
- package/types/index.d.ts +1 -1
- package/types/realtime.d.ts +91 -93
- package/types/routing.d.ts +60 -60
- package/types/stops.d.ts +62 -62
- package/ol/layers/MapGlLayer.js +0 -142
|
@@ -1,114 +1,142 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
// /* eslint-disable no-underscore-dangle */
|
|
3
|
+
// import { FrameState } from 'ol/Map';
|
|
4
|
+
// import { toDegrees } from 'ol/math';
|
|
5
|
+
// import { toLonLat } from 'ol/proj';
|
|
6
|
+
// import LayerRenderer from 'ol/renderer/Layer';
|
|
7
|
+
// import GeoJSON from 'ol/format/GeoJSON';
|
|
8
|
+
// import { Coordinate } from 'ol/coordinate';
|
|
9
|
+
// import { FeatureCallback } from 'ol/renderer/vector';
|
|
10
|
+
// import { Feature } from 'ol';
|
|
11
|
+
// import { Geometry } from 'ol/geom';
|
|
12
|
+
// import { Pixel } from 'ol/pixel';
|
|
13
|
+
// import { Map } from 'maplibre-gl';
|
|
14
|
+
// import { VECTOR_TILE_FEATURE_PROPERTY } from '../../common';
|
|
15
|
+
// import type MaplibreLayer from '../layers/MaplibreLayer';
|
|
16
|
+
// /**
|
|
17
|
+
// * @private
|
|
18
|
+
// */
|
|
19
|
+
// const formats: {
|
|
20
|
+
// [key: string]: GeoJSON;
|
|
21
|
+
// } = {
|
|
22
|
+
// 'EPSG:3857': new GeoJSON({
|
|
23
|
+
// featureProjection: 'EPSG:3857',
|
|
24
|
+
// }),
|
|
25
|
+
// };
|
|
26
|
+
// /**
|
|
27
|
+
// * This class is a renderer for Maplibre Layer to be able to use the native ol
|
|
28
|
+
// * functionnalities like map.getFeaturesAtPixel or map.hasFeatureAtPixel.
|
|
29
|
+
// * @private
|
|
30
|
+
// */
|
|
31
|
+
// // @ts-expect-error
|
|
32
|
+
// export default class MaplibreLayerRenderer extends LayerRenderer<MaplibreLayer> {
|
|
33
|
+
// getFeaturesAtCoordinate(
|
|
34
|
+
// coordinate: Coordinate | undefined,
|
|
35
|
+
// hitTolerance: number = 5,
|
|
36
|
+
// ): Feature<Geometry>[] {
|
|
37
|
+
// if (!coordinate) {
|
|
38
|
+
// return [];
|
|
39
|
+
// }
|
|
40
|
+
// const layer = this.getLayer();
|
|
41
|
+
// const map = layer.getMapInternal();
|
|
42
|
+
// const { mbMap } = layer;
|
|
43
|
+
// const projection =
|
|
44
|
+
// map?.getView()?.getProjection()?.getCode() || 'EPSG:3857';
|
|
45
|
+
// let features: Feature[] = [];
|
|
46
|
+
// if (!formats[projection]) {
|
|
47
|
+
// formats[projection] = new GeoJSON({
|
|
48
|
+
// featureProjection: projection,
|
|
49
|
+
// });
|
|
50
|
+
// }
|
|
51
|
+
// if (mbMap?.isStyleLoaded()) {
|
|
52
|
+
// const pixel =
|
|
53
|
+
// coordinate && mbMap.project(toLonLat(coordinate) as [number, number]);
|
|
54
|
+
// if (pixel?.x && pixel?.y) {
|
|
55
|
+
// let pixels: [[number, number], [number, number]] | [number, number] = [
|
|
56
|
+
// pixel.x,
|
|
57
|
+
// pixel.y,
|
|
58
|
+
// ];
|
|
59
|
+
// if (hitTolerance) {
|
|
60
|
+
// const [x, y] = pixels as [number, number];
|
|
61
|
+
// pixels = [
|
|
62
|
+
// [x - hitTolerance, y - hitTolerance],
|
|
63
|
+
// [x + hitTolerance, y + hitTolerance],
|
|
64
|
+
// ];
|
|
65
|
+
// }
|
|
66
|
+
// // At this point we get GeoJSON Maplibre feature, we transform it to an OpenLayers
|
|
67
|
+
// // feature to be consistent with other layers.
|
|
68
|
+
// features = (mbMap as Map)
|
|
69
|
+
// .queryRenderedFeatures(
|
|
70
|
+
// pixels,
|
|
71
|
+
// layer.queryRenderedFeaturesOptions || {},
|
|
72
|
+
// )
|
|
73
|
+
// .map((feature) => {
|
|
74
|
+
// const olFeature = formats[projection].readFeature(
|
|
75
|
+
// feature,
|
|
76
|
+
// ) as Feature;
|
|
77
|
+
// if (olFeature) {
|
|
78
|
+
// // We save the original Maplibre feature to avoid losing informations
|
|
79
|
+
// // potentially needed for other functionnality like highlighting
|
|
80
|
+
// // (id, layer id, source, sourceLayer ...)
|
|
81
|
+
// // @ts-expect-error
|
|
82
|
+
// olFeature.set(VECTOR_TILE_FEATURE_PROPERTY, feature);
|
|
83
|
+
// }
|
|
84
|
+
// return olFeature;
|
|
85
|
+
// });
|
|
86
|
+
// }
|
|
87
|
+
// }
|
|
88
|
+
// return features;
|
|
89
|
+
// }
|
|
90
|
+
// // eslint-disable-next-line class-methods-use-this
|
|
91
|
+
// override prepareFrame() {
|
|
92
|
+
// return true;
|
|
93
|
+
// }
|
|
94
|
+
// override renderFrame(frameState: FrameState) {
|
|
95
|
+
// const layer = this.getLayer();
|
|
96
|
+
// const { map, mbMap } = layer;
|
|
97
|
+
// if (!layer || !map || !mbMap) {
|
|
98
|
+
// return null;
|
|
99
|
+
// }
|
|
100
|
+
// const canvas = mbMap.getCanvas();
|
|
101
|
+
// const { viewState } = frameState;
|
|
102
|
+
// const opacity = layer.getOpacity() || 1;
|
|
103
|
+
// canvas.style.opacity = `${opacity}`;
|
|
104
|
+
// // adjust view parameters in Maplibre
|
|
105
|
+
// mbMap.jumpTo({
|
|
106
|
+
// center: toLonLat(viewState.center) as [number, number],
|
|
107
|
+
// zoom: viewState.zoom - 1,
|
|
108
|
+
// bearing: toDegrees(-viewState.rotation),
|
|
109
|
+
// });
|
|
110
|
+
// if (!canvas.isConnected) {
|
|
111
|
+
// // The canvas is not connected to the DOM, request a map rendering at the next animation frame
|
|
112
|
+
// // to set the canvas size.
|
|
113
|
+
// map.render();
|
|
114
|
+
// } else if (
|
|
115
|
+
// canvas.width !== frameState.size[0] ||
|
|
116
|
+
// canvas.height !== frameState.size[1]
|
|
117
|
+
// ) {
|
|
118
|
+
// mbMap.resize();
|
|
119
|
+
// }
|
|
120
|
+
// mbMap.redraw();
|
|
121
|
+
// return mbMap.getContainer();
|
|
122
|
+
// }
|
|
123
|
+
// override getFeatures(pixel: Pixel) {
|
|
124
|
+
// const coordinate = this.getLayer()
|
|
125
|
+
// ?.getMapInternal()
|
|
126
|
+
// ?.getCoordinateFromPixel(pixel);
|
|
127
|
+
// return Promise.resolve(this.getFeaturesAtCoordinate(coordinate));
|
|
128
|
+
// }
|
|
129
|
+
// override forEachFeatureAtCoordinate<Feature>(
|
|
130
|
+
// coordinate: Coordinate,
|
|
131
|
+
// frameState: FrameState,
|
|
132
|
+
// hitTolerance: number,
|
|
133
|
+
// callback: FeatureCallback<Feature>,
|
|
134
|
+
// ): Feature | undefined {
|
|
135
|
+
// const features = this.getFeaturesAtCoordinate(coordinate, hitTolerance);
|
|
136
|
+
// features.forEach((feature) => {
|
|
137
|
+
// // @ts-expect-error
|
|
138
|
+
// callback(feature, this.layer_, feature.getGeometry());
|
|
139
|
+
// });
|
|
140
|
+
// return features?.[0] as Feature;
|
|
141
|
+
// }
|
|
142
|
+
// }
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Feature } from 'ol';
|
|
2
|
+
import { Coordinate } from 'ol/coordinate';
|
|
3
|
+
import { Geometry } from 'ol/geom';
|
|
4
|
+
import { FrameState } from 'ol/Map';
|
|
5
|
+
import { Pixel } from 'ol/pixel';
|
|
6
|
+
import LayerRenderer from 'ol/renderer/Layer';
|
|
7
|
+
import { FeatureCallback } from 'ol/renderer/vector';
|
|
8
|
+
import type { MaplibreStyleLayer } from '../layers';
|
|
9
|
+
/**
|
|
10
|
+
* This class is a renderer for Maplibre Layer to be able to use the native ol
|
|
11
|
+
* functionnalities like map.getFeaturesAtPixel or map.hasFeatureAtPixel.
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
export default class MaplibreStyleLayerRenderer extends LayerRenderer<MaplibreStyleLayer> {
|
|
15
|
+
forEachFeatureAtCoordinate<Feature>(coordinate: Coordinate, frameState: FrameState, hitTolerance: number, callback: FeatureCallback<Feature>): Feature | undefined;
|
|
16
|
+
getFeatures(pixel: Pixel): Promise<Feature<Geometry>[]>;
|
|
17
|
+
getFeaturesAtCoordinate(coordinate: Coordinate | undefined, hitTolerance?: number): Feature<Geometry>[];
|
|
18
|
+
prepareFrame(): boolean;
|
|
19
|
+
renderFrame(): null;
|
|
20
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import GeoJSON from 'ol/format/GeoJSON';
|
|
1
2
|
import { toLonLat } from 'ol/proj';
|
|
2
3
|
import LayerRenderer from 'ol/renderer/Layer';
|
|
3
|
-
import GeoJSON from 'ol/format/GeoJSON';
|
|
4
4
|
import { VECTOR_TILE_FEATURE_PROPERTY } from '../../common';
|
|
5
5
|
/**
|
|
6
6
|
* @private
|
|
@@ -15,8 +15,20 @@ const formats = {
|
|
|
15
15
|
* functionnalities like map.getFeaturesAtPixel or map.hasFeatureAtPixel.
|
|
16
16
|
* @private
|
|
17
17
|
*/
|
|
18
|
-
// @ts-ignore
|
|
19
18
|
export default class MaplibreStyleLayerRenderer extends LayerRenderer {
|
|
19
|
+
forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback) {
|
|
20
|
+
const features = this.getFeaturesAtCoordinate(coordinate, hitTolerance);
|
|
21
|
+
features.forEach((feature) => {
|
|
22
|
+
// @ts-expect-error
|
|
23
|
+
callback(feature, this.layer_, feature.getGeometry());
|
|
24
|
+
});
|
|
25
|
+
return features === null || features === void 0 ? void 0 : features[0];
|
|
26
|
+
}
|
|
27
|
+
getFeatures(pixel) {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
const coordinate = (_b = (_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.getMapInternal()) === null || _b === void 0 ? void 0 : _b.getCoordinateFromPixel(pixel);
|
|
30
|
+
return Promise.resolve(this.getFeaturesAtCoordinate(coordinate));
|
|
31
|
+
}
|
|
20
32
|
getFeaturesAtCoordinate(coordinate, hitTolerance = 5) {
|
|
21
33
|
var _a, _b;
|
|
22
34
|
if (!coordinate) {
|
|
@@ -24,7 +36,7 @@ export default class MaplibreStyleLayerRenderer extends LayerRenderer {
|
|
|
24
36
|
}
|
|
25
37
|
const layer = this.getLayer();
|
|
26
38
|
const map = layer.getMapInternal();
|
|
27
|
-
const {
|
|
39
|
+
const { mapLibreMap } = layer.maplibreLayer;
|
|
28
40
|
const projection = ((_b = (_a = map === null || map === void 0 ? void 0 : map.getView()) === null || _a === void 0 ? void 0 : _a.getProjection()) === null || _b === void 0 ? void 0 : _b.getCode()) || 'EPSG:3857';
|
|
29
41
|
let features = [];
|
|
30
42
|
if (!formats[projection]) {
|
|
@@ -32,9 +44,9 @@ export default class MaplibreStyleLayerRenderer extends LayerRenderer {
|
|
|
32
44
|
featureProjection: projection,
|
|
33
45
|
});
|
|
34
46
|
}
|
|
35
|
-
if (
|
|
47
|
+
if (mapLibreMap === null || mapLibreMap === void 0 ? void 0 : mapLibreMap.isStyleLoaded()) {
|
|
36
48
|
const pixel = coordinate &&
|
|
37
|
-
|
|
49
|
+
mapLibreMap.project(toLonLat(coordinate));
|
|
38
50
|
if ((pixel === null || pixel === void 0 ? void 0 : pixel.x) && (pixel === null || pixel === void 0 ? void 0 : pixel.y)) {
|
|
39
51
|
let pixels = [
|
|
40
52
|
pixel.x,
|
|
@@ -50,18 +62,17 @@ export default class MaplibreStyleLayerRenderer extends LayerRenderer {
|
|
|
50
62
|
// We query features only on style layers used by this layer.
|
|
51
63
|
let layers = layer.layers || [];
|
|
52
64
|
if (layer.layersFilter) {
|
|
53
|
-
layers =
|
|
65
|
+
layers = mapLibreMap.getStyle().layers.filter(layer.layersFilter);
|
|
54
66
|
}
|
|
55
67
|
if (layer.queryRenderedLayersFilter) {
|
|
56
|
-
// @ts-ignore
|
|
57
68
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
58
|
-
layers =
|
|
69
|
+
layers = mapLibreMap
|
|
59
70
|
.getStyle()
|
|
60
71
|
.layers.filter(layer.queryRenderedLayersFilter);
|
|
61
72
|
}
|
|
62
73
|
// At this point we get GeoJSON Maplibre feature, we transform it to an OpenLayers
|
|
63
74
|
// feature to be consistent with other layers.
|
|
64
|
-
features =
|
|
75
|
+
features = mapLibreMap
|
|
65
76
|
.queryRenderedFeatures(pixels, {
|
|
66
77
|
layers: layers.map((l) => l.id),
|
|
67
78
|
validate: false,
|
|
@@ -73,7 +84,6 @@ export default class MaplibreStyleLayerRenderer extends LayerRenderer {
|
|
|
73
84
|
// We save the original Maplibre feature to avoid losing informations
|
|
74
85
|
// potentially needed for other functionnality like highlighting
|
|
75
86
|
// (id, layer id, source, sourceLayer ...)
|
|
76
|
-
// @ts-ignore
|
|
77
87
|
olFeature.set(VECTOR_TILE_FEATURE_PROPERTY, feature);
|
|
78
88
|
}
|
|
79
89
|
return olFeature;
|
|
@@ -90,17 +100,4 @@ export default class MaplibreStyleLayerRenderer extends LayerRenderer {
|
|
|
90
100
|
renderFrame() {
|
|
91
101
|
return null;
|
|
92
102
|
}
|
|
93
|
-
getFeatures(pixel) {
|
|
94
|
-
var _a, _b;
|
|
95
|
-
const coordinate = (_b = (_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.getMapInternal()) === null || _b === void 0 ? void 0 : _b.getCoordinateFromPixel(pixel);
|
|
96
|
-
return Promise.resolve(this.getFeaturesAtCoordinate(coordinate));
|
|
97
|
-
}
|
|
98
|
-
forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback) {
|
|
99
|
-
const features = this.getFeaturesAtCoordinate(coordinate, hitTolerance);
|
|
100
|
-
features.forEach((feature) => {
|
|
101
|
-
// @ts-ignore
|
|
102
|
-
callback(feature, this.layer_, feature.getGeometry());
|
|
103
|
-
});
|
|
104
|
-
return features === null || features === void 0 ? void 0 : features[0];
|
|
105
|
-
}
|
|
106
103
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Feature } from 'ol';
|
|
2
|
+
import { Coordinate } from 'ol/coordinate';
|
|
3
|
+
import { Geometry } from 'ol/geom';
|
|
4
|
+
import { FrameState } from 'ol/Map';
|
|
5
|
+
import { Pixel } from 'ol/pixel';
|
|
6
|
+
import CanvasLayerRenderer from 'ol/renderer/canvas/Layer';
|
|
7
|
+
import { FeatureCallback } from 'ol/renderer/vector';
|
|
8
|
+
import type RealtimeLayer from '../layers/RealtimeLayer';
|
|
9
|
+
/**
|
|
10
|
+
* This class is a renderer for Maplibre Layer to be able to use the native ol
|
|
11
|
+
* functionnalities like map.getFeaturesAtPixel or map.hasFeatureAtPixel.
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
export default class RealtimeLayerRenderer extends CanvasLayerRenderer<RealtimeLayer> {
|
|
15
|
+
private canvas;
|
|
16
|
+
forEachFeatureAtCoordinate<Feature>(coordinate: Coordinate, frameState: FrameState, hitTolerance: number, callback: FeatureCallback<Feature>): Feature | undefined;
|
|
17
|
+
getData(pixel: Pixel): Uint8ClampedArray | null;
|
|
18
|
+
getFeatures(pixel: Pixel): Promise<Feature<Geometry>[]>;
|
|
19
|
+
getFeaturesAtCoordinate(coordinate: Coordinate | undefined, hitTolerance?: number): Feature<Geometry>[];
|
|
20
|
+
prepareFrame(): boolean;
|
|
21
|
+
renderFrame(frameState: FrameState): HTMLElement;
|
|
22
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import GeoJSON from 'ol/format/GeoJSON';
|
|
2
|
-
import { composeCssTransform } from 'ol/transform';
|
|
3
1
|
import { buffer, containsCoordinate } from 'ol/extent';
|
|
2
|
+
import GeoJSON from 'ol/format/GeoJSON';
|
|
4
3
|
import CanvasLayerRenderer from 'ol/renderer/canvas/Layer';
|
|
4
|
+
import { composeCssTransform } from 'ol/transform';
|
|
5
5
|
/** @private */
|
|
6
6
|
const format = new GeoJSON();
|
|
7
7
|
/**
|
|
@@ -9,47 +9,15 @@ const format = new GeoJSON();
|
|
|
9
9
|
* functionnalities like map.getFeaturesAtPixel or map.hasFeatureAtPixel.
|
|
10
10
|
* @private
|
|
11
11
|
*/
|
|
12
|
-
// @ts-
|
|
12
|
+
// @ts-expect-error
|
|
13
13
|
export default class RealtimeLayerRenderer extends CanvasLayerRenderer {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (!this.container) {
|
|
22
|
-
this.container = document.createElement('div');
|
|
23
|
-
this.container.className = this.getLayer().getClassName();
|
|
24
|
-
this.container.style.position = 'absolute';
|
|
25
|
-
this.container.style.width = '100%';
|
|
26
|
-
this.container.style.height = '100%';
|
|
27
|
-
if (canvas) {
|
|
28
|
-
canvas.style.position = 'absolute';
|
|
29
|
-
canvas.style.top = '0';
|
|
30
|
-
canvas.style.left = '0';
|
|
31
|
-
canvas.style.transformOrigin = 'top left';
|
|
32
|
-
this.container.appendChild(canvas);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (renderedViewState) {
|
|
36
|
-
const { center, resolution, rotation } = frameState.viewState;
|
|
37
|
-
const { center: renderedCenter, resolution: renderedResolution, rotation: renderedRotation, } = renderedViewState;
|
|
38
|
-
if (renderedResolution / resolution >= 3) {
|
|
39
|
-
// Avoid having really big points when zooming fast.
|
|
40
|
-
const context = canvas === null || canvas === void 0 ? void 0 : canvas.getContext('2d');
|
|
41
|
-
context === null || context === void 0 ? void 0 : context.clearRect(0, 0, canvas === null || canvas === void 0 ? void 0 : canvas.width, canvas === null || canvas === void 0 ? void 0 : canvas.height);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
const pixelCenterRendered = (_a = this.getLayer()
|
|
45
|
-
.getMapInternal()) === null || _a === void 0 ? void 0 : _a.getPixelFromCoordinate(renderedCenter);
|
|
46
|
-
const pixelCenter = this.getLayer()
|
|
47
|
-
.getMapInternal()
|
|
48
|
-
.getPixelFromCoordinate(center);
|
|
49
|
-
this.container.style.transform = composeCssTransform(pixelCenterRendered[0] - pixelCenter[0], pixelCenterRendered[1] - pixelCenter[1], renderedResolution / resolution, renderedResolution / resolution, rotation - renderedRotation, 0, 0);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return this.container;
|
|
14
|
+
forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback) {
|
|
15
|
+
const features = this.getFeaturesAtCoordinate(coordinate, hitTolerance);
|
|
16
|
+
features.forEach((feature) => {
|
|
17
|
+
// @ts-expect-error
|
|
18
|
+
callback(feature, this.layer_, feature.getGeometry());
|
|
19
|
+
});
|
|
20
|
+
return features === null || features === void 0 ? void 0 : features[0];
|
|
53
21
|
}
|
|
54
22
|
getData(pixel) {
|
|
55
23
|
var _a;
|
|
@@ -74,33 +42,29 @@ export default class RealtimeLayerRenderer extends CanvasLayerRenderer {
|
|
|
74
42
|
const coordinate = (_b = (_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.getMapInternal()) === null || _b === void 0 ? void 0 : _b.getCoordinateFromPixel(pixel);
|
|
75
43
|
return Promise.resolve(this.getFeaturesAtCoordinate(coordinate));
|
|
76
44
|
}
|
|
77
|
-
forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback) {
|
|
78
|
-
const features = this.getFeaturesAtCoordinate(coordinate, hitTolerance);
|
|
79
|
-
features.forEach((feature) => {
|
|
80
|
-
// @ts-ignore
|
|
81
|
-
callback(feature, this.layer_, feature.getGeometry());
|
|
82
|
-
});
|
|
83
|
-
return features === null || features === void 0 ? void 0 : features[0];
|
|
84
|
-
}
|
|
85
45
|
getFeaturesAtCoordinate(coordinate, hitTolerance = 5) {
|
|
46
|
+
var _a;
|
|
86
47
|
if (!coordinate) {
|
|
87
48
|
return [];
|
|
88
49
|
}
|
|
89
50
|
const layer = this.getLayer();
|
|
90
51
|
const map = layer.getMapInternal();
|
|
91
|
-
const resolution = map.getView().getResolution();
|
|
52
|
+
const resolution = ((_a = map === null || map === void 0 ? void 0 : map.getView()) === null || _a === void 0 ? void 0 : _a.getResolution()) || 1;
|
|
92
53
|
const nb = 10;
|
|
93
54
|
const ext = buffer([...coordinate, ...coordinate], hitTolerance * resolution);
|
|
94
55
|
let features = [];
|
|
95
56
|
let trajectories = Object.values(layer.trajectories || {});
|
|
96
57
|
if (layer.sort) {
|
|
97
|
-
// @ts-
|
|
58
|
+
// @ts-expect-error
|
|
98
59
|
trajectories = trajectories.sort(this.sort);
|
|
99
60
|
}
|
|
100
61
|
const vehicles = [];
|
|
101
62
|
for (let i = 0; i < trajectories.length; i += 1) {
|
|
102
63
|
const trajectory = trajectories[i];
|
|
103
|
-
if (
|
|
64
|
+
if (
|
|
65
|
+
// @ts-expect-error coordinate is added by the RealtimeLayer
|
|
66
|
+
trajectory.properties.coordinate &&
|
|
67
|
+
// @ts-expect-error coordinate is added by the RealtimeLayer
|
|
104
68
|
containsCoordinate(ext, trajectory.properties.coordinate)) {
|
|
105
69
|
vehicles.push(trajectories[i]);
|
|
106
70
|
}
|
|
@@ -111,4 +75,45 @@ export default class RealtimeLayerRenderer extends CanvasLayerRenderer {
|
|
|
111
75
|
features = vehicles.map((vehicle) => format.readFeature(vehicle));
|
|
112
76
|
return features;
|
|
113
77
|
}
|
|
78
|
+
// eslint-disable-next-line class-methods-use-this
|
|
79
|
+
prepareFrame() {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
renderFrame(frameState) {
|
|
83
|
+
const { canvas, renderedViewState } = this.getLayer();
|
|
84
|
+
if (!this.container) {
|
|
85
|
+
this.container = document.createElement('div');
|
|
86
|
+
this.container.className = this.getLayer().getClassName();
|
|
87
|
+
this.container.style.position = 'absolute';
|
|
88
|
+
this.container.style.width = '100%';
|
|
89
|
+
this.container.style.height = '100%';
|
|
90
|
+
if (canvas instanceof HTMLCanvasElement) {
|
|
91
|
+
canvas.style.position = 'absolute';
|
|
92
|
+
canvas.style.top = '0';
|
|
93
|
+
canvas.style.left = '0';
|
|
94
|
+
canvas.style.transformOrigin = 'top left';
|
|
95
|
+
this.container.appendChild(canvas);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (renderedViewState) {
|
|
99
|
+
const { center, resolution, rotation } = frameState.viewState;
|
|
100
|
+
const { center: renderedCenter, resolution: renderedResolution, rotation: renderedRotation, } = renderedViewState;
|
|
101
|
+
if (renderedResolution / resolution >= 3) {
|
|
102
|
+
// Avoid having really big points when zooming fast.
|
|
103
|
+
const context = canvas === null || canvas === void 0 ? void 0 : canvas.getContext('2d');
|
|
104
|
+
if ((canvas === null || canvas === void 0 ? void 0 : canvas.width) && (canvas === null || canvas === void 0 ? void 0 : canvas.height)) {
|
|
105
|
+
context === null || context === void 0 ? void 0 : context.clearRect(0, 0, canvas.width, canvas.height);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const map = this.getLayer().getMapInternal();
|
|
110
|
+
const pixelCenterRendered = map === null || map === void 0 ? void 0 : map.getPixelFromCoordinate(renderedCenter);
|
|
111
|
+
const pixelCenter = map === null || map === void 0 ? void 0 : map.getPixelFromCoordinate(center);
|
|
112
|
+
if (pixelCenterRendered && pixelCenter) {
|
|
113
|
+
this.container.style.transform = composeCssTransform(pixelCenterRendered[0] - pixelCenter[0], pixelCenterRendered[1] - pixelCenter[1], renderedResolution / resolution, renderedResolution / resolution, rotation - renderedRotation, 0, 0);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return this.container;
|
|
118
|
+
}
|
|
114
119
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LayerGetFeatureInfoResponse } from '../../types';
|
|
2
|
+
import type { Coordinate } from 'ol/coordinate';
|
|
3
|
+
import type { Layer } from 'ol/layer';
|
|
4
|
+
/**
|
|
5
|
+
* @private
|
|
6
|
+
*/
|
|
7
|
+
declare const getFeatureInfoAtCoordinate: (coordinate: Coordinate, layers: Layer[], hitTolerance?: number) => Promise<LayerGetFeatureInfoResponse[]>;
|
|
8
|
+
export default getFeatureInfoAtCoordinate;
|