@geops/rvf-mobility-web-component 0.1.57 → 0.1.59

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.57",
5
+ "version": "0.1.59",
6
6
  "homepage": "https://rvf-mobility-web-component-geops.vercel.app/",
7
7
  "type": "module",
8
8
  "main": "index.js",
@@ -1,3 +1,4 @@
1
+ import { unByKey } from "ol/Observable";
1
2
  import { useEffect, useMemo, useState } from "preact/hooks";
2
3
  import { LiaMapSolid } from "react-icons/lia";
3
4
  import { twMerge } from "tailwind-merge";
@@ -17,25 +18,21 @@ function RvfMainLinkButton({
17
18
  const [z, setZ] = useState(0);
18
19
 
19
20
  useEffect(() => {
20
- if (!map) {
21
- return;
22
- }
23
- const view = map.getView();
24
- if (!view) {
25
- return;
26
- }
27
- const update = () => {
28
- const center = view.getCenter();
21
+ const update = (evt) => {
22
+ const center = evt.map?.getView()?.getCenter();
29
23
  if (center) {
30
24
  setX(center[0]);
31
25
  setY(center[1]);
32
26
  }
33
- setZ(view.getZoom() || 0);
27
+ const zoom = evt.map?.getView()?.getZoom();
28
+ if (zoom) {
29
+ setZ(zoom);
30
+ }
34
31
  };
35
- update();
36
- map.on("moveend", update);
32
+ update({ map });
33
+ const key = map?.on("moveend", update);
37
34
  return () => {
38
- map.un("moveend", update);
35
+ unByKey(key);
39
36
  };
40
37
  }, [map]);
41
38