mobility-toolbox-js 3.0.0-beta.9 → 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.
Files changed (105) hide show
  1. package/README.md +11 -3
  2. package/api/HttpAPI.d.ts +5 -16
  3. package/api/HttpAPI.js +1 -14
  4. package/api/RealtimeAPI.d.ts +188 -143
  5. package/api/RealtimeAPI.js +265 -206
  6. package/api/RoutingAPI.d.ts +21 -11
  7. package/api/RoutingAPI.js +17 -7
  8. package/api/StopsAPI.d.ts +20 -14
  9. package/api/StopsAPI.js +17 -11
  10. package/api/WebSocketAPI.d.ts +60 -66
  11. package/api/WebSocketAPI.js +164 -165
  12. package/api/index.js +1 -1
  13. package/api/typedefs.d.ts +0 -102
  14. package/api/typedefs.js +27 -42
  15. package/common/controls/StopFinderControlCommon.d.ts +13 -13
  16. package/common/controls/StopFinderControlCommon.js +32 -32
  17. package/common/index.d.ts +1 -1
  18. package/common/index.js +1 -1
  19. package/common/styles/realtimeDefaultStyle.js +6 -11
  20. package/common/styles/realtimeHeadingStyle.js +5 -10
  21. package/common/styles/realtimeSimpleStyle.d.ts +0 -1
  22. package/common/styles/realtimeSimpleStyle.js +0 -1
  23. package/common/typedefs.d.ts +11 -121
  24. package/common/typedefs.js +6 -31
  25. package/common/utils/RealtimeEngine.d.ts +214 -0
  26. package/common/utils/RealtimeEngine.js +554 -0
  27. package/common/utils/compareDepartures.d.ts +2 -2
  28. package/common/utils/compareDepartures.js +2 -2
  29. package/common/utils/debounceWebsocketMessages.d.ts +1 -1
  30. package/common/utils/getLayersAsFlatArray.d.ts +0 -1
  31. package/common/utils/getLayersAsFlatArray.js +0 -1
  32. package/common/utils/getMapGlCopyrights.d.ts +1 -1
  33. package/common/utils/getMapGlCopyrights.js +3 -3
  34. package/common/utils/getRealtimeModeSuffix.d.ts +1 -0
  35. package/common/utils/getRealtimeModeSuffix.js +1 -0
  36. package/common/utils/getVehiclePosition.d.ts +5 -4
  37. package/common/utils/getVehiclePosition.js +6 -3
  38. package/common/utils/realtimeConfig.d.ts +1 -1
  39. package/common/utils/realtimeConfig.js +0 -1
  40. package/common/utils/renderTrajectories.d.ts +2 -1
  41. package/common/utils/renderTrajectories.js +7 -6
  42. package/common/utils/sortAndFilterDepartures.d.ts +2 -1
  43. package/common/utils/sortAndFilterDepartures.js +2 -1
  44. package/common/utils/sortByDelay.d.ts +2 -2
  45. package/common/utils/sortByDelay.js +5 -1
  46. package/maplibre/controls/CopyrightControl.d.ts +9 -6
  47. package/maplibre/controls/CopyrightControl.js +11 -8
  48. package/maplibre/layers/Layer.d.ts +8 -7
  49. package/maplibre/layers/Layer.js +2 -3
  50. package/maplibre/layers/RealtimeLayer.d.ts +82 -118
  51. package/maplibre/layers/RealtimeLayer.js +154 -118
  52. package/maplibre/utils/getSourceCoordinates.d.ts +1 -0
  53. package/maplibre/utils/getSourceCoordinates.js +6 -5
  54. package/mbt.js +14611 -14591
  55. package/mbt.js.map +4 -4
  56. package/mbt.min.js +75 -75
  57. package/mbt.min.js.map +4 -4
  58. package/ol/controls/CopyrightControl.d.ts +13 -5
  59. package/ol/controls/CopyrightControl.js +13 -5
  60. package/ol/controls/RoutingControl.d.ts +105 -101
  61. package/ol/controls/RoutingControl.js +250 -264
  62. package/ol/controls/StopFinderControl.d.ts +24 -5
  63. package/ol/controls/StopFinderControl.js +24 -5
  64. package/ol/layers/Layer.d.ts +26 -0
  65. package/ol/layers/Layer.js +39 -0
  66. package/ol/layers/MaplibreLayer.d.ts +56 -28
  67. package/ol/layers/MaplibreLayer.js +154 -31
  68. package/ol/layers/MaplibreStyleLayer.d.ts +71 -149
  69. package/ol/layers/MaplibreStyleLayer.js +281 -210
  70. package/ol/layers/RealtimeLayer.d.ts +95 -230
  71. package/ol/layers/RealtimeLayer.js +209 -211
  72. package/ol/layers/VectorLayer.d.ts +17 -0
  73. package/ol/layers/VectorLayer.js +33 -0
  74. package/ol/layers/index.d.ts +2 -0
  75. package/ol/layers/index.js +3 -0
  76. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -20
  77. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  78. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +6 -6
  79. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  80. package/ol/renderers/RealtimeLayerRenderer.d.ts +7 -7
  81. package/ol/renderers/RealtimeLayerRenderer.js +46 -66
  82. package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
  83. package/ol/styles/fullTrajectoryStyle.d.ts +1 -2
  84. package/ol/styles/fullTrajectoryStyle.js +5 -7
  85. package/ol/styles/routingStyle.d.ts +0 -1
  86. package/ol/styles/routingStyle.js +13 -10
  87. package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
  88. package/ol/utils/defineDeprecatedProperties.js +180 -0
  89. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +1 -1
  90. package/ol/utils/getFeatureInfoAtCoordinate.js +11 -17
  91. package/package.json +44 -44
  92. package/setupTests.js +17 -4
  93. package/types/common.d.ts +53 -69
  94. package/types/index.d.ts +1 -1
  95. package/types/realtime.d.ts +98 -95
  96. package/types/routing.d.ts +60 -60
  97. package/types/stops.d.ts +62 -62
  98. package/common/mixins/RealtimeLayerMixin.d.ts +0 -273
  99. package/common/mixins/RealtimeLayerMixin.js +0 -743
  100. package/ol/layers/MapGlLayer.d.ts +0 -144
  101. package/ol/layers/MapGlLayer.js +0 -144
  102. package/ol/mixins/MobilityLayerMixin.d.ts +0 -98
  103. package/ol/mixins/MobilityLayerMixin.js +0 -6
  104. package/ol/mixins/PropertiesLayerMixin.d.ts +0 -127
  105. package/ol/mixins/PropertiesLayerMixin.js +0 -143
@@ -1,114 +1,142 @@
1
- import { toDegrees } from 'ol/math';
2
- import { toLonLat } from 'ol/proj';
3
- import LayerRenderer from 'ol/renderer/Layer';
4
- import GeoJSON from 'ol/format/GeoJSON';
5
- import { VECTOR_TILE_FEATURE_PROPERTY } from '../../common';
6
- /**
7
- * @private
8
- */
9
- const formats = {
10
- 'EPSG:3857': new GeoJSON({
11
- featureProjection: 'EPSG:3857',
12
- }),
13
- };
14
- /**
15
- * This class is a renderer for Maplibre Layer to be able to use the native ol
16
- * functionnalities like map.getFeaturesAtPixel or map.hasFeatureAtPixel.
17
- * @private
18
- */
19
- // @ts-ignore
20
- export default class MaplibreLayerRenderer extends LayerRenderer {
21
- getFeaturesAtCoordinate(coordinate, hitTolerance = 5) {
22
- var _a, _b;
23
- if (!coordinate) {
24
- return [];
25
- }
26
- const layer = this.getLayer();
27
- const map = layer.getMapInternal();
28
- const { mbMap } = layer;
29
- 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';
30
- let features = [];
31
- if (!formats[projection]) {
32
- formats[projection] = new GeoJSON({
33
- featureProjection: projection,
34
- });
35
- }
36
- if (mbMap === null || mbMap === void 0 ? void 0 : mbMap.isStyleLoaded()) {
37
- const pixel = coordinate && mbMap.project(toLonLat(coordinate));
38
- if ((pixel === null || pixel === void 0 ? void 0 : pixel.x) && (pixel === null || pixel === void 0 ? void 0 : pixel.y)) {
39
- let pixels = [
40
- pixel.x,
41
- pixel.y,
42
- ];
43
- if (hitTolerance) {
44
- const [x, y] = pixels;
45
- pixels = [
46
- [x - hitTolerance, y - hitTolerance],
47
- [x + hitTolerance, y + hitTolerance],
48
- ];
49
- }
50
- // At this point we get GeoJSON Maplibre feature, we transform it to an OpenLayers
51
- // feature to be consistent with other layers.
52
- features = mbMap
53
- .queryRenderedFeatures(pixels, layer.queryRenderedFeaturesOptions || {})
54
- .map((feature) => {
55
- const olFeature = formats[projection].readFeature(feature);
56
- if (olFeature) {
57
- // We save the original Maplibre feature to avoid losing informations
58
- // potentially needed for other functionnality like highlighting
59
- // (id, layer id, source, sourceLayer ...)
60
- // @ts-ignore
61
- olFeature.set(VECTOR_TILE_FEATURE_PROPERTY, feature);
62
- }
63
- return olFeature;
64
- });
65
- }
66
- }
67
- return features;
68
- }
69
- // eslint-disable-next-line class-methods-use-this
70
- prepareFrame() {
71
- return true;
72
- }
73
- renderFrame(frameState) {
74
- const layer = this.getLayer();
75
- const { map, mbMap } = layer;
76
- if (!layer || !map || !mbMap) {
77
- return null;
78
- }
79
- const canvas = mbMap.getCanvas();
80
- const { viewState } = frameState;
81
- const opacity = layer.getOpacity() || 1;
82
- canvas.style.opacity = `${opacity}`;
83
- // adjust view parameters in Maplibre
84
- mbMap.jumpTo({
85
- center: toLonLat(viewState.center),
86
- zoom: viewState.zoom - 1,
87
- bearing: toDegrees(-viewState.rotation),
88
- });
89
- if (!canvas.isConnected) {
90
- // The canvas is not connected to the DOM, request a map rendering at the next animation frame
91
- // to set the canvas size.
92
- map.render();
93
- }
94
- else if (canvas.width !== frameState.size[0] ||
95
- canvas.height !== frameState.size[1]) {
96
- mbMap.resize();
97
- }
98
- mbMap.redraw();
99
- return mbMap.getContainer();
100
- }
101
- getFeatures(pixel) {
102
- var _a, _b;
103
- const coordinate = (_b = (_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.getMapInternal()) === null || _b === void 0 ? void 0 : _b.getCoordinateFromPixel(pixel);
104
- return Promise.resolve(this.getFeaturesAtCoordinate(coordinate));
105
- }
106
- forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback) {
107
- const features = this.getFeaturesAtCoordinate(coordinate, hitTolerance);
108
- features.forEach((feature) => {
109
- // @ts-ignore
110
- callback(feature, this.layer_, feature.getGeometry());
111
- });
112
- return features === null || features === void 0 ? void 0 : features[0];
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
+ // }
@@ -1,10 +1,10 @@
1
- import { FrameState } from 'ol/Map';
2
- import LayerRenderer from 'ol/renderer/Layer';
3
- import { Coordinate } from 'ol/coordinate';
4
- import { FeatureCallback } from 'ol/renderer/vector';
5
1
  import { Feature } from 'ol';
2
+ import { Coordinate } from 'ol/coordinate';
6
3
  import { Geometry } from 'ol/geom';
4
+ import { FrameState } from 'ol/Map';
7
5
  import { Pixel } from 'ol/pixel';
6
+ import LayerRenderer from 'ol/renderer/Layer';
7
+ import { FeatureCallback } from 'ol/renderer/vector';
8
8
  import type { MaplibreStyleLayer } from '../layers';
9
9
  /**
10
10
  * This class is a renderer for Maplibre Layer to be able to use the native ol
@@ -12,9 +12,9 @@ import type { MaplibreStyleLayer } from '../layers';
12
12
  * @private
13
13
  */
14
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>[]>;
15
17
  getFeaturesAtCoordinate(coordinate: Coordinate | undefined, hitTolerance?: number): Feature<Geometry>[];
16
18
  prepareFrame(): boolean;
17
19
  renderFrame(): null;
18
- getFeatures(pixel: Pixel): Promise<Feature<Geometry>[]>;
19
- forEachFeatureAtCoordinate<Feature>(coordinate: Coordinate, frameState: FrameState, hitTolerance: number, callback: FeatureCallback<Feature>): Feature | undefined;
20
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 { maplibreMap } = layer.maplibreLayer;
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 (maplibreMap === null || maplibreMap === void 0 ? void 0 : maplibreMap.isStyleLoaded()) {
47
+ if (mapLibreMap === null || mapLibreMap === void 0 ? void 0 : mapLibreMap.isStyleLoaded()) {
36
48
  const pixel = coordinate &&
37
- maplibreMap.project(toLonLat(coordinate));
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 = maplibreMap.getStyle().layers.filter(layer.layersFilter);
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 = maplibreMap
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 = maplibreMap
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
  }
@@ -1,10 +1,10 @@
1
- import { FrameState } from 'ol/Map';
2
- import { Coordinate } from 'ol/coordinate';
3
- import { FeatureCallback } from 'ol/renderer/vector';
4
1
  import { Feature } from 'ol';
2
+ import { Coordinate } from 'ol/coordinate';
5
3
  import { Geometry } from 'ol/geom';
4
+ import { FrameState } from 'ol/Map';
6
5
  import { Pixel } from 'ol/pixel';
7
6
  import CanvasLayerRenderer from 'ol/renderer/canvas/Layer';
7
+ import { FeatureCallback } from 'ol/renderer/vector';
8
8
  import type RealtimeLayer from '../layers/RealtimeLayer';
9
9
  /**
10
10
  * This class is a renderer for Maplibre Layer to be able to use the native ol
@@ -13,10 +13,10 @@ import type RealtimeLayer from '../layers/RealtimeLayer';
13
13
  */
14
14
  export default class RealtimeLayerRenderer extends CanvasLayerRenderer<RealtimeLayer> {
15
15
  private canvas;
16
- prepareFrame(): boolean;
17
- renderFrame(frameState: FrameState): HTMLElement;
18
- getData(pixel: Pixel): Uint8ClampedArray | null;
19
- getFeatures(pixel: Pixel): Promise<Feature<Geometry>[]>;
20
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>[]>;
21
19
  getFeaturesAtCoordinate(coordinate: Coordinate | undefined, hitTolerance?: number): Feature<Geometry>[];
20
+ prepareFrame(): boolean;
21
+ renderFrame(frameState: FrameState): HTMLElement;
22
22
  }
@@ -1,16 +1,55 @@
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
- /** @private */
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 {
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];
18
+ }
19
+ getData(pixel) {
20
+ var _a;
21
+ let data;
22
+ try {
23
+ const { pixelRatio } = this.getLayer();
24
+ const context = (_a = this.canvas) === null || _a === void 0 ? void 0 : _a.getContext('2d', {
25
+ willReadFrequently: true,
26
+ });
27
+ data =
28
+ (context === null || context === void 0 ? void 0 : context.getImageData(pixel[0] * (pixelRatio || 1), pixel[1] * (pixelRatio || 1), 1, 1).data) || null; // [3];
29
+ return data;
30
+ }
31
+ catch (err) {
32
+ // eslint-disable-next-line no-console
33
+ console.error('error getting data', err);
34
+ }
35
+ return null;
36
+ }
37
+ getFeatures(pixel) {
38
+ var _a, _b;
39
+ const coordinate = (_b = (_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.getMapInternal()) === null || _b === void 0 ? void 0 : _b.getCoordinateFromPixel(pixel);
40
+ return Promise.resolve(this.getFeaturesAtCoordinate(coordinate));
41
+ }
42
+ getFeaturesAtCoordinate(coordinate, hitTolerance = 5) {
43
+ if (!coordinate) {
44
+ return [];
45
+ }
46
+ const layer = this.getLayer();
47
+ const featureCollection = layer.engine.getVehiclesAtCoordinate(coordinate, {
48
+ hitTolerance,
49
+ nb: layer.maxNbFeaturesRequested,
50
+ });
51
+ return format.readFeatures(featureCollection);
52
+ }
14
53
  // eslint-disable-next-line class-methods-use-this
15
54
  prepareFrame() {
16
55
  return true;
@@ -37,7 +76,9 @@ export default class RealtimeLayerRenderer extends CanvasLayerRenderer {
37
76
  if (renderedResolution / resolution >= 3) {
38
77
  // Avoid having really big points when zooming fast.
39
78
  const context = canvas === null || canvas === void 0 ? void 0 : canvas.getContext('2d');
40
- 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);
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
+ }
41
82
  }
42
83
  else {
43
84
  const map = this.getLayer().getMapInternal();
@@ -50,65 +91,4 @@ export default class RealtimeLayerRenderer extends CanvasLayerRenderer {
50
91
  }
51
92
  return this.container;
52
93
  }
53
- getData(pixel) {
54
- var _a;
55
- let data;
56
- try {
57
- const { pixelRatio } = this.getLayer();
58
- const context = (_a = this.canvas) === null || _a === void 0 ? void 0 : _a.getContext('2d', {
59
- willReadFrequently: true,
60
- });
61
- data =
62
- (context === null || context === void 0 ? void 0 : context.getImageData(pixel[0] * (pixelRatio || 1), pixel[1] * (pixelRatio || 1), 1, 1).data) || null; // [3];
63
- return data;
64
- }
65
- catch (err) {
66
- // eslint-disable-next-line no-console
67
- console.error('error getting data', err);
68
- }
69
- return null;
70
- }
71
- getFeatures(pixel) {
72
- var _a, _b;
73
- const coordinate = (_b = (_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.getMapInternal()) === null || _b === void 0 ? void 0 : _b.getCoordinateFromPixel(pixel);
74
- return Promise.resolve(this.getFeaturesAtCoordinate(coordinate));
75
- }
76
- forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback) {
77
- const features = this.getFeaturesAtCoordinate(coordinate, hitTolerance);
78
- features.forEach((feature) => {
79
- // @ts-ignore
80
- callback(feature, this.layer_, feature.getGeometry());
81
- });
82
- return features === null || features === void 0 ? void 0 : features[0];
83
- }
84
- getFeaturesAtCoordinate(coordinate, hitTolerance = 5) {
85
- var _a;
86
- if (!coordinate) {
87
- return [];
88
- }
89
- const layer = this.getLayer();
90
- const map = layer.getMapInternal();
91
- const resolution = ((_a = map === null || map === void 0 ? void 0 : map.getView()) === null || _a === void 0 ? void 0 : _a.getResolution()) || 1;
92
- const nb = 10;
93
- const ext = buffer([...coordinate, ...coordinate], hitTolerance * resolution);
94
- let features = [];
95
- let trajectories = Object.values(layer.trajectories || {});
96
- if (layer.sort) {
97
- // @ts-ignore
98
- trajectories = trajectories.sort(this.sort);
99
- }
100
- const vehicles = [];
101
- for (let i = 0; i < trajectories.length; i += 1) {
102
- const trajectory = trajectories[i];
103
- if (trajectory.properties.coordinate &&
104
- containsCoordinate(ext, trajectory.properties.coordinate)) {
105
- vehicles.push(trajectories[i]);
106
- }
107
- if (vehicles.length === nb) {
108
- break;
109
- }
110
- }
111
- features = vehicles.map((vehicle) => format.readFeature(vehicle));
112
- return features;
113
- }
114
94
  }
@@ -1,31 +1,29 @@
1
- import { Style, Fill, Stroke, Circle } from 'ol/style';
2
- /** @private */
1
+ import { Circle, Fill, Stroke, Style } from 'ol/style';
3
2
  const stroke = new Style({
4
- zIndex: 2,
5
3
  image: new Circle({
6
- radius: 5,
7
4
  fill: new Fill({
8
5
  color: '#000000',
9
6
  }),
7
+ radius: 5,
10
8
  }),
11
9
  stroke: new Stroke({
12
10
  color: '#000000',
13
11
  width: 6,
14
12
  }),
13
+ zIndex: 2,
15
14
  });
16
- /** @private */
17
15
  const fill = new Style({
18
- zIndex: 3,
19
16
  image: new Circle({
20
- radius: 4,
21
17
  fill: new Fill({
22
18
  color: '#a0a0a0',
23
19
  }),
20
+ radius: 4,
24
21
  }),
25
22
  stroke: new Stroke({
26
23
  color: '#a0a0a0',
27
24
  width: 4,
28
25
  }),
26
+ zIndex: 3,
29
27
  });
30
28
  /**
31
29
  * @private
@@ -1,5 +1,4 @@
1
- import type { FeatureLike } from 'ol/Feature';
2
1
  import { Style } from 'ol/style';
3
- /** @private */
2
+ import type { FeatureLike } from 'ol/Feature';
4
3
  declare const fullTrajectorystyle: (feature: FeatureLike, resolution: number, options: any) => Style[];
5
4
  export default fullTrajectorystyle;
@@ -1,19 +1,17 @@
1
- import { Style, Fill, Stroke, Circle } from 'ol/style';
2
- /** @private */
1
+ import { Circle, Fill, Stroke, Style } from 'ol/style';
3
2
  const borderStyle = new Style({
4
- zIndex: 2,
5
3
  image: new Circle({
6
- radius: 5,
7
4
  fill: new Fill({
8
5
  color: '#000000',
9
6
  }),
7
+ radius: 5,
10
8
  }),
11
9
  stroke: new Stroke({
12
10
  color: '#000000',
13
11
  width: 6,
14
12
  }),
13
+ zIndex: 2,
15
14
  });
16
- /** @private */
17
15
  const fullTrajectorystyle = (feature, resolution, options) => {
18
16
  let lineColor = '#ffffff'; // white
19
17
  const type = feature.get('type');
@@ -27,17 +25,17 @@ const fullTrajectorystyle = (feature, resolution, options) => {
27
25
  const style = [
28
26
  borderStyle,
29
27
  new Style({
30
- zIndex: 3,
31
28
  image: new Circle({
32
- radius: 4,
33
29
  fill: new Fill({
34
30
  color: lineColor,
35
31
  }),
32
+ radius: 4,
36
33
  }),
37
34
  stroke: new Stroke({
38
35
  color: lineColor,
39
36
  width: 4,
40
37
  }),
38
+ zIndex: 3,
41
39
  }),
42
40
  ];
43
41
  return style;
@@ -1,4 +1,3 @@
1
1
  import { StyleFunction } from 'ol/style/Style';
2
- /** @private */
3
2
  declare const routingStyle: StyleFunction;
4
3
  export default routingStyle;