asdfaf
This commit is contained in:
@@ -9,6 +9,7 @@ const MowingExecutionModal = ({ plan, onClose, onComplete }) => {
|
|||||||
const [tracking, setTracking] = useState(false);
|
const [tracking, setTracking] = useState(false);
|
||||||
const [isPaused, setIsPaused] = useState(false);
|
const [isPaused, setIsPaused] = useState(false);
|
||||||
const [gpsTrack, setGpsTrack] = useState([]);
|
const [gpsTrack, setGpsTrack] = useState([]);
|
||||||
|
const [mapCenter, setMapCenter] = useState(null);
|
||||||
const [currentLocation, setCurrentLocation] = useState(null);
|
const [currentLocation, setCurrentLocation] = useState(null);
|
||||||
const [currentSpeed, setCurrentSpeed] = useState(0);
|
const [currentSpeed, setCurrentSpeed] = useState(0);
|
||||||
const [previousLocation, setPreviousLocation] = useState(null);
|
const [previousLocation, setPreviousLocation] = useState(null);
|
||||||
@@ -24,11 +25,35 @@ const MowingExecutionModal = ({ plan, onClose, onComplete }) => {
|
|||||||
const load = async () => {
|
const load = async () => {
|
||||||
try {
|
try {
|
||||||
const r = await mowingAPI.getPlan(plan.id);
|
const r = await mowingAPI.getPlan(plan.id);
|
||||||
setSections(r.data.data.sections || []);
|
const secs = r.data.data.sections || [];
|
||||||
} catch {}
|
setSections(secs);
|
||||||
|
if (!secs.length && plan.property_id) {
|
||||||
|
// Fallback: fetch sections from property
|
||||||
|
const pr = await propertiesAPI.getById(plan.property_id);
|
||||||
|
const propSecs = pr.data?.data?.property?.sections || [];
|
||||||
|
setSections(propSecs);
|
||||||
|
computeCenter(propSecs);
|
||||||
|
} else {
|
||||||
|
computeCenter(secs);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
try {
|
||||||
|
if (plan.property_id) {
|
||||||
|
const pr = await propertiesAPI.getById(plan.property_id);
|
||||||
|
const propSecs = pr.data?.data?.property?.sections || [];
|
||||||
|
setSections(propSecs);
|
||||||
|
computeCenter(propSecs);
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const computeCenter = (secs) => {
|
||||||
|
let totalLat=0,totalLng=0,count=0;
|
||||||
|
secs.forEach(s=>{ let poly=s.polygonData || s.polygon_data; if (typeof poly==='string'){ try{poly=JSON.parse(poly);}catch{return;} } if (poly?.coordinates?.[0]){ poly.coordinates[0].forEach(([lat,lng])=>{ totalLat+=lat; totalLng+=lng; count++;});}});
|
||||||
|
if (count) setMapCenter([totalLat/count, totalLng/count]); else setMapCenter(null);
|
||||||
};
|
};
|
||||||
load();
|
load();
|
||||||
}, [plan?.id]);
|
}, [plan?.id, plan?.property_id]);
|
||||||
|
|
||||||
const toRad = (d) => (d * Math.PI) / 180;
|
const toRad = (d) => (d * Math.PI) / 180;
|
||||||
const haversineMeters = (a, b) => {
|
const haversineMeters = (a, b) => {
|
||||||
@@ -110,8 +135,7 @@ const MowingExecutionModal = ({ plan, onClose, onComplete }) => {
|
|||||||
|
|
||||||
useEffect(() => () => { if (watchId) navigator.geolocation.clearWatch(watchId); releaseWakeLock(); }, [watchId]);
|
useEffect(() => () => { if (watchId) navigator.geolocation.clearWatch(watchId); releaseWakeLock(); }, [watchId]);
|
||||||
|
|
||||||
const center = (() => {
|
const center = mapCenter;
|
||||||
let totalLat=0,totalLng=0,count=0; sections.forEach(s=>{ let poly=s.polygonData; if (typeof poly==='string'){ try{poly=JSON.parse(poly);}catch{return;} } if (poly?.coordinates?.[0]){ poly.coordinates[0].forEach(([lat,lng])=>{ totalLat+=lat; totalLng+=lng; count++;});}}); return count? [totalLat/count, totalLng/count]: null; })();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
|
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
|
||||||
|
|||||||
Reference in New Issue
Block a user