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

View

Quick answer

For detailed explanations and code examples about deck.gl's views system, visit the Views and Projections article.

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

For detailed explanations and code examples about deck.gl's views system, visit the Views and Projections article.

The View class and its subclasses are used to specify where and how your deck.gl layers should be rendered. Applications typically instantiate at least one View subclass.

Views allow you to specify:

deck.gl offers a set of View classes that package the camera and controller logic that you need to visualize and interact with your data. You may choose one or multiple View classes based on the type of data (e.g. geospatial, 2D chart) and the desired perspective (top down, first-person, etc).

Constructor​

const view = new View({id, x, y, width, height, ...});

Parameters:

id (string, optional)​

A unique id of the view. In a multi-view use case, this is important for matching view states and place contents into this view.

canvasId (string, optional)​

When Deck._canvases is supplied, selects which presentation canvas renders this view. If omitted, the view renders into the first configured canvas.

x (string | number, optional)​

A relative (e.g. '50%') or absolute position. Accepts CSS-like expressions that mix numbers, %, px, whitespace/parentheses, and calc() with +/- to combine units. Default 0.

y (string | number, optional)​

A relative (e.g. '50%') or absolute position. Accepts CSS-like expressions that mix numbers, %, px, whitespace/parentheses, and calc() with +/- to combine units. Default 0.

width (string | number, optional)​

A relative (e.g. '50%') or absolute extent. Accepts CSS-like expressions that mix numbers, %, px, whitespace/parentheses, and calc() with +/- to combine units. Default '100%'.

height (string | number, optional)​

A relative (e.g. '50%') or absolute extent. Accepts CSS-like expressions that mix numbers, %, px, whitespace/parentheses, and calc() with +/- to combine units. Default '100%'.

padding (object, optional)​

Padding around the viewport, in the shape of {left, right, top, bottom} where each value is either a relative (e.g. '50%') or absolute pixels. These values support the same CSS-style expressions (numbers/percentages/px with parentheses and calc() addition/subtraction) as x, y, width, and height. This can be used to move the "look at"/target/vanishing point away from the center of the viewport rectangle.

controller (Function | boolean | object, optional)​

Options for viewport interactivity.

Default null.

viewState (string | object, optional)​

The optional viewState property enables a View to specify, select or select-and-modify its view state.

viewState is an overloaded property that can take either just a view state id string, or an object specifying view state parameters and optionally a view state id string:

Note that specifying viewState as an object with an id field effectively allows the View to modify a dynamic view state by overriding some of its fields. This is useful in multiview situations where it enables having one view that fixes some parameters (eg. zoom, pitch and bearing to show an overview map).

The viewState property is intended to support a number of use cases:

clear (boolean, optional)​

Clears the contents (pixels) of the viewport. If true clears color, depth, and stencil buffers. Behavior is controlled with the clearColor, clearDepth, and clearStencil properties.

Note that deck.gl always clears the screen before each render, and clearing, while cheap, is not totally free. This means that viewports should only clear the viewport if they need additional clearing, e.g. because they are rendering on top of another viewport, or want to have a different background color etc.

Default false.

clearColor (number[] | false, optional)​

Specifies the color to clear the viewport with, as an array of four numbers [r, g, b, a?]. Each channel should be an integer between 0 and 255. For example, [255, 0, 0, 255] for opaque red. If clearColor is false, the depth buffer will not be cleared. If clear is set to false, this property will be ignored.

Default [0, 0, 0, 0] (transparent).

clearDepth (number | false, optional)​

Specifies the depth buffer value to clear the viewport with, as number between 0.0 and 1.0. If clearDepth is false, the depth buffer will not be cleared. If clear is set to false, this property will be ignored.

Default 1.0 (far plane).

clearStencil (number | false, optional)​

Specifies the stencil buffer value to clear the viewport with, as number between 0 and 255. If clearStencil is false, the depth buffer will not be cleared. If clear is set to false, this property will be ignored.

Default 0 (clear).

parameters (object, optional)​

Override the GPU parameters used to draw layers in this view. See the luma.gl GPU parameters documentation for supported parameters and values.

View parameters override the Deck.parameters defaults for layers rendered in this view. Layer parameters still take precedence over both.

Examples:

Methods​

Note: most applications just create Views with the appropriate props and do not need to call the following View methods directly.

equals​

Returns true if deck.gl can determine that the supplied View instance is identical (equivalent) with this view.

view.equals(otherView)

Returns:

Note: For speed, deck.gl uses shallow equality. This means that a value of false does not guarantee that the views are not equivalent.

clone​

view.clone(newProps)

Creates a new View instance by merging the existing view's props with the provided newProps.

Parameters:

Returns:

makeViewport​

view.makeViewport({width, height, viewState})

Parameters:

Returns a Viewport using the viewport type, props in the View and provided dimensions and view state.

getDimensions​

Returns the actual pixel position and size that this View will occupy in a given "canvas" size.

const {x, y, width, height} = view.getDimensions({width, height});

Parameters:

Returns an object containing the following fields:

Remarks​

Source​

modules/core/src/views/view.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/view · Chinese note: /deckgl/api/view.html
Cite this page

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