mobility-toolbox-js 3.0.0-beta.13 → 3.0.0-beta.15
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/common/typedefs.d.ts +2 -2
- package/common/typedefs.js +1 -1
- package/mbt.js +357 -216
- package/mbt.js.map +4 -4
- package/mbt.min.js +12 -12
- package/mbt.min.js.map +4 -4
- package/ol/layers/Layer.d.ts +2 -2
- package/ol/layers/MaplibreLayer.d.ts +19 -43
- package/ol/layers/MaplibreLayer.js +31 -98
- package/ol/layers/MaplibreStyleLayer.d.ts +3 -3
- package/ol/layers/MaplibreStyleLayer.js +15 -4
- package/ol/layers/RealtimeLayer.d.ts +4 -5
- package/ol/layers/RealtimeLayer.js +1 -1
- package/ol/layers/VectorLayer.d.ts +18 -0
- package/ol/layers/VectorLayer.js +31 -0
- package/ol/layers/index.d.ts +1 -0
- package/ol/layers/index.js +2 -0
- package/ol/mixins/MobilityLayerMixin.d.ts +2 -2
- package/ol/mixins/PropertiesLayerMixin.d.ts +13 -2
- package/ol/mixins/PropertiesLayerMixin.js +40 -14
- package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -20
- package/ol/renderers/MaplibreLayerRenderer.js +142 -114
- package/package.json +2 -1
|
@@ -1,41 +1,56 @@
|
|
|
1
1
|
import { getUid } from 'ol';
|
|
2
|
+
import debounce from 'lodash.debounce';
|
|
2
3
|
import getLayersAsFlatArray from '../../common/utils/getLayersAsFlatArray';
|
|
4
|
+
const deprecated = debounce((message) => {
|
|
5
|
+
// eslint-disable-next-line no-console
|
|
6
|
+
console.warn(message);
|
|
7
|
+
}, 1000);
|
|
3
8
|
/**
|
|
4
9
|
* This mixin adds some properties to access ol custom properties easily.
|
|
5
10
|
*/
|
|
6
11
|
function PropertiesLayerMixin(Base) {
|
|
7
12
|
return class PropertiesLayer extends Base {
|
|
13
|
+
/** @deprecated */
|
|
8
14
|
get children() {
|
|
15
|
+
deprecated("Layer.children is deprecated. Use the Layer.get('children') method instead.");
|
|
9
16
|
return this.get('children') || [];
|
|
10
17
|
}
|
|
18
|
+
/** @deprecated */
|
|
11
19
|
set children(newValue) {
|
|
20
|
+
deprecated("Layer.children is deprecated. Use the Layer.set('children', children) method instead.");
|
|
12
21
|
this.set('children', newValue || []);
|
|
13
22
|
}
|
|
23
|
+
/** @deprecated */
|
|
14
24
|
get copyrights() {
|
|
15
|
-
|
|
16
|
-
console.warn('Deprecated. Use the source object to get the attributions');
|
|
25
|
+
deprecated('Layer.copyrights is deprecated. Get the attributions from the source object');
|
|
17
26
|
return this.get('copyrights');
|
|
18
27
|
}
|
|
28
|
+
/** @deprecated */
|
|
19
29
|
set copyrights(newCopyrights) {
|
|
20
|
-
|
|
21
|
-
console.warn('Deprecated. Use the source object to set the attributions');
|
|
30
|
+
deprecated('Layer.copyrights is deprecated. Set the attributions to the source object.');
|
|
22
31
|
const arrValue = newCopyrights && !Array.isArray(newCopyrights)
|
|
23
32
|
? [newCopyrights]
|
|
24
33
|
: newCopyrights;
|
|
25
34
|
this.set('copyrights', arrValue || []);
|
|
26
35
|
}
|
|
36
|
+
/** @deprecated */
|
|
27
37
|
get disabled() {
|
|
38
|
+
deprecated("Layer.disabled is deprecated. Use the Layer.get('disabled') method instead.");
|
|
28
39
|
return this.get('disabled');
|
|
29
40
|
}
|
|
41
|
+
/** @deprecated */
|
|
30
42
|
set disabled(newValue) {
|
|
43
|
+
deprecated("Layer.disabled is deprecated. Use the Layer.set('disabled', newValue) method instead.");
|
|
31
44
|
this.set('disabled', newValue);
|
|
32
45
|
}
|
|
46
|
+
/** @deprecated */
|
|
33
47
|
get group() {
|
|
48
|
+
deprecated("Layer.group is deprecated. Use the Layer.get('group') method instead.");
|
|
34
49
|
return this.get('group');
|
|
35
50
|
}
|
|
51
|
+
/** @deprecated */
|
|
36
52
|
get hitTolerance() {
|
|
37
|
-
|
|
38
|
-
console.warn('Deprecated. Pass the pixelTolerance when you request the features.');
|
|
53
|
+
deprecated('Layer.hitTolerance is deprecated.Pass the hitTolerance when you request the features.');
|
|
39
54
|
return this.get('hitTolerance') || 5;
|
|
40
55
|
}
|
|
41
56
|
get key() {
|
|
@@ -44,29 +59,39 @@ function PropertiesLayerMixin(Base) {
|
|
|
44
59
|
get map() {
|
|
45
60
|
return this.getMapInternal();
|
|
46
61
|
}
|
|
62
|
+
/** @deprecated */
|
|
47
63
|
get name() {
|
|
64
|
+
deprecated("Layer.name is deprecated. Use the Layer.get('name') method instead.");
|
|
48
65
|
return this.get('name');
|
|
49
66
|
}
|
|
67
|
+
/** @deprecated */
|
|
50
68
|
get olLayer() {
|
|
51
|
-
|
|
52
|
-
console.warn("Deprecated property: mobility-toolbox-js/ol layers inherits now from ol/layer/Layer class. This getter is only a redirect to the current 'this' object.");
|
|
69
|
+
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.");
|
|
53
70
|
return this;
|
|
54
71
|
}
|
|
72
|
+
/** @deprecated */
|
|
55
73
|
// eslint-disable-next-line class-methods-use-this
|
|
56
74
|
set olLayer(newValue) {
|
|
57
|
-
|
|
58
|
-
console.log('Deprecated property: mobility-toolbox-js/ol layers inherits now from ol/layer/Layer class. This setter has no effect.');
|
|
75
|
+
deprecated('Layer.olLayer is deprecated. mobility-toolbox-js/ol layers inherits now from ol/layer/Layer class. This setter has no effect.');
|
|
59
76
|
}
|
|
77
|
+
/** @deprecated */
|
|
60
78
|
get parent() {
|
|
79
|
+
deprecated("Layer.parent is deprecated. Use the Layer.get('parent') method instead.");
|
|
61
80
|
return this.get('parent');
|
|
62
81
|
}
|
|
82
|
+
/** @deprecated */
|
|
63
83
|
set parent(newValue) {
|
|
84
|
+
deprecated("Layer.parent is deprecated. Use the Layer.set('parent', parent) method instead.");
|
|
64
85
|
this.set('parent', newValue);
|
|
65
86
|
}
|
|
87
|
+
/** @deprecated */
|
|
66
88
|
get visible() {
|
|
89
|
+
deprecated('Layer.visible is deprecated. Use the Layer.getVisible() method instead.');
|
|
67
90
|
return this.getVisible();
|
|
68
91
|
}
|
|
92
|
+
/** @deprecated */
|
|
69
93
|
set visible(newValue) {
|
|
94
|
+
deprecated('Layer.visible is deprecated. Use the Layer.setVisible(newValue) method instead.');
|
|
70
95
|
this.setVisible(newValue);
|
|
71
96
|
}
|
|
72
97
|
constructor(...args) {
|
|
@@ -74,13 +99,12 @@ function PropertiesLayerMixin(Base) {
|
|
|
74
99
|
const options = args[0];
|
|
75
100
|
super(options);
|
|
76
101
|
this.options = {};
|
|
77
|
-
this.
|
|
102
|
+
this.olEventsKeys = [];
|
|
78
103
|
if (options.properties) {
|
|
79
|
-
|
|
80
|
-
console.warn("Deprecated. Don't use properties options. Pass the values directly in options object.");
|
|
104
|
+
deprecated("Deprecated. Don't use properties options. Pass the values directly in options object.");
|
|
81
105
|
this.setProperties(options.properties);
|
|
82
106
|
}
|
|
83
|
-
(_a = this.
|
|
107
|
+
(_a = this.olEventsKeys) === null || _a === void 0 ? void 0 : _a.push(
|
|
84
108
|
// Update parent property
|
|
85
109
|
this.on('propertychange', (evt) => {
|
|
86
110
|
if (evt.key === 'children') {
|
|
@@ -134,8 +158,10 @@ function PropertiesLayerMixin(Base) {
|
|
|
134
158
|
}
|
|
135
159
|
/**
|
|
136
160
|
* Return the an array containing all the descendants of the layer in a flat array. Including the current layer.
|
|
161
|
+
* @deprecated
|
|
137
162
|
*/
|
|
138
163
|
flat() {
|
|
164
|
+
deprecated('Layer.flat is deprecated. Use getLayersAsFlatArray utils method instead.');
|
|
139
165
|
return getLayersAsFlatArray(this);
|
|
140
166
|
}
|
|
141
167
|
};
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
import { Feature } from 'ol';
|
|
6
|
-
import { Geometry } from 'ol/geom';
|
|
7
|
-
import { Pixel } from 'ol/pixel';
|
|
8
|
-
import type MaplibreLayer from '../layers/MaplibreLayer';
|
|
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 MaplibreLayerRenderer extends LayerRenderer<MaplibreLayer> {
|
|
15
|
-
getFeaturesAtCoordinate(coordinate: Coordinate | undefined, hitTolerance?: number): Feature<Geometry>[];
|
|
16
|
-
prepareFrame(): boolean;
|
|
17
|
-
renderFrame(frameState: FrameState): HTMLElement | null;
|
|
18
|
-
getFeatures(pixel: Pixel): Promise<Feature<Geometry>[]>;
|
|
19
|
-
forEachFeatureAtCoordinate<Feature>(coordinate: Coordinate, frameState: FrameState, hitTolerance: number, callback: FeatureCallback<Feature>): Feature | undefined;
|
|
20
|
-
}
|
|
@@ -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-ignore
|
|
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-ignore
|
|
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-ignore
|
|
138
|
+
// callback(feature, this.layer_, feature.getGeometry());
|
|
139
|
+
// });
|
|
140
|
+
// return features?.[0] as Feature;
|
|
141
|
+
// }
|
|
142
|
+
// }
|
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.15",
|
|
6
6
|
"homepage": "https://mobility-toolbox-js.geops.io/",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./index.js",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"./types": "./types/index.d.ts"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
+
"@geoblocks/ol-maplibre-layer": "^1.0.0",
|
|
15
16
|
"@turf/helpers": "6.5.0",
|
|
16
17
|
"@turf/transform-rotate": "6.5.0",
|
|
17
18
|
"lodash.debounce": "4.0.8",
|