import { schedule, addFrameTask } from "@arcgis/core/core/scheduling.js";const { schedule, addFrameTask } = await $arcgis.import("@arcgis/core/core/scheduling.js");- Since
- ArcGIS Maps SDK for JavaScript 4.7
Various utilities and convenience functions for executing code at various phases of browser frames. The scheduling module allows you to register tasks that are executed in every animation frame. This can be used to synchronize updates with ongoing animations of the view, or to animate the view manually by adjusting the extent or camera in every frame.
// Animate the scene view camera heading in every framelet handle = scheduling.addFrameTask({ update: function() { let camera = view.camera.clone(); camera.heading += 0.2; view.camera = camera; }});
// Remove frame task as soon as the user starts navigating in the viewreactiveUtils.whenOnce(() => view.navigating, () => handle.remove());Type definitions
PhaseEvent
An object with timing information.
elapsedFrameTime
- Type
- number
The amount of time spent within the current animation frame. This can be used for budgeting (e.g. some tasks may already have run).
PhaseCallbacks
A set of callbacks that will be called at specific phases of the animation frame.
PhaseCallback
A function called at a specific phase of the animation frame.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| event | An object with timing information. | |
- Returns
- void
FrameTaskHandle
An object to remove or pause a frame task registered with addFrameTask().
pause
- Signature
-
pause (): void
Pause the execution the frame task at every frame.
- Returns
- void
Functions
schedule
Schedules the execution of a callback function at the next web browser tick.
Unlike addFrameTask(), a scheduled callback will only run
once. Scheduling a task for the next execution tick can be useful when you
want to throttle/accumulate functionality over a single javascript execution
context.
- Signature
-
schedule (callback: () => void): ResourceHandle
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| callback | () => void | The function to call at the next tick. | |
- Returns
- ResourceHandle
Returns an scheduling handler with a
remove()method that can be called to prevent the callback to be called at the next tick.Property Type Description remove Function When called, removes the callback from the callbacks queue.
- Example
- // Use scheduling.schedule to log an error message at most once per ticklet logErrorHandle;function logError(error) {if (!logErrorHandle) {logErrorHandle = scheduling.schedule(function() {console.error(error);logErrorHandle = null;});}});
addFrameTask
Registers a frame task. An animation frame is composed of different phases to let various actors execute code before, after, or during the rendering of MapView or SceneView.
- Signature
-
addFrameTask (phases: PhaseCallbacks): FrameTaskHandle
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| phases | The callbacks for each phase of the frame. | |
- Returns
- FrameTaskHandle
A handle to remove, pause, or resume the frame task.
- Example
- // Animate the scene view camera heading in every framelet handle = scheduling.addFrameTask({update: function() {let camera = view.camera.clone();camera.heading += 0.2;view.camera = camera;}});// Remove frame task as soon as the user starts navigating in the viewreactiveUtils.whenOnce(() => view.navigating, () => handle.remove());