@geops/rvf-mobility-web-component 0.1.68 → 0.1.69
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/CHANGELOG.md +7 -0
- package/index.js +51 -51
- package/package.json +1 -1
- package/src/LayerTreeMenu/LayerTreeMenu.tsx +9 -1
- package/src/MapsetLayer/MapsetLayer.tsx +36 -0
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@geops/rvf-mobility-web-component",
|
|
3
3
|
"license": "UNLICENSED",
|
|
4
4
|
"description": "Web components for rvf in the domains of mobility and logistics.",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.69",
|
|
6
6
|
"homepage": "https://rvf-mobility-web-component-geops.vercel.app/",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "index.js",
|
|
@@ -27,6 +27,7 @@ export interface LayerTreeConfig {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export type LayerTreeMenuProps = {
|
|
30
|
+
filter?: (layer: BaseLayer) => boolean;
|
|
30
31
|
order: string[];
|
|
31
32
|
} & HTMLAttributes<HTMLDivElement> &
|
|
32
33
|
Partial<LayerTreeProps> &
|
|
@@ -62,6 +63,7 @@ const getConfigForLayer = (
|
|
|
62
63
|
};
|
|
63
64
|
|
|
64
65
|
function LayerTreeMenu({
|
|
66
|
+
filter,
|
|
65
67
|
order = LAYER_TREE_ORDER,
|
|
66
68
|
...props
|
|
67
69
|
}: LayerTreeMenuProps) {
|
|
@@ -74,6 +76,12 @@ function LayerTreeMenu({
|
|
|
74
76
|
map
|
|
75
77
|
?.getLayers()
|
|
76
78
|
.getArray()
|
|
79
|
+
.filter(
|
|
80
|
+
filter ??
|
|
81
|
+
(() => {
|
|
82
|
+
return true;
|
|
83
|
+
}),
|
|
84
|
+
)
|
|
77
85
|
.sort((a, b) => {
|
|
78
86
|
if (
|
|
79
87
|
order &&
|
|
@@ -88,7 +96,7 @@ function LayerTreeMenu({
|
|
|
88
96
|
return getConfigForLayer(layer, revision, layersConfig);
|
|
89
97
|
}) || [];
|
|
90
98
|
return config;
|
|
91
|
-
}, [layersConfig, map, order, revision]);
|
|
99
|
+
}, [filter, layersConfig, map, order, revision]);
|
|
92
100
|
|
|
93
101
|
// Force update of config when a layers`s visibility changes progammatically
|
|
94
102
|
useEffect(() => {
|
|
@@ -11,6 +11,13 @@ import type { MapsetLayerOptions } from "mobility-toolbox-js/ol";
|
|
|
11
11
|
|
|
12
12
|
let moveEndTimeout: ReturnType<typeof setTimeout>;
|
|
13
13
|
|
|
14
|
+
export const isFeatureOutsideZoomLimit = (feature, map) => {
|
|
15
|
+
const zoom = map?.getView()?.getZoom();
|
|
16
|
+
const minZoom = feature.get("minZoom");
|
|
17
|
+
const maxZoom = feature.get("maxZoom");
|
|
18
|
+
return minZoom > zoom || zoom > maxZoom;
|
|
19
|
+
};
|
|
20
|
+
|
|
14
21
|
function MapsetLayer(props?: Partial<MapsetLayerOptions>) {
|
|
15
22
|
const {
|
|
16
23
|
apikey,
|
|
@@ -131,6 +138,35 @@ function MapsetLayer(props?: Partial<MapsetLayerOptions>) {
|
|
|
131
138
|
};
|
|
132
139
|
}, [map, layer, mapsetplanid]);
|
|
133
140
|
|
|
141
|
+
// Apply fetaure's minzoom and maxzoom to its style
|
|
142
|
+
// TODO should be done by the mapset layer itself
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
let key = null;
|
|
145
|
+
if (layer) {
|
|
146
|
+
key = layer.on("updatefeatures", () => {
|
|
147
|
+
const features = layer.getSource()?.getFeatures();
|
|
148
|
+
if (!features?.length) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
features.forEach((feature) => {
|
|
152
|
+
const styleFunction = feature.getStyleFunction();
|
|
153
|
+
if (styleFunction) {
|
|
154
|
+
(feature as Feature).setStyle((feat, resolution) => {
|
|
155
|
+
if (isFeatureOutsideZoomLimit(feat, layer.getMapInternal())) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
return styleFunction(feature, resolution);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return () => {
|
|
166
|
+
unByKey(key);
|
|
167
|
+
};
|
|
168
|
+
}, [layer]);
|
|
169
|
+
|
|
134
170
|
return null;
|
|
135
171
|
}
|
|
136
172
|
|