mobility-toolbox-js 3.0.0-beta.19 → 3.0.0-beta.20
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 +5 -5
- package/api/RealtimeAPI.d.ts +204 -171
- package/api/RealtimeAPI.js +306 -258
- package/api/RoutingAPI.d.ts +4 -4
- package/api/StopsAPI.d.ts +4 -4
- package/api/WebSocketAPI.d.ts +60 -66
- package/api/WebSocketAPI.js +164 -164
- package/api/index.js +1 -1
- package/common/controls/StopFinderControlCommon.d.ts +11 -11
- package/common/controls/StopFinderControlCommon.js +30 -30
- package/common/index.d.ts +1 -1
- package/common/index.js +1 -1
- package/common/mixins/RealtimeLayerMixin.d.ts +149 -155
- package/common/mixins/RealtimeLayerMixin.js +395 -395
- package/common/styles/realtimeDefaultStyle.js +6 -6
- package/common/styles/realtimeHeadingStyle.js +5 -5
- package/common/utils/getMapGlCopyrights.d.ts +1 -1
- package/common/utils/getMapGlCopyrights.js +3 -3
- package/common/utils/getVehiclePosition.d.ts +2 -2
- package/common/utils/getVehiclePosition.js +7 -7
- package/common/utils/renderTrajectories.js +5 -5
- package/common/utils/sortByDelay.js +5 -5
- package/maplibre/layers/RealtimeLayer.d.ts +59 -64
- package/maplibre/layers/RealtimeLayer.js +8 -8
- package/maplibre/utils/getSourceCoordinates.js +5 -5
- package/mbt.js +7205 -7031
- package/mbt.js.map +4 -4
- package/mbt.min.js +25 -25
- package/mbt.min.js.map +4 -4
- package/ol/controls/RoutingControl.d.ts +81 -87
- package/ol/controls/RoutingControl.js +216 -218
- package/ol/layers/Layer.d.ts +9 -9
- package/ol/layers/MaplibreLayer.d.ts +10 -10
- package/ol/layers/MaplibreLayer.js +9 -3
- package/ol/layers/MaplibreStyleLayer.d.ts +77 -76
- package/ol/layers/MaplibreStyleLayer.js +237 -238
- package/ol/layers/RealtimeLayer.d.ts +92 -96
- package/ol/layers/RealtimeLayer.js +139 -131
- package/ol/mixins/MobilityLayerMixin.d.ts +9 -9
- package/ol/mixins/PropertiesLayerMixin.d.ts +33 -36
- package/ol/mixins/PropertiesLayerMixin.js +73 -72
- package/ol/renderers/MaplibreLayerRenderer.js +3 -3
- package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +6 -6
- package/ol/renderers/MaplibreStyleLayerRenderer.js +14 -17
- package/ol/renderers/RealtimeLayerRenderer.d.ts +6 -6
- package/ol/renderers/RealtimeLayerRenderer.js +54 -52
- package/ol/utils/getFeatureInfoAtCoordinate.d.ts +1 -1
- package/ol/utils/getFeatureInfoAtCoordinate.js +10 -16
- package/package.json +6 -5
- package/setupTests.js +3 -4
- package/types/common.d.ts +53 -49
- 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
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
// eslint-disable-next-line max-classes-per-file
|
|
2
2
|
import debounce from 'lodash.debounce';
|
|
3
|
+
import { getUid } from 'ol';
|
|
3
4
|
import getLayersAsFlatArray from '../../common/utils/getLayersAsFlatArray';
|
|
4
5
|
const deprecated = debounce((message) => {
|
|
5
6
|
// eslint-disable-next-line no-console
|
|
@@ -10,6 +11,76 @@ const deprecated = debounce((message) => {
|
|
|
10
11
|
*/
|
|
11
12
|
function PropertiesLayerMixin(Base) {
|
|
12
13
|
return class PropertiesLayer extends Base {
|
|
14
|
+
constructor(...args) {
|
|
15
|
+
var _a;
|
|
16
|
+
const options = args[0];
|
|
17
|
+
super(options);
|
|
18
|
+
this.olEventsKeys = [];
|
|
19
|
+
this.options = {};
|
|
20
|
+
if (options.properties) {
|
|
21
|
+
deprecated("Deprecated. Don't use properties options. Pass the values directly in options object.");
|
|
22
|
+
this.setProperties(options.properties);
|
|
23
|
+
}
|
|
24
|
+
(_a = this.olEventsKeys) === null || _a === void 0 ? void 0 : _a.push(
|
|
25
|
+
// Update parent property
|
|
26
|
+
this.on('propertychange', (evt) => {
|
|
27
|
+
if (evt.key === 'children') {
|
|
28
|
+
this.onChildrenChange(evt.oldValue);
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
this.options = options;
|
|
32
|
+
this.set('children', options.children || []); // Trigger the on children change event
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Initialize the layer with the map passed in parameters.
|
|
36
|
+
*
|
|
37
|
+
* @param {ol/Map~Map} map A map.
|
|
38
|
+
*/
|
|
39
|
+
attachToMap(map) {
|
|
40
|
+
// @ts-expect-error
|
|
41
|
+
(super.attachToMap || (() => { }))(map);
|
|
42
|
+
(this.get('children') || []).forEach((child) => {
|
|
43
|
+
map.addLayer(child);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Terminate what was initialized in init function. Remove layer, events...
|
|
48
|
+
*/
|
|
49
|
+
detachFromMap() {
|
|
50
|
+
(this.get('children') || []).forEach((child) => {
|
|
51
|
+
this.map.removeLayer(child);
|
|
52
|
+
});
|
|
53
|
+
// @ts-expect-error
|
|
54
|
+
(super.detachFromMap || (() => { }))();
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Return the an array containing all the descendants of the layer in a flat array. Including the current layer.
|
|
58
|
+
* @deprecated
|
|
59
|
+
*/
|
|
60
|
+
flat() {
|
|
61
|
+
deprecated('Layer.flat is deprecated. Use getLayersAsFlatArray utils method instead.');
|
|
62
|
+
return getLayersAsFlatArray(this);
|
|
63
|
+
}
|
|
64
|
+
/** @private */
|
|
65
|
+
onChildrenChange(oldValue) {
|
|
66
|
+
// Set the parent property
|
|
67
|
+
(oldValue || []).forEach((child) => {
|
|
68
|
+
child.set('parent', undefined);
|
|
69
|
+
});
|
|
70
|
+
(this.get('children') || []).forEach((child) => {
|
|
71
|
+
child.set('parent', this);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// @ts-expect-error - this is a mixin
|
|
75
|
+
setMapInternal(map) {
|
|
76
|
+
super.setMapInternal(map);
|
|
77
|
+
if (map) {
|
|
78
|
+
this.attachToMap(map);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this.detachFromMap();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
13
84
|
/** @deprecated */
|
|
14
85
|
get children() {
|
|
15
86
|
deprecated("Layer.children is deprecated. Use the Layer.get('children') method instead.");
|
|
@@ -44,6 +115,7 @@ function PropertiesLayerMixin(Base) {
|
|
|
44
115
|
this.set('disabled', newValue);
|
|
45
116
|
}
|
|
46
117
|
/** @deprecated */
|
|
118
|
+
/** @deprecated */
|
|
47
119
|
get group() {
|
|
48
120
|
deprecated("Layer.group is deprecated. Use the Layer.get('group') method instead.");
|
|
49
121
|
return this.get('group');
|
|
@@ -69,7 +141,6 @@ function PropertiesLayerMixin(Base) {
|
|
|
69
141
|
deprecated("Layer.olLayer is deprecated. mobility-toolbox-js/ol layers inherits now from ol/layer/Layer class. This getter is only a redirect to the current 'this' object.");
|
|
70
142
|
return this;
|
|
71
143
|
}
|
|
72
|
-
/** @deprecated */
|
|
73
144
|
// eslint-disable-next-line class-methods-use-this
|
|
74
145
|
set olLayer(newValue) {
|
|
75
146
|
deprecated('Layer.olLayer is deprecated. mobility-toolbox-js/ol layers inherits now from ol/layer/Layer class. This setter has no effect.');
|
|
@@ -94,76 +165,6 @@ function PropertiesLayerMixin(Base) {
|
|
|
94
165
|
deprecated('Layer.visible is deprecated. Use the Layer.setVisible(newValue) method instead.');
|
|
95
166
|
this.setVisible(newValue);
|
|
96
167
|
}
|
|
97
|
-
constructor(...args) {
|
|
98
|
-
var _a;
|
|
99
|
-
const options = args[0];
|
|
100
|
-
super(options);
|
|
101
|
-
this.options = {};
|
|
102
|
-
this.olEventsKeys = [];
|
|
103
|
-
if (options.properties) {
|
|
104
|
-
deprecated("Deprecated. Don't use properties options. Pass the values directly in options object.");
|
|
105
|
-
this.setProperties(options.properties);
|
|
106
|
-
}
|
|
107
|
-
(_a = this.olEventsKeys) === null || _a === void 0 ? void 0 : _a.push(
|
|
108
|
-
// Update parent property
|
|
109
|
-
this.on('propertychange', (evt) => {
|
|
110
|
-
if (evt.key === 'children') {
|
|
111
|
-
this.onChildrenChange(evt.oldValue);
|
|
112
|
-
}
|
|
113
|
-
}));
|
|
114
|
-
this.options = options;
|
|
115
|
-
this.set('children', options.children || []); // Trigger the on children change event
|
|
116
|
-
}
|
|
117
|
-
// @ts-expect-error - this is a mixin
|
|
118
|
-
setMapInternal(map) {
|
|
119
|
-
super.setMapInternal(map);
|
|
120
|
-
if (map) {
|
|
121
|
-
this.attachToMap(map);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
this.detachFromMap();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
/** @private */
|
|
128
|
-
onChildrenChange(oldValue) {
|
|
129
|
-
// Set the parent property
|
|
130
|
-
(oldValue || []).forEach((child) => {
|
|
131
|
-
child.set('parent', undefined);
|
|
132
|
-
});
|
|
133
|
-
(this.get('children') || []).forEach((child) => {
|
|
134
|
-
child.set('parent', this);
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Initialize the layer with the map passed in parameters.
|
|
139
|
-
*
|
|
140
|
-
* @param {ol/Map~Map} map A map.
|
|
141
|
-
*/
|
|
142
|
-
attachToMap(map) {
|
|
143
|
-
// @ts-ignore
|
|
144
|
-
(super.attachToMap || (() => { }))(map);
|
|
145
|
-
(this.get('children') || []).forEach((child) => {
|
|
146
|
-
map.addLayer(child);
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Terminate what was initialized in init function. Remove layer, events...
|
|
151
|
-
*/
|
|
152
|
-
detachFromMap() {
|
|
153
|
-
(this.get('children') || []).forEach((child) => {
|
|
154
|
-
this.map.removeLayer(child);
|
|
155
|
-
});
|
|
156
|
-
// @ts-ignore
|
|
157
|
-
(super.detachFromMap || (() => { }))();
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Return the an array containing all the descendants of the layer in a flat array. Including the current layer.
|
|
161
|
-
* @deprecated
|
|
162
|
-
*/
|
|
163
|
-
flat() {
|
|
164
|
-
deprecated('Layer.flat is deprecated. Use getLayersAsFlatArray utils method instead.');
|
|
165
|
-
return getLayersAsFlatArray(this);
|
|
166
|
-
}
|
|
167
168
|
};
|
|
168
169
|
}
|
|
169
170
|
export default PropertiesLayerMixin;
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
// * functionnalities like map.getFeaturesAtPixel or map.hasFeatureAtPixel.
|
|
29
29
|
// * @private
|
|
30
30
|
// */
|
|
31
|
-
// // @ts-
|
|
31
|
+
// // @ts-expect-error
|
|
32
32
|
// export default class MaplibreLayerRenderer extends LayerRenderer<MaplibreLayer> {
|
|
33
33
|
// getFeaturesAtCoordinate(
|
|
34
34
|
// coordinate: Coordinate | undefined,
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
// // We save the original Maplibre feature to avoid losing informations
|
|
79
79
|
// // potentially needed for other functionnality like highlighting
|
|
80
80
|
// // (id, layer id, source, sourceLayer ...)
|
|
81
|
-
// // @ts-
|
|
81
|
+
// // @ts-expect-error
|
|
82
82
|
// olFeature.set(VECTOR_TILE_FEATURE_PROPERTY, feature);
|
|
83
83
|
// }
|
|
84
84
|
// return olFeature;
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
// ): Feature | undefined {
|
|
135
135
|
// const features = this.getFeaturesAtCoordinate(coordinate, hitTolerance);
|
|
136
136
|
// features.forEach((feature) => {
|
|
137
|
-
// // @ts-
|
|
137
|
+
// // @ts-expect-error
|
|
138
138
|
// callback(feature, this.layer_, feature.getGeometry());
|
|
139
139
|
// });
|
|
140
140
|
// return features?.[0] as Feature;
|
|
@@ -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
|
|
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) {
|
|
@@ -53,7 +65,6 @@ export default class MaplibreStyleLayerRenderer extends LayerRenderer {
|
|
|
53
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
69
|
layers = mapLibreMap
|
|
59
70
|
.getStyle()
|
|
@@ -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
|
-
|
|
17
|
-
renderFrame(frameState: FrameState): HTMLElement;
|
|
16
|
+
forEachFeatureAtCoordinate<Feature>(coordinate: Coordinate, frameState: FrameState, hitTolerance: number, callback: FeatureCallback<Feature>): Feature | undefined;
|
|
18
17
|
getData(pixel: Pixel): Uint8ClampedArray | null;
|
|
19
18
|
getFeatures(pixel: Pixel): Promise<Feature<Geometry>[]>;
|
|
20
|
-
forEachFeatureAtCoordinate<Feature>(coordinate: Coordinate, frameState: FrameState, hitTolerance: number, callback: FeatureCallback<Feature>): Feature | undefined;
|
|
21
19
|
getFeaturesAtCoordinate(coordinate: Coordinate | undefined, hitTolerance?: number): Feature<Geometry>[];
|
|
20
|
+
prepareFrame(): boolean;
|
|
21
|
+
renderFrame(frameState: FrameState): HTMLElement;
|
|
22
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,46 +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
|
-
this.container = document.createElement('div');
|
|
22
|
-
this.container.className = this.getLayer().getClassName();
|
|
23
|
-
this.container.style.position = 'absolute';
|
|
24
|
-
this.container.style.width = '100%';
|
|
25
|
-
this.container.style.height = '100%';
|
|
26
|
-
if (canvas instanceof HTMLCanvasElement) {
|
|
27
|
-
canvas.style.position = 'absolute';
|
|
28
|
-
canvas.style.top = '0';
|
|
29
|
-
canvas.style.left = '0';
|
|
30
|
-
canvas.style.transformOrigin = 'top left';
|
|
31
|
-
this.container.appendChild(canvas);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
if (renderedViewState) {
|
|
35
|
-
const { center, resolution, rotation } = frameState.viewState;
|
|
36
|
-
const { center: renderedCenter, resolution: renderedResolution, rotation: renderedRotation, } = renderedViewState;
|
|
37
|
-
if (renderedResolution / resolution >= 3) {
|
|
38
|
-
// Avoid having really big points when zooming fast.
|
|
39
|
-
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);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
const map = this.getLayer().getMapInternal();
|
|
44
|
-
const pixelCenterRendered = map === null || map === void 0 ? void 0 : map.getPixelFromCoordinate(renderedCenter);
|
|
45
|
-
const pixelCenter = map === null || map === void 0 ? void 0 : map.getPixelFromCoordinate(center);
|
|
46
|
-
if (pixelCenterRendered && pixelCenter) {
|
|
47
|
-
this.container.style.transform = composeCssTransform(pixelCenterRendered[0] - pixelCenter[0], pixelCenterRendered[1] - pixelCenter[1], renderedResolution / resolution, renderedResolution / resolution, rotation - renderedRotation, 0, 0);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
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];
|
|
52
21
|
}
|
|
53
22
|
getData(pixel) {
|
|
54
23
|
var _a;
|
|
@@ -73,14 +42,6 @@ export default class RealtimeLayerRenderer extends CanvasLayerRenderer {
|
|
|
73
42
|
const coordinate = (_b = (_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.getMapInternal()) === null || _b === void 0 ? void 0 : _b.getCoordinateFromPixel(pixel);
|
|
74
43
|
return Promise.resolve(this.getFeaturesAtCoordinate(coordinate));
|
|
75
44
|
}
|
|
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
45
|
getFeaturesAtCoordinate(coordinate, hitTolerance = 5) {
|
|
85
46
|
var _a;
|
|
86
47
|
if (!coordinate) {
|
|
@@ -94,16 +55,16 @@ export default class RealtimeLayerRenderer extends CanvasLayerRenderer {
|
|
|
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
64
|
if (
|
|
104
|
-
// @ts-expect-error
|
|
65
|
+
// @ts-expect-error coordinate is added by the RealtimeLayer
|
|
105
66
|
trajectory.properties.coordinate &&
|
|
106
|
-
// @ts-expect-error
|
|
67
|
+
// @ts-expect-error coordinate is added by the RealtimeLayer
|
|
107
68
|
containsCoordinate(ext, trajectory.properties.coordinate)) {
|
|
108
69
|
vehicles.push(trajectories[i]);
|
|
109
70
|
}
|
|
@@ -114,4 +75,45 @@ export default class RealtimeLayerRenderer extends CanvasLayerRenderer {
|
|
|
114
75
|
features = vehicles.map((vehicle) => format.readFeature(vehicle));
|
|
115
76
|
return features;
|
|
116
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
|
+
}
|
|
117
119
|
}
|
|
@@ -19,11 +19,11 @@ const format = new GeoJSON();
|
|
|
19
19
|
*/
|
|
20
20
|
const getFeaturesFromWMS = (source, options, abortController) => {
|
|
21
21
|
let url;
|
|
22
|
-
const { coordinate,
|
|
22
|
+
const { coordinate, params, projection, resolution } = options;
|
|
23
23
|
if (source && resolution && projection) {
|
|
24
24
|
url = source.getFeatureInfoUrl(coordinate, resolution, projection, Object.assign({ info_format: 'application/json', query_layers: source.getParams().layers }, params));
|
|
25
25
|
}
|
|
26
|
-
// @ts-
|
|
26
|
+
// @ts-expect-error
|
|
27
27
|
return fetch(url, { signal: abortController.signal })
|
|
28
28
|
.then((resp) => resp.json())
|
|
29
29
|
.then((featureCollection) => format.readFeatures(featureCollection))
|
|
@@ -47,21 +47,17 @@ const getFeatureInfoAtCoordinate = (coordinate_1, layers_1, ...args_1) => __awai
|
|
|
47
47
|
var _a, _b, _c, _d;
|
|
48
48
|
const map = layer.getMapInternal();
|
|
49
49
|
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();
|
|
50
|
-
const emptyResponse = { features: [], layer
|
|
50
|
+
const emptyResponse = { coordinate, features: [], layer };
|
|
51
51
|
if (!projection) {
|
|
52
52
|
return Promise.resolve(emptyResponse);
|
|
53
53
|
}
|
|
54
54
|
// For backward compatibility
|
|
55
|
-
// @ts-ignore
|
|
56
55
|
if (layer.getFeatureInfoAtCoordinate) {
|
|
57
|
-
return (
|
|
58
|
-
// @ts-ignore
|
|
59
|
-
.getFeatureInfoAtCoordinate(coordinate));
|
|
56
|
+
return layer.getFeatureInfoAtCoordinate(coordinate);
|
|
60
57
|
}
|
|
61
58
|
// WMS sources
|
|
62
59
|
// Here we don't use instanceof, to be able to use this function if a layer comes from 2 different ol versions.
|
|
63
60
|
const source = layer === null || layer === void 0 ? void 0 : layer.getSource();
|
|
64
|
-
// @ts-ignore
|
|
65
61
|
if (source === null || source === void 0 ? void 0 : source.getFeatureInfoUrl) {
|
|
66
62
|
const id = getUid(layer);
|
|
67
63
|
// Abort and recreates one controller per layer
|
|
@@ -70,25 +66,25 @@ const getFeatureInfoAtCoordinate = (coordinate_1, layers_1, ...args_1) => __awai
|
|
|
70
66
|
const resolution = (_d = map === null || map === void 0 ? void 0 : map.getView()) === null || _d === void 0 ? void 0 : _d.getResolution();
|
|
71
67
|
return getFeaturesFromWMS(source, {
|
|
72
68
|
coordinate,
|
|
73
|
-
resolution,
|
|
74
|
-
projection,
|
|
75
69
|
params: {
|
|
76
70
|
info_format: 'application/json',
|
|
77
71
|
query_layers: source.getParams().layers,
|
|
78
72
|
},
|
|
73
|
+
projection,
|
|
74
|
+
resolution,
|
|
79
75
|
}, abortControllers[id])
|
|
80
76
|
.then((features) => {
|
|
81
77
|
return {
|
|
78
|
+
coordinate,
|
|
82
79
|
features,
|
|
83
80
|
layer,
|
|
84
|
-
coordinate,
|
|
85
81
|
};
|
|
86
82
|
})
|
|
87
83
|
.catch(() => {
|
|
88
84
|
return {
|
|
85
|
+
coordinate,
|
|
89
86
|
features: [],
|
|
90
87
|
layer,
|
|
91
|
-
coordinate,
|
|
92
88
|
};
|
|
93
89
|
});
|
|
94
90
|
}
|
|
@@ -99,15 +95,13 @@ const getFeatureInfoAtCoordinate = (coordinate_1, layers_1, ...args_1) => __awai
|
|
|
99
95
|
return Promise.resolve(emptyResponse);
|
|
100
96
|
}
|
|
101
97
|
const features = map === null || map === void 0 ? void 0 : map.getFeaturesAtPixel(pixel, {
|
|
98
|
+
hitTolerance: layer.get('hitTolerance') || hitTolerance || 5,
|
|
102
99
|
layerFilter: (l) => l === layer,
|
|
103
|
-
hitTolerance:
|
|
104
|
-
// @ts-ignore
|
|
105
|
-
layer.get('hitTolerance') || hitTolerance || 5,
|
|
106
100
|
});
|
|
107
101
|
return Promise.resolve({
|
|
102
|
+
coordinate,
|
|
108
103
|
features,
|
|
109
104
|
layer,
|
|
110
|
-
coordinate,
|
|
111
105
|
});
|
|
112
106
|
});
|
|
113
107
|
return Promise.all(promises);
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
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.20",
|
|
6
6
|
"homepage": "https://mobility-toolbox-js.geops.io/",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./index.js",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"@babel/preset-typescript": "^7.24.7",
|
|
29
29
|
"@commitlint/cli": "19.3.0",
|
|
30
30
|
"@commitlint/config-conventional": "19.2.2",
|
|
31
|
+
"@geops/eslint-config-react": "^1.0.2",
|
|
31
32
|
"@types/geojson": "7946.0.14",
|
|
32
33
|
"@types/lodash.debounce": "4.0.9",
|
|
33
34
|
"@types/lodash.throttle": "4.1.9",
|
|
@@ -35,8 +36,8 @@
|
|
|
35
36
|
"@types/offscreencanvas": "2019.7.3",
|
|
36
37
|
"@types/topojson": "3.2.6",
|
|
37
38
|
"@types/uuid": "10.0.0",
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "7.
|
|
39
|
-
"@typescript-eslint/parser": "7.
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "7.14.1",
|
|
40
|
+
"@typescript-eslint/parser": "7.14.1",
|
|
40
41
|
"cypress": "13.12.0",
|
|
41
42
|
"esbuild": "0.21.5",
|
|
42
43
|
"esdoc": "1.1.0",
|
|
@@ -64,7 +65,7 @@
|
|
|
64
65
|
"jest-transformer-svg": "2.0.2",
|
|
65
66
|
"jest-websocket-mock": "2.5.0",
|
|
66
67
|
"lint-staged": "15.2.7",
|
|
67
|
-
"maplibre-gl": "4.
|
|
68
|
+
"maplibre-gl": "4.5.0",
|
|
68
69
|
"mock-socket": "9.3.1",
|
|
69
70
|
"next": "14.2.4",
|
|
70
71
|
"next-transpile-modules": "10.0.1",
|
|
@@ -101,7 +102,7 @@
|
|
|
101
102
|
"esbuild:iife:base": "esbuild src/iife.js --bundle --sourcemap --target=chrome100",
|
|
102
103
|
"esbuild:iife:minify": "yarn esbuild:iife:base --minify --outfile=build/mbt.min.js",
|
|
103
104
|
"esbuild:iife:unminify": "yarn esbuild:iife:base --outfile=build/mbt.js",
|
|
104
|
-
"format": "prettier --write 'src/**/*.js' && eslint
|
|
105
|
+
"format": "prettier --write 'src/**/*.js' && eslint src/**/*.js src/**/*.ts --fix && stylelint 'src/**/*.css' 'src/**/*.scss' --fix --allow-empty-input",
|
|
105
106
|
"lib": "REACT_APP_LIB_MODE=1 webpack --mode production",
|
|
106
107
|
"lib:dev": "REACT_APP_LIB_MODE=1 webpack --mode development",
|
|
107
108
|
"link2": "cmdToAdd=$(node ./scripts/read-pkg-json.js add) && $cmdToAdd && yarn build && cmdToRemove=$(node ./scripts/read-pkg-json.js remove) && $cmdToRemove && cd build && yarn link",
|
package/setupTests.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import 'jest-canvas-mock';
|
|
3
|
-
import fetchTrajectoryByIdResponse from '../data/fetchTrajectoryById.json';
|
|
1
|
+
import fetchRouteResponse from '../data/fetchRoute.json';
|
|
4
2
|
import fetchTrajectoriesResponse from '../data/fetchTrajectories.json';
|
|
3
|
+
import fetchTrajectoryByIdResponse from '../data/fetchTrajectoryById.json';
|
|
5
4
|
import fetchTrajectoryStationsResponse from '../data/fetchTrajectoryStations.json';
|
|
6
5
|
import stopsSearchResponse from '../data/stopsSearch.json';
|
|
7
|
-
import
|
|
6
|
+
import 'jest-canvas-mock';
|
|
8
7
|
global.fetchTrajectoryByIdResponse = fetchTrajectoryByIdResponse;
|
|
9
8
|
global.fetchTrajectoriesResponse = fetchTrajectoriesResponse;
|
|
10
9
|
global.fetchTrajectoryStationsResponse = fetchTrajectoryStationsResponse;
|