mobility-toolbox-js 3.0.0-beta.8 → 3.0.0
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.d.ts +20 -0
- package/api/HttpAPI.js +1 -14
- package/api/RealtimeAPI.d.ts +404 -0
- package/api/RealtimeAPI.js +265 -206
- package/api/RoutingAPI.d.ts +47 -0
- package/api/RoutingAPI.js +17 -7
- package/api/StopsAPI.d.ts +44 -0
- package/api/StopsAPI.js +17 -11
- package/api/WebSocketAPI.d.ts +147 -0
- package/api/WebSocketAPI.js +164 -165
- 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 +32 -32
- package/common/index.d.ts +2 -0
- package/common/index.js +1 -1
- package/common/styles/index.d.ts +4 -0
- package/common/styles/realtimeDefaultStyle.d.ts +36 -0
- package/common/styles/realtimeDefaultStyle.js +6 -11
- package/common/styles/realtimeDelayStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.js +5 -10
- package/common/styles/realtimeSimpleStyle.d.ts +3 -0
- package/common/styles/realtimeSimpleStyle.js +0 -1
- package/common/typedefs.d.ts +102 -0
- package/common/typedefs.js +6 -31
- package/common/utils/RealtimeEngine.d.ts +214 -0
- package/common/utils/RealtimeEngine.js +554 -0
- 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 +2 -0
- package/common/utils/getLayersAsFlatArray.js +0 -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 +6 -3
- package/common/utils/index.d.ts +16 -0
- package/common/utils/realtimeConfig.d.ts +64 -0
- package/common/utils/realtimeConfig.js +0 -1
- package/common/utils/removeDuplicate.d.ts +9 -0
- package/common/utils/renderTrajectories.d.ts +17 -0
- package/common/utils/renderTrajectories.js +7 -6
- package/common/utils/sortAndFilterDepartures.d.ts +16 -0
- package/common/utils/sortAndFilterDepartures.js +2 -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 +38 -0
- package/maplibre/controls/CopyrightControl.js +11 -8
- package/maplibre/controls/index.d.ts +1 -0
- package/maplibre/index.d.ts +5 -0
- package/maplibre/layers/Layer.d.ts +29 -0
- package/maplibre/layers/Layer.js +2 -3
- package/maplibre/layers/RealtimeLayer.d.ts +124 -0
- package/maplibre/layers/RealtimeLayer.js +154 -118
- package/maplibre/layers/index.d.ts +2 -0
- package/maplibre/utils/getMercatorResolution.d.ts +7 -0
- package/maplibre/utils/getSourceCoordinates.d.ts +8 -0
- package/maplibre/utils/getSourceCoordinates.js +6 -5
- package/maplibre/utils/index.d.ts +2 -0
- package/mbt.js +14585 -14557
- package/mbt.js.map +4 -4
- package/mbt.min.js +75 -75
- package/mbt.min.js.map +4 -4
- package/ol/controls/CopyrightControl.d.ts +39 -0
- package/ol/controls/CopyrightControl.js +13 -5
- package/ol/controls/RoutingControl.d.ts +213 -0
- package/ol/controls/RoutingControl.js +250 -264
- package/ol/controls/StopFinderControl.d.ts +56 -0
- package/ol/controls/StopFinderControl.js +24 -5
- package/ol/controls/index.d.ts +3 -0
- package/ol/index.d.ts +6 -0
- package/ol/layers/Layer.d.ts +26 -0
- package/ol/layers/Layer.js +39 -0
- package/ol/layers/MaplibreLayer.d.ts +91 -0
- package/ol/layers/MaplibreLayer.js +154 -31
- package/ol/layers/MaplibreStyleLayer.d.ts +157 -0
- package/ol/layers/MaplibreStyleLayer.js +281 -210
- package/ol/layers/RealtimeLayer.d.ts +150 -0
- package/ol/layers/RealtimeLayer.js +210 -206
- package/ol/layers/VectorLayer.d.ts +17 -0
- package/ol/layers/VectorLayer.js +33 -0
- package/ol/layers/index.d.ts +5 -0
- package/ol/layers/index.js +3 -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 +50 -70
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
- package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryStyle.js +5 -7
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/routingStyle.d.ts +3 -0
- package/ol/styles/routingStyle.js +13 -10
- package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
- package/ol/utils/defineDeprecatedProperties.js +180 -0
- package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
- package/ol/utils/getFeatureInfoAtCoordinate.js +11 -17
- package/ol/utils/index.d.ts +1 -0
- package/package.json +44 -44
- package/setupTests.d.ts +1 -0
- package/setupTests.js +17 -4
- package/types/common.d.ts +53 -69
- package/types/index.d.ts +1 -1
- package/types/realtime.d.ts +98 -95
- package/types/routing.d.ts +60 -60
- package/types/stops.d.ts +62 -62
- package/common/mixins/RealtimeLayerMixin.js +0 -743
- package/ol/layers/MapGlLayer.js +0 -142
- package/ol/mixins/MobilityLayerMixin.js +0 -9
- package/ol/mixins/PropertiesLayerMixin.js +0 -142
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Coordinate } from 'ol/coordinate';
|
|
2
|
+
import { LayerGetFeatureInfoResponse } from '../../types';
|
|
3
|
+
import Layer, { MobilityLayerOptions } from './Layer';
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated
|
|
6
|
+
*/
|
|
7
|
+
declare class VectorLayer extends Layer {
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated
|
|
10
|
+
*/
|
|
11
|
+
clone(newOptions: MobilityLayerOptions): VectorLayer;
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated
|
|
14
|
+
*/
|
|
15
|
+
getFeatureInfoAtCoordinate(coordinate: Coordinate): Promise<LayerGetFeatureInfoResponse>;
|
|
16
|
+
}
|
|
17
|
+
export default VectorLayer;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Layer from './Layer';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated
|
|
4
|
+
*/
|
|
5
|
+
class VectorLayer extends Layer {
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated
|
|
8
|
+
*/
|
|
9
|
+
clone(newOptions) {
|
|
10
|
+
return new VectorLayer(Object.assign(Object.assign({}, this.get('options')), newOptions));
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated
|
|
14
|
+
*/
|
|
15
|
+
getFeatureInfoAtCoordinate(coordinate) {
|
|
16
|
+
let features = [];
|
|
17
|
+
const mapInternal = this.getMapInternal();
|
|
18
|
+
if (mapInternal) {
|
|
19
|
+
const pixel = mapInternal.getPixelFromCoordinate(coordinate);
|
|
20
|
+
features =
|
|
21
|
+
mapInternal.getFeaturesAtPixel(pixel, {
|
|
22
|
+
hitTolerance: this.get('hitTolerance') || 5,
|
|
23
|
+
layerFilter: (l) => l === this,
|
|
24
|
+
}) || [];
|
|
25
|
+
}
|
|
26
|
+
return Promise.resolve({
|
|
27
|
+
coordinate,
|
|
28
|
+
features,
|
|
29
|
+
layer: this,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export default VectorLayer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as MaplibreLayer } from "./MaplibreLayer";
|
|
2
|
+
export { default as MaplibreStyleLayer } from "./MaplibreStyleLayer";
|
|
3
|
+
export { default as RealtimeLayer } from "./RealtimeLayer";
|
|
4
|
+
export { default as Layer } from "./Layer";
|
|
5
|
+
export { default as VectorLayer } from "./VectorLayer";
|
package/ol/layers/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export { default as MaplibreLayer } from './MaplibreLayer';
|
|
2
2
|
export { default as MaplibreStyleLayer } from './MaplibreStyleLayer';
|
|
3
3
|
export { default as RealtimeLayer } from './RealtimeLayer';
|
|
4
|
+
// Deprecated export
|
|
5
|
+
export { default as Layer } from './Layer';
|
|
6
|
+
export { default as VectorLayer } from './VectorLayer';
|
|
File without changes
|
|
@@ -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 improve ts types
|
|
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.mapLibreMap;
|
|
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<ArrayBufferLike> | 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,55 +1,20 @@
|
|
|
1
1
|
import GeoJSON from 'ol/format/GeoJSON';
|
|
2
|
-
import { composeCssTransform } from 'ol/transform';
|
|
3
|
-
import { buffer, containsCoordinate } from 'ol/extent';
|
|
4
2
|
import CanvasLayerRenderer from 'ol/renderer/canvas/Layer';
|
|
5
|
-
|
|
3
|
+
import { composeCssTransform } from 'ol/transform';
|
|
6
4
|
const format = new GeoJSON();
|
|
7
5
|
/**
|
|
8
6
|
* This class is a renderer for Maplibre Layer to be able to use the native ol
|
|
9
7
|
* functionnalities like map.getFeaturesAtPixel or map.hasFeatureAtPixel.
|
|
10
8
|
* @private
|
|
11
9
|
*/
|
|
12
|
-
// @ts-ignore
|
|
13
10
|
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;
|
|
11
|
+
forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback) {
|
|
12
|
+
const features = this.getFeaturesAtCoordinate(coordinate, hitTolerance);
|
|
13
|
+
features.forEach((feature) => {
|
|
14
|
+
// @ts-expect-error defintion to fix
|
|
15
|
+
callback(feature, this.layer_, feature.getGeometry());
|
|
16
|
+
});
|
|
17
|
+
return features === null || features === void 0 ? void 0 : features[0];
|
|
53
18
|
}
|
|
54
19
|
getData(pixel) {
|
|
55
20
|
var _a;
|
|
@@ -74,41 +39,56 @@ export default class RealtimeLayerRenderer extends CanvasLayerRenderer {
|
|
|
74
39
|
const coordinate = (_b = (_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.getMapInternal()) === null || _b === void 0 ? void 0 : _b.getCoordinateFromPixel(pixel);
|
|
75
40
|
return Promise.resolve(this.getFeaturesAtCoordinate(coordinate));
|
|
76
41
|
}
|
|
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
42
|
getFeaturesAtCoordinate(coordinate, hitTolerance = 5) {
|
|
86
43
|
if (!coordinate) {
|
|
87
44
|
return [];
|
|
88
45
|
}
|
|
89
46
|
const layer = this.getLayer();
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
47
|
+
const featureCollection = layer.engine.getVehiclesAtCoordinate(coordinate, {
|
|
48
|
+
hitTolerance,
|
|
49
|
+
nb: layer.maxNbFeaturesRequested,
|
|
50
|
+
});
|
|
51
|
+
return format.readFeatures(featureCollection);
|
|
52
|
+
}
|
|
53
|
+
// eslint-disable-next-line class-methods-use-this
|
|
54
|
+
prepareFrame() {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
renderFrame(frameState) {
|
|
58
|
+
const { canvas, renderedViewState } = this.getLayer();
|
|
59
|
+
if (!this.container) {
|
|
60
|
+
this.container = document.createElement('div');
|
|
61
|
+
this.container.className = this.getLayer().getClassName();
|
|
62
|
+
this.container.style.position = 'absolute';
|
|
63
|
+
this.container.style.width = '100%';
|
|
64
|
+
this.container.style.height = '100%';
|
|
65
|
+
if (canvas instanceof HTMLCanvasElement) {
|
|
66
|
+
canvas.style.position = 'absolute';
|
|
67
|
+
canvas.style.top = '0';
|
|
68
|
+
canvas.style.left = '0';
|
|
69
|
+
canvas.style.transformOrigin = 'top left';
|
|
70
|
+
this.container.appendChild(canvas);
|
|
71
|
+
}
|
|
99
72
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
|
|
73
|
+
if (renderedViewState) {
|
|
74
|
+
const { center, resolution, rotation } = frameState.viewState;
|
|
75
|
+
const { center: renderedCenter, resolution: renderedResolution, rotation: renderedRotation, } = renderedViewState;
|
|
76
|
+
if (renderedResolution / resolution >= 3) {
|
|
77
|
+
// Avoid having really big points when zooming fast.
|
|
78
|
+
const context = canvas === null || canvas === void 0 ? void 0 : canvas.getContext('2d');
|
|
79
|
+
if ((canvas === null || canvas === void 0 ? void 0 : canvas.width) && (canvas === null || canvas === void 0 ? void 0 : canvas.height)) {
|
|
80
|
+
context === null || context === void 0 ? void 0 : context.clearRect(0, 0, canvas.width, canvas.height);
|
|
81
|
+
}
|
|
106
82
|
}
|
|
107
|
-
|
|
108
|
-
|
|
83
|
+
else {
|
|
84
|
+
const map = this.getLayer().getMapInternal();
|
|
85
|
+
const pixelCenterRendered = map === null || map === void 0 ? void 0 : map.getPixelFromCoordinate(renderedCenter);
|
|
86
|
+
const pixelCenter = map === null || map === void 0 ? void 0 : map.getPixelFromCoordinate(center);
|
|
87
|
+
if (pixelCenterRendered && pixelCenter) {
|
|
88
|
+
this.container.style.transform = composeCssTransform(pixelCenterRendered[0] - pixelCenter[0], pixelCenterRendered[1] - pixelCenter[1], renderedResolution / resolution, renderedResolution / resolution, rotation - renderedRotation, 0, 0);
|
|
89
|
+
}
|
|
109
90
|
}
|
|
110
91
|
}
|
|
111
|
-
|
|
112
|
-
return features;
|
|
92
|
+
return this.container;
|
|
113
93
|
}
|
|
114
94
|
}
|