This repository has been archived by the owner on Apr 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a basic timeline UI (#232)
* enhance timeline properties * add timeline * fix * update property
- Loading branch information
Showing
3 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/components/molecules/Visualizer/Engine/Cesium/core/Clock.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ClockRange, ClockStep, JulianDate } from "cesium"; | ||
import React, { useEffect, useMemo } from "react"; | ||
import { Clock, useCesium } from "resium"; | ||
|
||
import type { SceneProperty } from "../../ref"; | ||
|
||
export type Props = { | ||
property?: SceneProperty; | ||
}; | ||
|
||
export default function ReearthClock({ property }: Props): JSX.Element | null { | ||
const { animation, visible, start, stop, current, stepType, rangeType, multiplier, step } = | ||
property?.timeline ?? {}; | ||
const startTime = useMemo(() => (start ? JulianDate.fromIso8601(start) : undefined), [start]); | ||
const stopTime = useMemo(() => (stop ? JulianDate.fromIso8601(stop) : undefined), [stop]); | ||
const currentTime = useMemo( | ||
() => (current ? JulianDate.fromIso8601(current) : undefined), | ||
[current], | ||
); | ||
const clockStep = | ||
stepType === "fixed" ? ClockStep.TICK_DEPENDENT : ClockStep.SYSTEM_CLOCK_MULTIPLIER; | ||
const clockMultiplier = stepType === "fixed" ? step ?? 1 : multiplier ?? 1; | ||
|
||
const { viewer } = useCesium(); | ||
useEffect(() => { | ||
if (!viewer) return; | ||
if (viewer.animation?.container) { | ||
(viewer.animation.container as HTMLDivElement).style.visibility = visible | ||
? "visible" | ||
: "hidden"; | ||
} | ||
if (viewer.timeline?.container) { | ||
(viewer.timeline.container as HTMLDivElement).style.visibility = visible | ||
? "visible" | ||
: "hidden"; | ||
} | ||
viewer.forceResize(); | ||
}, [viewer, visible]); | ||
|
||
return ( | ||
<Clock | ||
shouldAnimate={animation} | ||
startTime={startTime} | ||
stopTime={stopTime} | ||
currentTime={currentTime} | ||
clockStep={clockStep} | ||
multiplier={clockMultiplier} | ||
clockRange={rangeType ? rangeTypes[rangeType] : undefined} | ||
/> | ||
); | ||
} | ||
|
||
const rangeTypes = { | ||
unbounded: ClockRange.UNBOUNDED, | ||
clamped: ClockRange.CLAMPED, | ||
bounced: ClockRange.LOOP_STOP, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters