@geops/rvf-mobility-web-component 0.1.68 → 0.1.70

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/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.68",
5
+ "version": "0.1.70",
6
6
  "homepage": "https://rvf-mobility-web-component-geops.vercel.app/",
7
7
  "type": "module",
8
8
  "main": "index.js",
@@ -33,15 +33,11 @@ function FeaturesInfosListener() {
33
33
  return info.layer === realtimeLayer;
34
34
  })?.features || [];
35
35
 
36
- const stationsFeatures =
36
+ const [stationFeature] =
37
37
  featuresInfos?.find((info) => {
38
38
  return info.layer === stationsLayer;
39
39
  })?.features || [];
40
40
 
41
- const [stationFeature] = stationsFeatures.filter((feat) => {
42
- return feat.get("tralis_network")?.includes(tenant);
43
- });
44
-
45
41
  const features =
46
42
  featuresInfos?.flatMap((info) => {
47
43
  return info.features;
@@ -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,
@@ -44,11 +51,19 @@ function MapsetLayer(props?: Partial<MapsetLayerOptions>) {
44
51
  bbox = transformExtent(bbox, "EPSG:3857", "EPSG:4326");
45
52
  }
46
53
  } else {
47
- bbox = transformExtent(
48
- map.getView()?.calculateExtent(map.getSize()),
49
- "EPSG:3857",
50
- "EPSG:4326",
51
- );
54
+ // we have to wait that the map is well sized to get the extent
55
+ // It triggers an erro in FF without this
56
+ if (
57
+ map.getView()?.getCenter() &&
58
+ map.getSize()[0] > 0 &&
59
+ map.getSize()[1] > 0
60
+ ) {
61
+ bbox = transformExtent(
62
+ map.getView()?.calculateExtent(),
63
+ "EPSG:3857",
64
+ "EPSG:4326",
65
+ );
66
+ }
52
67
  }
53
68
  return new MtbMapsetLayer({
54
69
  apiKey: apikey,
@@ -131,6 +146,35 @@ function MapsetLayer(props?: Partial<MapsetLayerOptions>) {
131
146
  };
132
147
  }, [map, layer, mapsetplanid]);
133
148
 
149
+ // Apply fetaure's minzoom and maxzoom to its style
150
+ // TODO should be done by the mapset layer itself
151
+ useEffect(() => {
152
+ let key = null;
153
+ if (layer) {
154
+ key = layer.on("updatefeatures", () => {
155
+ const features = layer.getSource()?.getFeatures();
156
+ if (!features?.length) {
157
+ return;
158
+ }
159
+ features.forEach((feature) => {
160
+ const styleFunction = feature.getStyleFunction();
161
+ if (styleFunction) {
162
+ (feature as Feature).setStyle((feat, resolution) => {
163
+ if (isFeatureOutsideZoomLimit(feat, layer.getMapInternal())) {
164
+ return null;
165
+ }
166
+ return styleFunction(feature, resolution);
167
+ });
168
+ }
169
+ });
170
+ });
171
+ }
172
+
173
+ return () => {
174
+ unByKey(key);
175
+ };
176
+ }, [layer]);
177
+
134
178
  return null;
135
179
  }
136
180
 
@@ -20,8 +20,14 @@ function SingleClickListener({
20
20
  debounceTimeout = 0,
21
21
  hover = true,
22
22
  }: SingleClickListenerProps) {
23
- const { map, queryablelayers, setFeaturesInfos, setFeaturesInfosHovered } =
24
- useMapContext();
23
+ const {
24
+ map,
25
+ queryablelayers,
26
+ setFeaturesInfos,
27
+ setFeaturesInfosHovered,
28
+ stationsLayer,
29
+ tenant,
30
+ } = useMapContext();
25
31
 
26
32
  const getFeaturesInfosAtEvt = useCallback(
27
33
  async (evt: MapBrowserEvent<PointerEvent>) => {
@@ -34,9 +40,30 @@ function SingleClickListener({
34
40
  5,
35
41
  true,
36
42
  );
43
+
44
+ // Filter the features clicked in the stations layer by the tenant
45
+ if (stationsLayer) {
46
+ // Clean the features infos stations clicked
47
+ const featuresInfoStations = featuresInfos?.find((info) => {
48
+ return info.layer === stationsLayer;
49
+ });
50
+ const stationsFeatures = featuresInfoStations?.features || [];
51
+
52
+ const [stationFeature] = stationsFeatures.filter((feat) => {
53
+ return feat.get("tralis_network")?.includes(tenant);
54
+ });
55
+
56
+ // Replace the features clicked in the stations layer by the filtered one
57
+ if (featuresInfoStations) {
58
+ featuresInfoStations.features = stationFeature
59
+ ? [stationFeature]
60
+ : [];
61
+ }
62
+ }
63
+
37
64
  return featuresInfos;
38
65
  },
39
- [queryablelayers],
66
+ [queryablelayers, stationsLayer, tenant],
40
67
  );
41
68
 
42
69
  const onPointerMove = useCallback(