diff --git a/src/components/infrastructure/tollHouseMap/PointsOnMap/index.jsx b/src/components/infrastructure/tollHouseMap/PointsOnMap/index.jsx index 05b4d03..2cdd91c 100644 --- a/src/components/infrastructure/tollHouseMap/PointsOnMap/index.jsx +++ b/src/components/infrastructure/tollHouseMap/PointsOnMap/index.jsx @@ -20,8 +20,9 @@ const PointsOnMap = ({ data, isCluster }) => { }; const markers = useMemo(() => { - return data.map(({ id, lat, lng, step }) => ( - { + if (!lat && !lng) return + return { }, }} color={getMarkerColor(Number(status))} - /> - )); + />; + }); }, [data, theme]); useEffect(() => { - if (data.length === 0) return; + if (data.length === 0) { + // fly to Iran + map.flyTo([32.4279, 53.6880], 6, { duration: 0.7 }); + return; + } - const bounds = L.latLngBounds( - data.map(({ lat, lng }) => { - return L.latLng(Number(lat), Number(lng)); - }) - ); + // ساختن bounds با حذف مواردی که lat/lng ندارند + const validPoints = data + .filter(({ lat, lng }) => lat && lng) + .map(({ lat, lng }) => L.latLng(Number(lat), Number(lng))); + + if (validPoints.length === 0) { + // اگر هیچ مختصات معتبری نبود → ایران + map.flyTo([32.4279, 53.6880], 6, { duration: 0.7 }); + return; + } + + const bounds = L.latLngBounds(validPoints); + + if (!bounds.isValid()) { + // اگر bounds معتبر نبود → fallback روی ایران + map.flyTo([32.4279, 53.6880], 6, { duration: 0.7 }); + return; + } map.flyToBounds(bounds, { duration: 0.7 }); + }, [data]); + const createClusterCustomIcon = (cluster) => { const count = cluster.getChildCount(); return L.divIcon({