Merge pull request #12 from witelgroup/feature/debug_cluster_tollhouse
Feature/debug cluster tollhouse
This commit is contained in:
@@ -20,30 +20,50 @@ const PointsOnMap = ({ data, isCluster }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const markers = useMemo(() => {
|
const markers = useMemo(() => {
|
||||||
return data.map(({ id, lat, lng, step }) => (
|
return data.map(({ id, lat, lng, step }) => {
|
||||||
<CircleMarker
|
if (!lat && !lng) return;
|
||||||
key={id}
|
return (
|
||||||
center={L.latLng(Number(lat), Number(lng))}
|
<CircleMarker
|
||||||
radius={8}
|
key={id}
|
||||||
eventHandlers={{
|
center={L.latLng(Number(lat), Number(lng))}
|
||||||
click: () => {
|
radius={8}
|
||||||
openDialog();
|
eventHandlers={{
|
||||||
setSelectedId(id);
|
click: () => {
|
||||||
},
|
openDialog();
|
||||||
}}
|
setSelectedId(id);
|
||||||
color={getMarkerColor(Number(status))}
|
},
|
||||||
/>
|
}}
|
||||||
));
|
color={getMarkerColor(Number(status))}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
}, [data, theme]);
|
}, [data, theme]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data.length === 0) return;
|
if (data.length === 0) {
|
||||||
|
// fly to Iran
|
||||||
|
map.flyTo([32.4279, 53.688], 6, { duration: 0.7 });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const bounds = L.latLngBounds(
|
// ساختن bounds با حذف مواردی که lat/lng ندارند
|
||||||
data.map(({ lat, lng }) => {
|
const validPoints = data
|
||||||
return L.latLng(Number(lat), Number(lng));
|
.filter(({ lat, lng }) => lat && lng)
|
||||||
})
|
.map(({ lat, lng }) => L.latLng(Number(lat), Number(lng)));
|
||||||
);
|
|
||||||
|
if (validPoints.length === 0) {
|
||||||
|
// اگر هیچ مختصات معتبری نبود → ایران
|
||||||
|
map.flyTo([32.4279, 53.688], 6, { duration: 0.7 });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bounds = L.latLngBounds(validPoints);
|
||||||
|
|
||||||
|
if (!bounds.isValid()) {
|
||||||
|
// اگر bounds معتبر نبود → fallback روی ایران
|
||||||
|
map.flyTo([32.4279, 53.688], 6, { duration: 0.7 });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
map.flyToBounds(bounds, { duration: 0.7 });
|
map.flyToBounds(bounds, { duration: 0.7 });
|
||||||
}, [data]);
|
}, [data]);
|
||||||
|
|||||||
Reference in New Issue
Block a user