Namespace: reearth.clock
Description: This property represents the start time of the simulated clock within the scene that is currently loaded in the rearth
environment. The startTime
is essential for applications involving time-based simulations or animations, such as environmental monitoring, historical data visualization, future projections, or any scenario where the passage of time affects the displayed data. It is stored as a JavaScript Date
object, which provides a standard way to handle dates and times in JavaScript.
Syntax: reearth.clock.startTime: Date
Properties:
Date // Represents the beginning point in time for the current Reearth scene or simulation. It encapsulates the start time with full date and time precision
Example Usage
// Accessing the start time of the current Reearth scene
const simulationStart = reearth.clock.startTime;
// Display the start time in the console in a human-readable format
console.log("Simulation starts at:", simulationStart.toString());
// Using the start time to calculate durations or schedule future events
const now = new Date();
const timeSinceStart = now.getTime() - simulationStart.getTime();
console.log("Milliseconds since simulation start:", timeSinceStart);
// Explicitly state a date for the start time.
{startTime: new Date("2022-06-01"),}
Description: Represents the end time of the simulated clock that is currently active in the reearth
scene. The stopTime
is particularly important for defining the duration of time-based simulations or animations, such as tracking environmental changes, visualizing time-lapse data, or any scenario where temporal boundaries are needed to delimit the displayed information. This property is stored as a JavaScript Date
object, which is a standard format for handling dates and times.
Syntax: reearth.clock.stopTime: Date
Properties:
Date // Denotes the end point in time for the ongoing Reearth scene or simulation. It provides a precise endpoint for the time-based activities within the scene, marking the specific date and time at which these activities should halt.
Example Usage
// Accessing the stop time of the current Reearth scene
const simulationEnd = reearth.clock.stopTime;
// Logging the stop time to the console
console.log("Simulation ends at:", simulationEnd.toString());
// Using the stop time to calculate the remaining time in a simulation
const now = new Date();
const timeUntilEnd = simulationEnd.getTime() - now.getTime();
console.log("Milliseconds until simulation ends:", timeUntilEnd);
// Explicitly state a date for the stop time.
{stopTime: new Date("2022-06-03"),}
Description: This represents the current simulation time or the present moment within the context of an active reearth
scene. This method is integral to real-time or time-lapse simulations where tracking the passage of time is crucial for accurate data display and interaction, such as in live environmental monitoring, real-time asset tracking, or dynamic data visualization projects. This property is encapsulated as a JavaScript Date
object, offering a universally accepted method for managing date and time data.
Syntax: reearth.clock.currentTime: Date
Properties:
Date // Indicates the current time in the context of the Reearth scene or simulation, used to synchronize real-time data and animations.
Example Usage:
// Accessing the current time in the Reearth simulation
const currentSimulationTime = reearth.clock.currentTime;
// Displaying the current simulation time
console.log("Current simulation time:", currentSimulationTime.toISOString());
// Calculating the time elapsed since the start of the simulation
const simulationStart = reearth.clock.startTime;
const elapsed = currentSimulationTime.getTime() - simulationStart.getTime();
console.log("Elapsed time in milliseconds:", elapsed);
// Explicitly state a date for the current time.
{currentTime: new Date("2022-06-02"),}
Description: This method indicates whether a time-based simulation or animation within the scene is currently active and running. This status is crucial for controlling and monitoring the flow of time-dependent operations within the scene, such as animations, simulations, or any dynamic data visualizations that are tied to the passage of time.
Syntax: reearth.clock.playing: boolean
Properties:
boolean // Shows whether the simulation or animation is currently in play mode.
// true indicates that the simulation is actively progressing, driving all time-dependent activities within the scene.
// false shows that the simulation is stopped or paused, suspending any operations that depend on time advancement.
Example Usage:
// Check if the simulation is currently playing
if (reearth.clock.playing) {
console.log("The simulation is running.");
} else {
console.log("The simulation is paused.");
}
// Toggle the playing status of the clock based on a user action
function toggleClock() {
reearth.clock.playing = !reearth.clock.playing;
}
// Set the playing status to be false
reearth.clock.playing = false
// Set the playing status to be false within the clock object.
{playing: false,}
Description: Indicates whether the current time-based simulation or animation within the scene is in a paused state. This property is crucial for managing the playback of dynamic simulations, providing users with the ability to determine and control the pause state of activities. It also involves managing the progression of time-dependent functionalities such as simulations, animations, or any scheduled events within the environment.
Syntax: reearth.clock.paused: boolean
Properties:
boolean // Indicates whether the simulation or animation is currently paused.
// true indicates that the virtual clock is paused, halting the progression of all time-based operations within the scene.
// false signifies that the virtual clock is not paused, meaning time-dependent activities are ongoing.
Example Usage:
// Check if the simulation is paused
if (reearth.clock.paused) {
console.log("The simulation is currently paused.");
} else {
console.log("The simulation is active.");
}
// Function to pause or resume the clock based on user interaction
function togglePause() {
reearth.clock.paused = !reearth.clock.paused; // Toggle the paused state
}
Description: This method represents the rate at which time progresses in a simulation or in a reearth
scene compared to real-world time. This property allows users to adjust the speed of time-based simulations, making it possible to fast-forward through events or slow them down for detailed observation.
Syntax: reearth.clock.speed: number
Properties:
Number // Controls the simulation speed, where a value of 1 indicates real-time progression, values greater than 1 indicate a faster-than-real-time progression, values between 0 and 1 indicate a slower-than-real-time progression.
// The value is a multiplier applied to the normal flow of time. For example, a speed of 2 means time moves twice as fast as normal, and 0.5 means time moves at half the normal speed.
Example Usage:
// Setting the simulation speed to twice the normal speed
reearth.clock.speed = 2.0;
// Checking the current speed and adjusting if necessary
console.log("Current simulation speed:", reearth.clock.speed);
if (reearth.clock.speed !== 1.0) {
console.log("Adjusting speed to normal time.");
reearth.clock.speed = 1.0;
}
// Slowing down the simulation for detailed observation
reearth.clock.speed = 0.5;
console.log("Simulation is now at half the normal speed for detailed analysis.");
Description: This serves as a mechanism to advance the simulation's time by one tick and returns the new current time as a JavaScript Date
object. This method is critical for manually controlling the progression of time within simulations or interactive environments where precise increments of time advancement are necessary. The returned Date
object reflects the updated current time within the simulation or scene, allowing users to synchronize other components or operations with the simulation's timeline.
Syntax: reearth.clock.tick: () => Date
Properties:
Date //Advances the simulation's time by one tick and returns the updated current time as a Date object.
Example Usage:
// Function to advance the simulation time and log the new current time
function advanceTime() {
const newCurrentTime = reearth.clock.tick();
console.log("New current time after tick:", newCurrentTime.toISOString());
}
// Call the function to advance the time
advanceTime();
// Using the updated time to perform time-sensitive operations
function updateSimulation() {
const currentTime = reearth.clock.tick();
// Perform operations that depend on the current simulation time
console.log("Updated simulation elements to reflect the time at", currentTime.toString());
}
updateSimulation()
Description: This method is designed to start or resume the progression of time in a simulation or scene. This method is essential for controlling the flow of time-based simulations, enabling users to initiate or continue a simulation that was paused or not yet started. By invoking this method, users can ensure that all activities reliant on the passage of time are active, facilitating dynamic interactions and realistic simulations.
Syntax: reearth.clock.play: () => void;
Return Value: None (void
). The method does not require any input parameters and performs its operation without returning a value. Its primary function is to alter the state of the virtual clock from paused or stopped to running.
Example Usage:
// Function to start the simulation
function startSimulation() {
reearth.clock.play();
console.log("Simulation started. Time is now progressing.");
}
// Calling the function to start or resume the simulation
startSimulation();
// Button event handler to play simulation
document.getElementById('playButton').addEventListener('click', function() {
reearth.clock.play();
console.log("Simulation resumed.");
});
Description: This method is used to temporarily halt the progression of time in a simulation or scene, effectively pausing any time-based activities. Pausing the simulation is essential in scenarios where users need to stop and analyze specific details, interact with data points, or make adjustments without the distraction of ongoing movements or changes.
Syntax: reearth.clock.pause: () => void;
Return Value: None (void
). The method does not require any input parameters and performs its operation without returning a value. Its primary function is to change the state of the virtual clock from running to paused.
Example Usage:
// Function to pause the simulation
function pauseSimulation() {
reearth.clock.pause();
console.log("Simulation paused. Time progression has been halted.");
}
// Calling the function to pause the simulation
pauseSimulation();
// Button event handler to pause the simulation
document.getElementById('pauseButton').addEventListener('click', function() {
reearth.clock.pause();
console.log("User has paused the simulation.");
});
The Clock Object Full Use Case:
clock: {
startTime: new Date("2022-06-01"),
stopTime: new Date("2022-06-03"),
currentTime: new Date("2022-06-02"),
playing: false,
paused: true,
speed: 1,
play: () => {},
pause: () => {},
tick: () => new Date("2022-06-03"),
},