Introducing a new way to review your PRs.

Read the announcement

visgl / deck.gl

WebGL2 powered visualization framework

View on GitHub

23 documents · Updated Nov 20, 2026

docs / interaction-and-picking

Interaction and picking

Interaction and picking connect pointer input to rendered data objects and application callbacks. Deck receives pointer and gesture events, finds the visible object at the event position, builds a PickingInfo value, and sends it to layer, Deck, or widget handlers. View controllers use the same input stream to update camera state, but they report through view-state callbacks rather than object callbacks. See Core rendering engine for the wider runtime, Deck instance and render loop for the frame cycle that hosts this work, and Layer lifecycle and state for how layers supply the rendered state that picking queries.

Interaction model

The interaction model separates input recognition from object lookup. An event manager recognizes pointer and gesture input, while the picking system uses the current views and layers to identify the rendered target.

Input events

The Deck runtime binds an event manager to each active canvas. It listens for pointer movement and leave events for hover, then listens for recognized click and pan events for click and drag callbacks. In multi-canvas mode, each presentation canvas has its own event path, and Deck carries that canvas identity into the related pick query. The same event stream can also drive view controllers, so camera changes and object interaction share the canvas input boundary.

View controllers turn navigation gestures into view-state changes and report interaction state such as panning, rotating, zooming, or dragging. The base controller now applies a clear constraint phase to each action: it can use hard bounds at the start, elastic bounds during movement, and a rebound at the end when rubberBand is enabled. This keeps temporary overshoot in the camera path without changing the separate object callback path. modules/…/controller.ts

Map, globe, and custom-projection controllers share this navigation contract but keep their own camera rules. Map navigation can use a 2D or 3D rotation pivot from a picked position. Globe navigation keeps motion on the globe and limits polar movement. Custom planar navigation anchors panning and zooming in common space on the ground plane. These camera updates remain separate from object drag callbacks, even though both use the same recognized gesture. modules/…/map-controller.ts, modules/…/globe-controller.ts, modules/…/custom-projection-controller.ts

The supported application-facing interaction callbacks are:

  • onHover for object enter, leave, and change events.
  • onClick for click and double-click gestures.
  • onDragStart, onDrag, and onDragEnd for pan gestures.
  • onViewStateChange and onInteractionStateChange for camera and navigation state.

References: modules/…/deck.ts• L1188-1228 modules/…/canvas-manager.ts• L75-159 modules/…/constants.ts• L95-112 modules/…/controller.ts• L260-302 modules/…/controller.ts• L372-425 modules/…/controller.ts• L528-561 modules/…/map-controller.ts• L698-775 modules/…/globe-controller.ts• L318-431 modules/…/custom-projection-controller.ts• L117-155

Picking requests

A picking request starts with CSS-pixel coordinates relative to a canvas. The picker maps those coordinates to the selected canvas drawing buffer using the current device-pixel ratio, applies the configured picking radius, and asks the picking pass to query the rendered result. In multi-canvas mode, the request also identifies the presentation canvas when needed. A point query can return the closest object or additional overlapping objects, while a region query returns the unique objects visible in a rectangle.

The asynchronous query path works across supported device types and is the preferred application-facing path. It also normalizes texture readback across device backends before decoding the picked identities. The older synchronous methods remain for WebGL callers. When a point query requests a 3D coordinate, the picker can run a second depth query against the picked layer or the terrain layers that supply depth for draped content.

The event pipeline is summarized below.

flowchart LR
  A[Pointer or gesture input] --> B[Event manager]
  B --> C{Interaction type}
  C -->|Move or leave| D[Point picking]
  C -->|Click or drag| E[Saved pointer-down pick]
  D --> F[PickingInfo]
  E --> F
  F --> G[Layer callback]
  G -->|Not handled| H[Deck callback]
  H --> I[Widget callback]
  B --> J[View controller]
  J --> K[View-state callback]

References: modules/…/deck.ts• L935-972 modules/…/deck.ts• L1030-1129 modules/…/deck.ts• L1528-1602 modules/…/deck-picker.ts• L118-174 modules/…/deck-picker.ts• L232-390 modules/…/deck-picker.ts• L559-661 modules/…/deck-picker.ts• L770-947 modules/…/deck.ts• L1875-1970

Callback delivery

Deck delivers an event to the top-level layer associated with the picked object before it delivers the event to Deck-level callbacks. A layer callback can return a truthy value to mark the event as handled. In that case the event does not continue to the Deck callback or widget handlers.

If no layer handles the event, Deck calls the matching callback in DeckProps, then sends the event to widgets. A widget can receive events for all views or only for the view named by its viewId. This lets an application use one callback for all layers or keep behavior close to a specific layer.

References: modules/…/deck.ts• L984-1028 modules/…/widget-manager.ts• L131-170 modules/…/widget.ts• L169-184

Rendered object identity

Picking identifies a rendered object by writing an encoded identity into a temporary off-screen buffer. The normal color of the object is not used for this purpose, so visual styling does not change which data item receives the event.

Pickable layers

A layer is part of the picking query only when its pickable prop is enabled and its visible draw output can take part in the picking pass. Composite layers provide the public identity while their rendered child layers provide the pixels that the picker reads. pickable: '3d' also asks the picker to recover a depth-aware coordinate when the device supports that path. Picking is disabled by default, and Deck can disable it for the whole runtime.

The meaning of an object belongs to the layer. For many layers it is one entry in data, but a layer can map several rendered pieces to one logical object or expose a different object type through its picking information.

References: modules/…/layer-props.ts• L155-166 modules/…/layer.ts• L333-336 modules/…/pick-layers-pass.ts• L117-123 modules/…/deck-picker.ts• L217-226

Picking colors

During a picking pass, each pickable layer receives a layer identity in the alpha channel. Each object receives an RGB identity based on its object index. The picker reads the buffer at the requested point or region, decodes the layer and object index, and then restores any temporary state used for deeper queries.

This design makes picking work on the same geometry that is rendered on screen. It also means that picking covers visible pixels only. Objects outside the rendered canvas are not available to a pick query.

The color space supports up to 255 encoded layers in one pass and up to 16,777,215 object indexes per layer. If more layers are present, Deck can still render them normally, but only the layers that receive an available picking identity participate in that pass.

References: modules/…/pick-layers-pass.ts• L49-115 modules/…/pick-layers-pass.ts• L188-243 modules/…/layer.ts• L394-418 modules/…/picking.ts• L44-82

Picking information

PickingInfo is the common hand-off between the picker and application code. It states whether an object was found and carries the layer, object index, screen position, viewport, and an unprojected coordinate when one is available.

The main fields have these roles:

FieldMeaning
pickedtrue when the query found a rendered object. Use this field to distinguish an empty result from an object whose object value is absent.
layerThe top-level layer that owns the interaction.
sourceLayerThe immediate layer that rendered the pixel when the owner is a composite layer.
indexThe logical object index returned by the layer.
objectThe application data object when the layer can map the index to its data.
x, yThe event position in CSS pixels.
coordinateThe position in the active viewport's coordinate system. It is null when unprojection fails or produces non-finite values.
viewportThe view that contains the picked pixel.

An empty result still carries position and viewport context. This lets an onHover callback clear application state when the pointer leaves an object.

References: modules/…/pick-info.ts• L9-23 modules/…/pick-info.ts• L31-87 modules/…/layer.ts• L555-568

Composite layer identity

Composite layers can render child layers while presenting one public layer to the application. After the picker finds a child layer, Deck passes the picking information through the child and its parent chain. Each layer can add context or map the result to a user-facing object.

The final layer points to the top-level layer, while sourceLayer records the child that first rendered the pixel. As a result, application callbacks do not need to know which internal child layer produced the geometry.

References: modules/…/pick-info.ts• L171-195 modules/…/deck-picker.ts• L619-661

Built-in interaction callbacks

Built-in callbacks turn picking results into common user actions. Layer callbacks are useful when behavior belongs to one visualization layer. Deck callbacks are useful when an application owns a shared selection, hover state, or drag workflow.

Hover callbacks

Deck schedules hover picking from pointer movement rather than running a full query for every raw browser event. It keeps the latest request and processes it during the render cycle. A new hover callback is sent only when the picked layer or object index changes.

When the pointer leaves an object, the previous layer receives a PickingInfo value with picked: false before the new target receives its enter state. autoHighlight uses the same hover result to update the layer's highlighted object. The cursor state also records whether the pointer is over a pickable object.

Asynchronous hover results are sequence-checked. A slower result cannot replace a newer pointer position.

References: modules/…/deck.ts• L1528-1602 modules/…/pick-info.ts• L100-165 modules/…/layer.ts• L1304-1328

Click and drag callbacks

Deck picks the object under the pointer on pointerdown and stores that result for later click and drag gestures. This gives a drag sequence a stable target even as the pointer moves. For a click that needs a 3D coordinate, Deck performs a point pick at the click position so the callback can receive depth-aware information.

The same pan gesture can update the active view through its controller. The controller reports camera changes through onViewStateChange and interaction flags through onInteractionStateChange. Globe navigation can add globe-specific motion and inertia. Map navigation can use a picked 3D position as a rotation pivot. Custom projection navigation uses a common-space ground anchor. The object callback path remains separate, so an application can handle navigation and object dragging as different concerns. modules/…/map-controller.ts, modules/…/globe-controller.ts, modules/…/custom-projection-controller.ts

The gesture mapping is:

GestureCallback
Click or double-clickonClick
Pan startonDragStart
Pan moveonDrag
Pan endonDragEnd

The callbacks receive both PickingInfo and the recognized gesture event. If the pointer-down query is still pending, asynchronous gesture handling waits for that result. A later pointer-down sequence invalidates an older pending result.

References: modules/…/deck.ts• L1875-1970 modules/…/constants.ts• L95-112 modules/…/layer-props.ts• L247-266 modules/…/controller.ts• L563-704 modules/…/map-controller.ts• L713-775 modules/…/globe-controller.ts• L328-431 modules/…/custom-projection-controller.ts• L342-367

Selection callbacks

Deck does not own application selection state. An application normally treats onClick as its selection boundary, reads the returned PickingInfo, and stores or clears the selected data in its own state. The callback can be placed on a layer for local selection or on Deck for selection across all pickable layers.

Layer handling runs before Deck handling. Returning true from the layer callback stops the event from reaching the Deck-level callback. Returning no value allows the event to continue.

References: modules/…/deck.ts• L1006-1028 modules/…/layer.ts• L379-392 modules/…/layer-props.ts• L247-266

Application-driven queries

Applications can use the picker without relying on Deck's built-in event dispatch. This is useful when an existing event system owns the browser event or when an interaction needs a custom query area or result count.

Point queries

pickObjectAsync returns the top object at a CSS-pixel position. A radius can include nearby pixels, canvasId can select a presentation canvas in multi-canvas mode, and layerIds can limit the query to named layers. The result is null when no pickable object is found.

The deprecated synchronous point methods remain for WebGL callers. New code should use the asynchronous method so the query works with both supported device types.

References: modules/…/deck.ts• L735-752 modules/…/deck.ts• L1030-1079 modules/…/deck-picker.ts• L118-174 modules/…/deck-picker.ts• L232-390

Region queries

pickObjectsAsync returns unique objects whose rendered pixels appear inside a CSS-pixel rectangle. The picker first removes duplicate encoded identities, then removes duplicate logical objects that may be drawn by more than one child layer. maxObjects can limit the returned set, and canvasId can select the presentation canvas in multi-canvas mode.

Region queries support box selection and other application-defined selection tools. They return PickingInfo values but do not invoke layer or Deck event callbacks by themselves.

References: modules/…/deck.ts• L754-775 modules/…/deck-picker.ts• L559-661 modules/…/query-object.ts• L96-136

Interaction feedback

Picking results can drive visual and UI feedback without changing the application's data. Hover state can update GPU highlighting, while widgets can display a tooltip or other view-specific UI from the same PickingInfo value.

Highlight state

autoHighlight follows the current hover result when the layer does not set an explicit highlightedObjectIndex. An explicit index takes precedence over automatic hover highlighting. The layer's highlightColor can be a fixed color or a function of the current picking information.

References: modules/…/layer-props.ts• L221-232 modules/…/layer.ts• L1304-1328 modules/…/layer.ts• L1353-1381

Widget feedback

Widgets receive the same picking and gesture information after Deck-level dispatch. A widget may filter events by viewport and can use hover information for tooltips or other UI that sits outside the rendered layer content.

References: modules/…/widget-manager.ts• L131-170 modules/…/tooltip-widget.ts• L70-82 modules/…/widget.ts• L169-184

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to the picking color format or layer encoding must stay aligned across PickLayersPass, Layer.encodePickingColor and Layer.decodePickingColor, and the picking shader module.
  • Changes to event names or gesture recognition must stay aligned across EVENT_HANDLERS, event-manager registration, layer props, Deck props, and widget event hooks.
  • Changes to composite-layer picking must preserve the layer and sourceLayer contract used by getPickingInfo and application callbacks.
  • Changes to asynchronous picking must preserve the hover and pointer-down sequence guards so stale GPU results cannot dispatch to a newer event.
  • Changes to canvas or view routing must keep event roots, canvas ids, viewport selection, and the picking canvas context in agreement.
  • Changes to object indexing must preserve the mapping between rendered geometry, index, and the layer's application-facing object value.
  • Changes to controller gesture handling must preserve the distinction between view-state updates and object interaction callbacks. Keep interaction flags and constraint behavior aligned with the view-state contract.
  • Changes to globe pan or inertia behavior must preserve pole limits, camera-frame motion, and the separation between navigation state and object drag callbacks.
  • Changes to custom projection anchors or bounds must preserve the common-space ground-plane rule so navigation does not depend on picked geometry height.
  • Changes to coordinate unprojection must preserve the rule that failed or non-finite results become null in PickingInfo.coordinate rather than usable positions.

Important failure modes

TriggerConsequenceGuard
pickable is false or the layer is not visible in the picking passThe layer does not produce an interaction target.Enable pickable and keep the layer's draw output visible.
A layer or custom shader emits no valid picking identityRendered pixels appear empty to the picker, so callbacks receive picked: false or no layer result.Keep the layer's object-index mapping and picking output valid.
A picking pass has more than 255 encoded layersLayers beyond the available layer identities cannot be resolved in that pass.Restrict the query with layerIds or split a large query into batches.
A slow asynchronous pick completes after a newer pointer eventHover or drag state can point to an old screen position.Deck sequence-checks hover and pointer-down results before dispatch.
Two overlapping views contain the same pixel without a clear backgroundThe selected viewport can be ambiguous.Avoid ambiguous overlap or use view-specific layout and canvas routing.
A multi-canvas event root is shared by more than one targetOne input event can be associated with the wrong presentation canvas.Use distinct event roots or let Deck bind the event manager directly to each canvas.
A pick query uses the wrong canvas context or an out-of-date device-pixel mappingThe query samples a different drawing-buffer position than the pointer position.Route each query through the active presentation context and its current CSS-to-device ratio.
A 3D pick has no usable depth pathThe callback receives no usable depth-aware coordinate.Use pickable: '3d' only when the device and layer support depth picking.
A pan is handled as only an object drag or only a camera gestureThe application can update selection or view state without the other state it expects.Handle object callbacks and view-state callbacks as separate paths.
Globe pan motion reaches a pole or uses stale inertia historyThe camera can move past the valid globe range or continue with the wrong motion.Keep globe latitude limits and actual-position velocity tracking aligned.
A controller gesture exceeds its configured view boundsThe view can overshoot or fail to return to the expected state.Keep controller bounds and any elastic or rebound policy consistent with the intended view behavior.
A picking coordinate unprojects to a non-finite value or the inverse projection failsPickingInfo.coordinate is null for that result.Treat a null coordinate as an invalid world position and use the screen position or object data instead.

Key files

FileWhy to read it
modules/…/deck.tsPrimary boundary for event-manager setup, pointer tracking, callback dispatch, and public pick query methods.
modules/…/canvas-manager.tsExplains how multi-canvas event roots, canvas ids, presentation targets, and event managers stay associated.
modules/…/deck-picker.tsCoordinates canvas-aware query mapping, cross-device pixel readback, layer filtering, point and region queries, and 3D depth lookup.
modules/…/pick-info.tsDefines the information passed to callbacks and resolves hover changes and composite-layer context.
modules/…/query-object.tsConverts sampled picking pixels into the closest or unique rendered objects.
modules/…/pick-layers-pass.tsDescribes the off-screen picking pass and the layer identity decoder.
modules/…/layer.tsDefines layer-side event handling, object-index encoding, picking-info enrichment, and automatic highlighting.
modules/…/layer-props.tsDefines the public layer interaction and picking contract.
modules/…/constants.tsDefines gesture-to-callback mappings and recognizer relationships.
modules/…/controller.tsConnects recognized gestures to view-state changes, interaction state, navigation constraints, and rebound behavior.
modules/…/map-controller.tsShows map navigation and the optional picked 3D rotation pivot.
modules/…/globe-controller.tsShows globe-specific pan, pole-limit, and inertia behavior that shares the input stream with picking.
modules/…/custom-projection-controller.tsShows how planar custom-projection gestures use common-space anchors and bounds.
modules/…/first-person-controller.tsShows how first-person gestures update camera position and orientation under bounds.
modules/…/widget-manager.tsShows how picking events reach view-aware widgets after Deck dispatch.
docs/…/interactivity.mdUser-facing examples and limits for built-in events and direct picking queries.