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

Viewport

Quick answer

Read the article detailing deck.gl's Views and Projections system.

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

Read the article detailing deck.gl's Views and Projections system.

A deck.gl Viewport is essentially a geospatially enabled camera, and combines a number of responsibilities, which can project and unproject 3D coordinates to the screen.

Viewport classes are focused on mathematical operations such as coordinate projection/unprojection, and calculation of view and projection matrices and other uniforms needed by the WebGL2/WebGPU vertex shaders. The basic Viewport class is a generic geospatially enabled version of the typical 3D "camera" class you would find in most 3D/WebGL2/OpenGL libraries.

While the Viewport class can certainly be used directly if you need and are able to calculate your own projection matrices, you typically do not directly create Viewport instances. Instead, Viewport classes are created using the View class descriptors and the current viewState.

Overview of Viewport Classes​

Viewport ClassDescription
ViewportThe base viewport has to be supplied view and projection matrices. It is typically only instantiated directly if the application needs to work with viewports that have been supplied from external sources, such as the WebVR API.
WebMercatorViewportWhile all Viewport subclasses are geospatially enabled, this class renders from a perspective that matches a typical top-down map and is designed to synchronize perfectly with a mapbox-gl base map (even in 3D enabled perspective mode).

Usage​

The Viewport class is normally not instantiated directly. The View class is more commonly used by applications. deck.gl automatically creates Viewports from Views and viewState when needed, using the View.makeViewport method.

Constructor​

new Viewport({width: 500, height: 500, viewMatrix, projectionMatrix, ...});

General Parameters

View Matrix Parameters

Position and Geospatial Anchor Options (Optional)

Projection Matrix Parameters.

If projectionMatrix is not supplied, an attempt is made to build from the remaining parameters. Otherwise the remaining parameters will be ignored.

Methods​

equals​

Parameters:

Returns:

project​

Projects world coordinates to pixel coordinates on screen.

Parameters:

Returns:

unproject​

Unproject pixel coordinates on screen into world coordinates.

Parameters:

Returns:

projectPosition​

Projects latitude, longitude (and altitude) to coordinates in the common space.

Parameters:

Returns:

unprojectPosition​

Projects a coordinate from the common space to latitude, longitude and altitude.

Parameters:

Returns:

getBounds​

Extracts the axis-aligned bounding box of the current visible area.

Returns:

getFrustumPlanes​

Extract view frustum planes of the current camera. Each plane is defined by its normal normal and distance from the origin distance (such that point x is on the plane if dot(normal, x) === distance) in the common space.

Returns:

import {Vector3} from '@math.gl/core';

// Culling tests must be done in common space
const commonPosition = new Vector3(viewport.projectPosition(point));

// Extract frustum planes based on current view.
const frustumPlanes = viewport.getFrustumPlanes();
let outDir = null;

// Check position against each plane
for (const dir in frustumPlanes) {
const plane = frustumPlanes[dir];
if (commonPosition.dot(plane.normal) > plane.distance) {
outDir = dir;
break;
}
}
if (outDir) {
console.log(`Point is outside of the ${outDir} plane`);
} else {
console.log('Point is visible');
}

Remarks​

Source​

modules/core/src/viewports/viewport.ts

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

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