diff --git a/src/components/olmap/core/Controls/Timeline.tsx b/src/components/olmap/core/Controls/Timeline.tsx index e5a290d..02d15fb 100644 --- a/src/components/olmap/core/Controls/Timeline.tsx +++ b/src/components/olmap/core/Controls/Timeline.tsx @@ -33,6 +33,7 @@ import { useMap } from "../MapComponent"; import { formatTimelineTime, getRoundedCurrentTimelineMinutes, + getTimelineDisabledRangePercentages, normalizeTimelineMinutes, } from "./timelineTime"; @@ -109,6 +110,10 @@ const Timeline: React.FC = ({ minTime, maxTime, ); + const disabledRangePercentages = getTimelineDisabledRangePercentages( + minTime, + maxTime, + ); useEffect(() => { if (schemeDate) { setSelectedDate(schemeDate); @@ -945,22 +950,28 @@ const Timeline: React.FC = ({ /> {/* 禁用区域遮罩 */} {timeRange && ( - <> + {/* 左侧禁用区域 */} {minTime > 0 && ( )} @@ -969,19 +980,16 @@ const Timeline: React.FC = ({ )} - + )} diff --git a/src/components/olmap/core/Controls/timelineTime.test.ts b/src/components/olmap/core/Controls/timelineTime.test.ts index 2928845..b55cae7 100644 --- a/src/components/olmap/core/Controls/timelineTime.test.ts +++ b/src/components/olmap/core/Controls/timelineTime.test.ts @@ -1,6 +1,7 @@ import { formatTimelineTime, getRoundedCurrentTimelineMinutes, + getTimelineDisabledRangePercentages, normalizeTimelineMinutes, } from "./timelineTime"; @@ -18,4 +19,12 @@ describe("timelineTime", () => { it("rounds the current time down to the timeline step", () => { expect(getRoundedCurrentTimelineMinutes(new Date("2026-07-16T10:29:00"))).toBe(615); }); + + it("calculates disabled range as full-day percentages", () => { + expect(getTimelineDisabledRangePercentages(360, 1080)).toEqual({ + leftWidth: 25, + rightLeft: 75, + rightWidth: 25, + }); + }); }); diff --git a/src/components/olmap/core/Controls/timelineTime.ts b/src/components/olmap/core/Controls/timelineTime.ts index 42f17b0..7c2438c 100644 --- a/src/components/olmap/core/Controls/timelineTime.ts +++ b/src/components/olmap/core/Controls/timelineTime.ts @@ -30,3 +30,18 @@ export const formatTimelineTime = ( .toString() .padStart(2, "0")}`; }; + +export const getTimelineDisabledRangePercentages = ( + minTime: number, + maxTime: number, +) => { + const rangeStart = normalizeTimelineMinutes(minTime); + const rangeEnd = normalizeTimelineMinutes(maxTime); + + return { + leftWidth: (rangeStart / TIMELINE_MINUTES_PER_DAY) * 100, + rightLeft: (rangeEnd / TIMELINE_MINUTES_PER_DAY) * 100, + rightWidth: + ((TIMELINE_MINUTES_PER_DAY - rangeEnd) / TIMELINE_MINUTES_PER_DAY) * 100, + }; +};