@geops/rvf-mobility-web-component 0.1.98 → 0.1.100

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.98",
5
+ "version": "0.1.100",
6
6
  "homepage": "https://rvf-mobility-web-component-geops.vercel.app/",
7
7
  "type": "module",
8
8
  "main": "index.js",
@@ -4,7 +4,6 @@ import { memo, useEffect, useMemo, useState } from "preact/compat";
4
4
 
5
5
  import I18n from "../I18n";
6
6
  import SituationDetails from "../SituationDetails";
7
- import useI18n from "../utils/hooks/useI18n";
8
7
 
9
8
  import MobilityNotificationsAttributes from "./MobilityNotificationsAttributes";
10
9
 
@@ -39,21 +38,15 @@ function MobilityNotifications({
39
38
  notificationurl,
40
39
  }: MobilityNotificationsProps) {
41
40
  const [situations, setSituations] = useState<SituationType[]>([]);
42
- const { locale } = useI18n();
43
41
 
44
42
  // Define fallback languages from the notificationlang attribute
45
43
  const fallbackLangs = useMemo(() => {
46
44
  return (
47
- notificationlang
48
- ?.split(",")
49
- .map((l) => {
50
- return l.trim();
51
- })
52
- .filter((l) => {
53
- return l !== locale();
54
- }) || []
45
+ notificationlang?.split(",").map((l) => {
46
+ return l.trim();
47
+ }) || []
55
48
  );
56
- }, [locale, notificationlang]);
49
+ }, [notificationlang]);
57
50
 
58
51
  useEffect(() => {
59
52
  new MocoAPI({
@@ -15,27 +15,34 @@ const applyInitialLayerVisibility = (
15
15
  const name = layer.get("name");
16
16
  const shouldBeVisible = names.includes(name);
17
17
  if (layer.getVisible() !== shouldBeVisible) {
18
+ // If the layer is a group we apply the visibility to its sublayers,
19
+ // not the group itself. Group should not appear in permalink layers param
18
20
  if ((layer as Group).getLayers) {
19
21
  (layer as Group)
20
22
  .getLayers()
21
23
  .getArray()
22
24
  .forEach((subLayer) => {
23
- subLayer.setVisible(shouldBeVisible);
24
- // applyInitialLayerVisibility(layersAttrValue, subLayer);
25
+ applyInitialLayerVisibility(layersAttrValue, subLayer);
25
26
  });
26
27
  } else {
27
28
  layer.setVisible(shouldBeVisible);
28
29
  }
29
30
  }
30
31
  }
32
+
33
+ // if the layer is a group we set it to false if all its sublayers are false
31
34
  if ((layer as Group).getLayers) {
32
- (layer as Group)
33
- .getLayers()
34
- .getArray()
35
- .forEach((subLayer) => {
36
- // subLayer.setVisible(false);
37
- applyInitialLayerVisibility(layersAttrValue, subLayer);
38
- });
35
+ if (
36
+ layer.getVisible() &&
37
+ !(layer as Group)
38
+ .getLayers()
39
+ ?.getArray()
40
+ .find((l) => {
41
+ return l.getVisible();
42
+ })
43
+ ) {
44
+ layer.setVisible(false);
45
+ }
39
46
  }
40
47
  };
41
48
  export default applyInitialLayerVisibility;
@@ -7,7 +7,7 @@ import applyInitialLayerVisibility from "../applyInitialLayerVisibility";
7
7
  import useInitialPermalink from "./useInitialPermalink";
8
8
 
9
9
  import type { Map } from "ol";
10
- // import type { Group } from "ol/layer";
10
+
11
11
  const useInitialLayersVisiblity = (
12
12
  map: Map,
13
13
  layers: string,
@@ -39,29 +39,11 @@ const useInitialLayersVisiblity = (
39
39
  const layersAsArray = getLayersAsFlatArray(
40
40
  map.getLayers().getArray(),
41
41
  ).reverse();
42
+
42
43
  layersAsArray.forEach((layer) => {
43
44
  applyInitialLayerVisibility(layersToUse, layer);
44
45
  });
45
46
 
46
- // Hide group if there is no children visible
47
- // layersAsArray
48
- // .filter((l) => {
49
- // return (l as Group).getLayers;
50
- // })
51
- // .forEach((layer) => {
52
- // if (
53
- // layer.getVisible() &&
54
- // !(layer as Group)
55
- // .getLayers()
56
- // ?.getArray()
57
- // .some((l) => {
58
- // return l.getVisible();
59
- // })
60
- // ) {
61
- // layer.setVisible(false);
62
- // }
63
- // });
64
-
65
47
  const key = map.getLayers().on("add", (event) => {
66
48
  applyInitialLayerVisibility(layersToUse, event.element);
67
49
  });