The base class for all viewport controllers.
A controller class can be passed to either the Deck class's controller prop or a View class's controller prop to specify viewport interactivity.
The base Controller class supports the following options:
scrollZoom(boolean | object) - enable zooming with mouse wheel. Defaulttrue. If an object is supplied, it may contain the following fields to customize the zooming behavior:speed(number) - scaler that translates wheel delta to the change of viewport scale. Default0.01.smooth(boolean) - smoothly transition to the new zoom. If enabled, will provide a slightly lagged but smoother experience. Defaultfalse.
dragPan(boolean) - enable panning with pointer drag. DefaulttruedragRotate(boolean) - enable rotating with pointer drag. DefaulttruedoubleClickZoom(boolean) - enable zooming with double click. Defaulttrue. Adds ~300ms latency to click events due to the tap recognizer waiting to distinguish single clicks from double clicks. Set tofalsefor immediate click response. Note: disabling also preventsonClickfrom firing withtapCount: 2on double-click.doubleClickDragZoom(boolean) - enable zooming by double clicking/tapping and dragging. Defaultfalse. Enabling adds ~300ms latency to click events due to the tap recognizer waiting to distinguish single clicks from double-click-drags.touchZoom(boolean) - enable zooming with multi-touch pinch. DefaulttruemultiTouchDrag('pan' | 'rotate' | null) - behavior of two-pointer translation gestures. Inpanmode, two-finger swiping pans the viewport. Inrotatemode, horizontal swiping changes bearing and vertical swiping changes pitch. Defaultnull(disabled).trackpadGesture(boolean) - treat trackpad similar to a touch screen instead of a mouse. Defaultfalse.- When
true, two-finger gesture on the trackpad emits multi-touch pinch or drag events. - When
false, two-finger gesture on the trackpad emits wheel scroll events.
- When
keyboard(boolean | object) - enable interaction with keyboard. Defaulttrue. If an object is supplied, it may contain the following fields to customize the keyboard behavior:zoomSpeed(number) - speed of zoom using +/- keys. Default2.moveSpeed(number) - speed of movement using arrow keys, in pixels.rotateSpeedX(number) - speed of rotation using shift + left/right arrow keys, in degrees. Default15.rotateSpeedY(number) - speed of rotation using shift + up/down arrow keys, in degrees. Default10.
dragMode(string) - drag behavior without pressing function keys, one ofpanandrotate.inertia(boolean | number) - Enable inertia after panning/pinching. If a number is provided, indicates the duration of time over which the velocity reduces to zero, in milliseconds. Defaultfalse.maxBounds([min: number[], max: number[]]) - constrain camera to the specified bounding box. Different type of views may handle this constraint differently.maxBoundsPadding({left, right, top, bottom}) - padding inside the viewport when fittingmaxBounds, 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/pxwith parentheses andcalc()addition/subtraction) as viewx,y,width,height, andpadding. This can be used to move the target rectangle away from the center of the viewport. A non-positive remaining dimension does not contribute a zoom constraint; a negative remaining dimension also disables target constraints. Default0.
Mobile users: See Optimization for Mobile for CSS and browser event guards that help prevent native selection, tap highlight, and touch callout UI during repeated touch gestures.
A controller is not meant to be instantiated by the application. The following methods are documented for creating custom controllers that extend the base Controller class.
import {Controller} from 'deck.gl';
class MyController extends Controller {
constructor(props) {
super(props);
}
}The constructor takes one argument:
props(object) - contains the following options:eventManager- handles events subscriptionsmakeViewPort (viewState)- creates newViewportbased on providedViewState, and current view'swidthandheightonStateChangecallback functiononViewStateChangecallback functiontimeline- an instance ofluma.glanimation timeline class
Called by the event manager to handle pointer events.
See Event object documentation.
Called by the view when the view state updates. This method handles adding/removing event listeners based on user options.
Called by the event handlers, this method updates internal state, and invokes onViewStateChange callback with a new map state.
Utility used by the event handlers, returns pointer position [x, y] from any event.
Utility used by the event handlers, returns true if ctrl/alt/meta key is pressed during any event.
Utility used by the event handlers, returns true if a pointer position [x, y] is inside the current view.
If event is provided, returns false if the event is already handled, and mark the event as handled if the point is in bounds. This can be used to make sure that certain events are only handled by one controller, when there are overlapping viewports.
Returns true if the user is dragging the view.
In its constructor, a controller class can optionally specify a list of event names that it subscribes to with the events field.
Supported events are:
clickdblclickpanpinch: 2-finger free-form manipulation, used for touch zooming and rotationmultipan: 2-finger translation, used for touch panning or rotationkeydownkeyuppointerdownpointermovepointeruppointeroverpointeroutpointerleavewheelcontextmenu
Note that the following events are always toggled on/off by user options:
scrollZoom-['wheel']dragPananddragRotate-['pan']touchZoom-['pinch']multiTouchDrag-['multipan'], and['pinch']inrotatemodedoubleClickZoom-['dblclick']doubleClickDragZoom-['pointerdown', 'pointermove', 'pointerup', 'pointercancel']keyboard-['keydown']
import {Controller} from 'deck.gl';
class MyController extends Controller{
constructor(props) {
super(props);
this.events = ['pointermove'];
}
handleEvent(event) {
if (event.type === 'pointermove') {
// do something
} else {
super.handleEvent(event);
}
}
}