diff --git a/src/atomicui/molecules/Marker/Marker.tsx b/src/atomicui/molecules/Marker/Marker.tsx index 31e77070..6f1ccc41 100644 --- a/src/atomicui/molecules/Marker/Marker.tsx +++ b/src/atomicui/molecules/Marker/Marker.tsx @@ -24,7 +24,7 @@ const Marker: FC = ({ latitude, longitude, searchValue, setSearchValue }) if (!info) { (async () => { const place: ReverseGeocodeCommandOutput | undefined = await getPlaceDataByCoordinates([longitude, latitude]); - setInfo({ id: uuid.randomUUID(), place: place!.ResultItems![0] }); + !!place?.ResultItems?.length && setInfo({ id: uuid.randomUUID(), place: place.ResultItems[0] }); })(); } }, [info, getPlaceDataByCoordinates, longitude, latitude, marker, selectedMarker, setMarker]); diff --git a/src/hooks/useMapManager.ts b/src/hooks/useMapManager.ts index 86128548..89a9efc2 100644 --- a/src/hooks/useMapManager.ts +++ b/src/hooks/useMapManager.ts @@ -3,7 +3,7 @@ import { MutableRefObject, useCallback, useEffect, useMemo, useState } from "rea import { showToast } from "@demo/core/Toast"; import { appConfig, regionsData } from "@demo/core/constants"; import { MapStyleEnum, ToastType } from "@demo/types/Enums"; -import { getStyleWithPreferredLanguage } from "@demo/utils"; +import { getStyleWithPreferredLanguage, normalizeLng } from "@demo/utils"; import { getCurrentLocation } from "@demo/utils/getCurrentLocation"; import type { GeolocateControl as GeolocateControlRef } from "maplibre-gl"; import { omit } from "ramda"; @@ -148,9 +148,10 @@ const useMapManager = ({ const handleMapClick = useCallback( ({ lngLat }: MapLayerMouseEvent) => { - if (lngLat && !isUnauthGeofenceBoxOpen && !isUnauthTrackerBoxOpen) { - const { lat: latitude, lng: longitude } = lngLat; + const { lng, lat: latitude } = lngLat; + const longitude = normalizeLng(lng); + if (!isUnauthGeofenceBoxOpen && !isUnauthTrackerBoxOpen) { if (!isRouteBoxOpen && !isAuthGeofenceBoxOpen && !isSettingsOpen && !isEditingRoute) { marker && setMarker(undefined); selectedMarker && setSelectedMarker(undefined); diff --git a/src/utils/index.ts b/src/utils/index.ts index c23411d6..5dc4f404 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -15,3 +15,4 @@ export * from "./distanceUtil"; export * from "./turfUtils"; export * from "./getFlagEmoji"; export * from "./getStyleWithPreferredLanguage"; +export * from "./normalizeLng"; diff --git a/src/utils/normalizeLng.ts b/src/utils/normalizeLng.ts new file mode 100644 index 00000000..7eb3cc8a --- /dev/null +++ b/src/utils/normalizeLng.ts @@ -0,0 +1 @@ +export const normalizeLng = (lng: number) => ((((lng + 180) % 360) + 360) % 360) - 180; // Normalize to [-180, 180];