Atlaslog
Atlaslog / deck.gl / API / transitions
deck.gl · API reference

transitions

Quick answer

deck.gl provides several built-in animation/transition features.

Last verified 2026-11-03 · deck.gl 9.0 · Cite this page
Runnable examplesChinese noteAll API topics

deck.gl provides several built-in animation/transition features.

Advanced motion effects can also be implemented using deck.gl in conjunction with other animation libraries, see the custom animations section.

Camera Transitions​

Camera transitions provide smooth and visually appealing transitions when viewState change from one state to the other.

Transitions are performed when setting Deck's viewState or initialViewState prop to a new value with the following additional fields:

Camera Transition Examples​

This example provides flyTo style transition to move camera from current location to the requested city.

import {Deck, FlyToInterpolator} from '@deck.gl/core';

const CITIES = {
SF: {
longitude: -122.4,
latitude: 37.8,
zoom: 10
},
NYC: {
longitude: -74.0,
latitude: 40.7,
zoom: 10
}
}

const deckInstance = new Deck({
initialViewState: CITIES.SF,
controller: true
});

for (const button of document.querySelectorAll('button')) {
button.onclick = () => flyToCity(button.id);
}

function flyToCity(name) {
deckInstance.setProps({
initialViewState: {
...CITIES[name],
transitionInterpolator: new FlyToInterpolator({speed: 2}),
transitionDuration: 'auto'
}
})
}

This example continuously rotates the camera along the Z (vertical) axis until user interrupts the rotation by dragging. It uses LinearInterpolator and restricts transitions to bearing. Continuous transitions are achieved by triggering new transitions upon the onTransitionEnd callback.

import {Deck, LinearInterpolator} from '@deck.gl/core';

let initialViewState = {
longitude: -122.4,
latitude: 37.8,
zoom: 12
};

const deckInstance = new Deck({
initialViewState,
controller: true,
onLoad: rotateCamera
});

function rotateCamera() {
initialViewState = {
...initialViewState,
bearing: initialViewState.bearing + 120,
transitionDuration: 1000,
transitionInterpolator: new LinearInterpolator(['bearing']),
onTransitionEnd: rotateCamera
};
deckInstance.setProps({initialViewState});
}

Remarks​

Deck's view state transition model is "set and forget": the values of the following props at the start of a transition carry through the entire duration of the transition:

The default transition behavior can always be intercepted and overwritten in the handler for onViewStateChange. However, if a transition is in progress, the properties that are being transitioned (e.g. longitude and latitude) should not be manipulated, otherwise the change will be interpreted as an interruption of the transition.

Layer Prop Transitions​

Layer properties may smoothly transition from one value to the next if a transitions prop is configured. There are two categories of transition-enabled props, for each enabling transition has different implications regarding performance and complexity.

To enable layer prop transitions, set the layer's transitions prop to an object that defines animation parameters by using the prop names as keys. The following example has the columns "grow" from the ground when data is loaded:

import {Deck} from '@deck.gl/core';
import {HexagonLayer} from '@deck.gl/aggregation-layers';

const deckInstance = new Deck({
// ...
layer: getLayers(null)
});

const resp = await fetch('/path/to/data.json');
const data = await resp.json();
deckInstance.setProps({
layer: getLayers(data)
});

function getLayers(data) {
return [
new HexagonLayer({
id: '3d-heatmap',
data,
getPosition: d => [d.longitude, d.latitude],
getElevationWeight: d => d.count,
extruded: true,
elevationScale: data && data.length ? 50 : 0,
transitions: {
elevationScale: 3000
}
})
];
}

In the transitions object, each prop name is mapped to a number or an object that is the transition setting. As a shorthand, if a prop name maps to a number, then the number is assigned to the duration parameter with an interpolation type transition. If an object is supplied, it may contain the following fields:

KeyTypeDefaultDescription
typestring'interpolation'Type of the transition, currently supports 'interpolation' and 'spring'
enterFunctionvalue => valueCallback to get the value that the entering vertices are transitioning from. See "attribute backfilling" below
onStartFunctionnullCallback when the transition is started
onEndFunctionnullCallback when the transition is done
onInterruptFunctionnullCallback when the transition is interrupted

Attribute Backfilling​

Consider the following setup, a ScatterplotLayer with transitions enabled for positions and fill colors:

import {ScatterplotLayer} from '@deck.gl/layers';
import type {Color} from '@deck.gl/core';

new ScatterplotLayer({
// ...
transitions: {
getPosition: {
type: 'spring',
damping: 0.2
},
getFillColor: {
duration: 600,
easing: (x: number) => -(Math.cos(Math.PI * x) - 1) / 2, // ease-in-out-sine
entry: ([r, g, b]: Color) => [r, g, b, 0]
}
}
});

When the layer's data updates from 3 elements to 4 elements, positions and colors also changed:

Object indexOld getPosition resultNew getPosition resultOld getFillColor resultNew getFillColor result
0[0, 0, 0][0, 3, 0][255, 0, 0, 255][255, 255, 0, 255]
1[1, 0, 0][0, 0, 0][0, 255, 0, 255][255, 0, 0, 255]
2[2, 0, 0][1, 0, 0][0, 0, 255, 255][0, 255, 0, 255]
3-[2, 0, 0]-[0, 0, 255, 255]

When working with variable-length geometries, such as PathLayer and PolygonLayer, transitions are handled per geometry (path or polygon). For each geometry, transitions are performed between the old and new values at the same vertex index. If the new path/polygon has more vertices, enter is called to backfill the "from" value. In this case, enter also receives a second argument fromChunk representing the "from" value of the entire geometry.

The process of attribute backfilling may be expensive performance-wise because it calls enter for each index on the CPU, then upload the new data to the GPU. It only happens when data size/vertex count is growing.

Limitations​

Between updates, objects are identified by their index in the data array. This means that if objects are inserted or removed, the transition will not look as expected. There is an open feature request for supporting custom object id.

Custom Animations​

The most powerful way to create animations with deck.gl is to manage data and settings externally, and update the layers' props on every frame.

The following example shows the TripsLayer's currentTime prop animated by the popmotion library:

import {Deck} from '@deck.gl/core';
import {TripsLayer} from '@deck.gl/geo-layers';
import {animate} from "popmotion";

const currentTimeAnimation = animate({
from: 0, // currentTime min value
to: 1800, // currentTime max value
duration: 5000, // over the course of 5 seconds
repeat: Infinity,
onUpdate: updateLayers
});

const deckInstance = new Deck({
initialViewState: {
longitude: -122.4,
latitude: 37.8,
zoom: 12
},
controller: true
});

function updateLayers(currentTime) {
const layers = [
new TripsLayer({
id: 'TripsLayer',
data: '/path/to/data.json',
getPath: d => d.waypoints.map(p => p.coordinates),
getTimestamps: d => d.waypoints.map(p => p.timestamp),
getColor: [253, 128, 93],
getWidth: 50,

currentTime,
trailLength: 600
})
];

deckInstance.setProps({layers});
}

Deck.gl is designed to handle layer updates very efficiently at high frame rate. An example of this kind of application is autonomous vehicle visualization, where car pose, LIDAR point clouds, camera imagery, as well as geometries outlining perception, prediction and planning decisions are streamed in from a server many times a second. The performance guide describes various techniques in optimizing for large datasets and frequent updates.

hubble.gl, a project by the vis.gl community, implements comprehensive keyframe-controlled animation of deck.gl layers for interactive storytelling and/or render to video.

TutorialsAPI index
English reference text adapted from the official deck.gl documentation, © vis.gl contributors, licensed under MIT.
Original page: https://deck.gl/docs/developer-guide/animations-and-transitions · Chinese note: /deckgl/api/transitions.html
Cite this page

Atlaslog (2026). transitions. https://www.jingweizhi.com/en/deckgl/api/transitions.html (accessed 2026-11-03).