feat: Cycle included area segments by recency
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -314,6 +314,8 @@ function Menu({data, duration, setDuration, end, setEnd, slider, setSlider, subm
|
|||||||
const scrollPositionRef = useRef(0);
|
const scrollPositionRef = useRef(0);
|
||||||
const [lastDrawnItemsForExclusion, setLastDrawnItemsForExclusion] = useState(null);
|
const [lastDrawnItemsForExclusion, setLastDrawnItemsForExclusion] = useState(null);
|
||||||
const [exclusionCycleIndex, setExclusionCycleIndex] = useState(0);
|
const [exclusionCycleIndex, setExclusionCycleIndex] = useState(0);
|
||||||
|
const [lastDrawnItemsForInclusion, setLastDrawnItemsForInclusion] = useState(null);
|
||||||
|
const [inclusionCycleIndex, setInclusionCycleIndex] = useState(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const container = scrollContainerRef.current;
|
const container = scrollContainerRef.current;
|
||||||
@@ -497,8 +499,8 @@ function Menu({data, duration, setDuration, end, setEnd, slider, setSlider, subm
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
let minTime = null;
|
const goodSegments = [];
|
||||||
let maxTime = null;
|
let currentSegment = null;
|
||||||
|
|
||||||
for (const point of data) {
|
for (const point of data) {
|
||||||
if (!point || typeof point.lat !== 'number' || typeof point.lon !== 'number' || !point.time) {
|
if (!point || typeof point.lat !== 'number' || typeof point.lon !== 'number' || !point.time) {
|
||||||
@@ -508,23 +510,45 @@ function Menu({data, duration, setDuration, end, setEnd, slider, setSlider, subm
|
|||||||
const isInside = isInsideInclusionZone(point.lat, point.lon);
|
const isInside = isInsideInclusionZone(point.lat, point.lon);
|
||||||
|
|
||||||
if (isInside) {
|
if (isInside) {
|
||||||
if (minTime === null || point.time < minTime) {
|
if (!currentSegment) {
|
||||||
minTime = point.time;
|
currentSegment = { start: point.time, end: point.time };
|
||||||
|
} else {
|
||||||
|
currentSegment.end = point.time;
|
||||||
}
|
}
|
||||||
if (maxTime === null || point.time > maxTime) {
|
} else {
|
||||||
maxTime = point.time;
|
if (currentSegment) {
|
||||||
|
goodSegments.push(currentSegment);
|
||||||
|
currentSegment = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minTime === null) {
|
if (currentSegment) {
|
||||||
|
goodSegments.push(currentSegment);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!goodSegments.length) {
|
||||||
alert("No data points found inside the selected area(s).");
|
alert("No data points found inside the selected area(s).");
|
||||||
setSubmenu(false);
|
setSubmenu(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const startUnix = moment(minTime).unix();
|
goodSegments.sort((a, b) => moment(b.end).diff(moment(a.end)));
|
||||||
const endUnix = moment(maxTime).unix();
|
|
||||||
|
const drawnItemsKey = JSON.stringify(drawnItems.map(item => item.bounds.toBBoxString()).sort());
|
||||||
|
|
||||||
|
let newIndex = 0;
|
||||||
|
if (lastDrawnItemsForInclusion === drawnItemsKey) {
|
||||||
|
newIndex = (inclusionCycleIndex + 1) % goodSegments.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
setLastDrawnItemsForInclusion(drawnItemsKey);
|
||||||
|
setInclusionCycleIndex(newIndex);
|
||||||
|
|
||||||
|
const segmentToSelect = goodSegments[newIndex];
|
||||||
|
|
||||||
|
const startUnix = moment(segmentToSelect.start).unix();
|
||||||
|
const endUnix = moment(segmentToSelect.end).unix();
|
||||||
const endOfWindowUnix = end.unix();
|
const endOfWindowUnix = end.unix();
|
||||||
|
|
||||||
const newSliderStart = Math.floor((startUnix - endOfWindowUnix) / duration.secs + duration.num);
|
const newSliderStart = Math.floor((startUnix - endOfWindowUnix) / duration.secs + duration.num);
|
||||||
|
|||||||
Reference in New Issue
Block a user