@geops/rvf-mobility-web-component 0.1.122 → 0.1.124

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.122",
5
+ "version": "0.1.124",
6
6
  "homepage": "https://rvf-mobility-web-component.vercel.app/",
7
7
  "type": "module",
8
8
  "main": "index.js",
@@ -12,7 +12,7 @@
12
12
  "jspdf": "^4.1.0",
13
13
  "lodash.debounce": "^4.0.8",
14
14
  "maplibre-gl": "5.12.0",
15
- "mobility-toolbox-js": "3.6.8",
15
+ "mobility-toolbox-js": "3.6.10",
16
16
  "ol": "^10.8.0",
17
17
  "preact": "^10.28.4",
18
18
  "preact-custom-element": "^4.6.0",
@@ -145,6 +145,9 @@ const attrs: MobilityMapAttributes = {
145
145
  },
146
146
  "title": "Liniennetzpläne"
147
147
  }
148
+ "sharedmobility": {
149
+ minZoom": 14,
150
+ }
148
151
  </pre>}
149
152
  <br/>
150
153
  where:
@@ -160,7 +163,8 @@ where:
160
163
  <li><i>href</i> is the target of the link. The <i>href</i> can be template, for example for the meldungen layer you can use {{id}} to insert the id of the notification in the url.</li>
161
164
  </ul>
162
165
  <li><i>title</i> is the title of the layer used in the details view header and in the layer tree, if not defined the layer name will be used.</li>
163
- </ul>`,
166
+ <li><i>minZoom</i> is the minimal zoom level at which the layer is visible (only <i>${LAYERS_NAMES.sharedMobility}</i> layer).</li>
167
+ </ul>`,
164
168
  public: true,
165
169
  },
166
170
  layertree: {
@@ -42,7 +42,8 @@ const Permalink = ({ replaceState = false }: { replaceState?: boolean }) => {
42
42
  replaceState &&
43
43
  permalink &&
44
44
  permalink !== window.location.href &&
45
- !permalink.includes(encodeURIComponent("{{"))
45
+ !permalink.includes(encodeURIComponent("{{")) &&
46
+ !permalink.includes("{{")
46
47
  ) {
47
48
  window.history.replaceState(null, null, permalink);
48
49
  }
@@ -37,8 +37,9 @@ function RvfSelectedFeatureHighlightLayer() {
37
37
  useEffect(() => {
38
38
  const vectorTileFeature = selectedFeature?.get("vectorTileFeature");
39
39
  selectedFeature?.set("selected", true);
40
- const source = mbMap?.getSource(SOURCE_SELECT);
40
+ let source;
41
41
  if (selectedFeature) {
42
+ source = mbMap?.getSource(SOURCE_SELECT);
42
43
  const feature = selectedFeature.clone();
43
44
  feature.setStyle(null);
44
45
 
@@ -27,6 +27,7 @@ import {
27
27
  WFS_STATIONS_TYPE,
28
28
  } from "../utils/constants";
29
29
  import useI18n from "../utils/hooks/useI18n";
30
+ import useLayerConfig from "../utils/hooks/useLayerConfig";
30
31
  import useMapContext from "../utils/hooks/useMapContext";
31
32
  import useRvfContext from "../utils/hooks/useRvfContext";
32
33
  import { fetchSharingWFS } from "../utils/sharingWFSUtils";
@@ -66,6 +67,7 @@ function RvfSharedMobilityLayerGroup(props: GroupOptions) {
66
67
  const { baseLayer, map } = useMapContext();
67
68
  const { setSharedMobilityLayerGroup } = useRvfContext();
68
69
  const { t } = useI18n();
70
+ const layerConfig = useLayerConfig(LAYERS_NAMES.sharedMobility);
69
71
 
70
72
  // Layers
71
73
  // const [bikeFreloLayer, setBikeFreloLayer] = useState<MaplibreStyleLayer>();
@@ -159,7 +161,6 @@ function RvfSharedMobilityLayerGroup(props: GroupOptions) {
159
161
  );
160
162
  },
161
163
  maplibreLayer: baseLayer,
162
- minZoom: 12,
163
164
  name: LAYERS_NAMES.bikeFrelo,
164
165
  styleLayersFilter: ({ metadata }) => {
165
166
  return metadata?.["rvf.filter"] === "bike.frelo";
@@ -314,14 +315,15 @@ function RvfSharedMobilityLayerGroup(props: GroupOptions) {
314
315
  scooter,
315
316
  hitchHiking,
316
317
  ],
318
+ minZoom: layerConfig?.minZoom || 15.5,
317
319
  name: LAYERS_NAMES.sharedMobility,
318
320
  ...props,
319
321
  } as GroupOptions);
320
- }, [baseLayer, props, t]);
322
+ }, [baseLayer, layerConfig?.minZoom, props, t]);
321
323
 
322
324
  const updateData = useCallback(() => {
323
325
  // Only update when layers are visible
324
- if (map?.getView()?.getZoom() < 15.5 || !group.getVisible()) {
326
+ if (map?.getView()?.getZoom() < group.getMinZoom() || !group.getVisible()) {
325
327
  return;
326
328
  }
327
329
  const abortController = new AbortController();
@@ -428,6 +430,39 @@ function RvfSharedMobilityLayerGroup(props: GroupOptions) {
428
430
  setSharedMobilityLayerGroup(group);
429
431
  }, [group, setSharedMobilityLayerGroup]);
430
432
 
433
+ // Override style layer zoom range to be able to display them at the right zoom level without modifying the style
434
+ // See TGSRVF-149
435
+ useEffect(() => {
436
+ if (layerConfig?.minZoom === undefined || !group) {
437
+ return;
438
+ }
439
+ const styleLayers = mbMap?.getStyle()?.layers;
440
+ const applyZoomRange = (evt) => {
441
+ group?.getLayersArray().forEach((layer: MaplibreStyleLayer) => {
442
+ evt.target
443
+ ?.getStyle()
444
+ ?.layers?.filter(layer.layersFilter)
445
+ .map((styleLayer) => {
446
+ return styleLayer.id;
447
+ })
448
+ .forEach((layerId: string) => {
449
+ if (evt.target?.getLayer(layerId)) {
450
+ evt.target.setLayerZoomRange(layerId, group.getMinZoom() - 1, 24);
451
+ }
452
+ });
453
+ });
454
+ };
455
+ if (!styleLayers) {
456
+ void mbMap?.once("idle", applyZoomRange);
457
+ return;
458
+ }
459
+ applyZoomRange({ target: mbMap });
460
+
461
+ return () => {
462
+ mbMap?.off("idle", applyZoomRange);
463
+ };
464
+ }, [mbMap, group, layerConfig?.minZoom]);
465
+
431
466
  useEffect(() => {
432
467
  if (!map || !group) {
433
468
  return;
@@ -16,6 +16,7 @@ export interface LayerConfig {
16
16
  show?: boolean;
17
17
  text?: string;
18
18
  };
19
+ minZoom?: number;
19
20
  title?: string;
20
21
  }
21
22
  export type LayersConfig = Record<string, LayerConfig>;