User interaction handlers¶
Items related to the ways in which the map responds to user input.
BoxZoomHandler¶
The BoxZoomHandler allows the user to zoom the map to fit within a bounding box. The bounding box is defined by clicking and holding shift while dragging the cursor.
Instance Members¶
disable()¶
Disables the "box zoom" interaction.
Example
map.boxZoom.disable();
enable()¶
Enables the "box zoom" interaction.
Example
map.boxZoom.enable();
isActive()¶
Returns a Boolean indicating whether the "box zoom" interaction is active, i.e. currently being used.
Returns
boolean: true if the "box zoom" interaction is active.
isEnabled()¶
Returns a Boolean indicating whether the "box zoom" interaction is enabled.
Returns
boolean: true if the "box zoom" interaction is enabled.
ScrollZoomHandler¶
The ScrollZoomHandler allows the user to zoom the map by scrolling.
Instance Members¶
disable()¶
Disables the "scroll to zoom" interaction.
Example
map.scrollZoom.disable();
enable()¶
Enables the "scroll to zoom" interaction.
Parameters
options(Object?)Options object. |Name|Description| |--- |--- | |options.aroundstring?|If "center" is passed, map will zoom around center of map|
Example
map.scrollZoom.enable();
map.scrollZoom.enable({ around: 'center' })
isEnabled()¶
Returns a Boolean indicating whether the "scroll to zoom" interaction is enabled.
Returns
boolean: true if the "scroll to zoom" interaction is enabled.
wheelZoomRate(wheelZoomRate)¶
Set the zoom rate of a mouse wheel
Parameters
wheelZoomRate(number)(default 1/450)The rate used to scale mouse wheel movement to a zoom value.
Example
// Slow down zoom of mouse wheel
map.scrollZoom.setWheelZoomRate(1/600);
setZoomRate(zoomRate)¶
Set the zoom rate of a trackpad
Parameters
zoomRate(number)(default 1/100)The rate used to scale trackpad movement to a zoom value.
Example
// Speed up trackpad zoom
map.scrollZoom.setZoomRate(1/25);
DragPanHandler¶
The DragPanHandler allows the user to pan the map by clicking and dragging the cursor.
Instance Members¶
disable()¶
Disables the "drag to pan" interaction.
Example
map.dragPan.disable();
enable()¶
Enables the "drag to pan" interaction.
Parameters
options(Object?)Options object
Name | Description |
---|---|
options.linearitynumberdefault: 0 | factor used to scale the drag velocity |
options.easingFunctiondefault: bezier(0,0,0.3,1) | easing function applled to map.panTo when applying the drag. |
options.maxSpeednumberdefault: 1400 | the maximum value of the drag velocity. |
options.decelerationnumberdefault: 2500 | the rate at which the speed reduces after the pan ends. |
Example
map.dragPan.enable();
map.dragPan.enable({
linearity: 0.3,
easing: bezier(0, 0, 0.3, 1),
maxSpeed: 1400,
deceleration: 2500,
});
isActive()¶
Returns a Boolean indicating whether the "drag to pan" interaction is active, i.e. currently being used.
Returns
boolean: true if the "drag to pan" interaction is active.
isEnabled()¶
Returns a Boolean indicating whether the "drag to pan" interaction is enabled.
Returns
boolean: true if the "drag to pan" interaction is enabled.
DragRotateHandler¶
The DragRotateHandler allows the user to rotate the map by clicking and dragging the cursor while holding the right mouse button or ctrl key.
Instance Members¶
disable()¶
Disables the "drag to rotate" interaction.
Example
map.dragRotate.disable();
enable()¶
Enables the "drag to rotate" interaction.
Example
map.dragRotate.enable();
isActive()¶
Returns a Boolean indicating whether the "drag to rotate" interaction is active, i.e. currently being used.
Returns
boolean: true if the "drag to rotate" interaction is active.
isEnabled()¶
Returns a Boolean indicating whether the "drag to rotate" interaction is enabled.
Returns
boolean: true if the "drag to rotate" interaction is enabled.
KeyboardHandler¶
The KeyboardHandler allows the user to zoom, rotate, and pan the map using the following keyboard shortcuts:
- = / +: Increase the zoom level by 1.
- Shift-= / Shift-+: Increase the zoom level by 2.
- -: Decrease the zoom level by 1.
- Shift--: Decrease the zoom level by 2.
- Arrow keys: Pan by 100 pixels.
- Shift+⇢: Increase the rotation by 15 degrees.
- Shift+⇠: Decrease the rotation by 15 degrees.
- Shift+⇡: Increase the pitch by 10 degrees.
- Shift+⇣: Decrease the pitch by 10 degrees.
Instance Members¶
disable()¶
Disables the "keyboard rotate and zoom" interaction.
Example
map.keyboard.disable();
disableRotation()¶
Disables the "keyboard pan/rotate" interaction, leaving the "keyboard zoom" interaction enabled.
Example
map.keyboard.disableRotation();
enable()¶
Enables the "keyboard rotate and zoom" interaction.
Example
map.keyboard.enable();
enableRotation()¶
Enables the "keyboard pan/rotate" interaction.
Example
map.keyboard.enable();
map.keyboard.enableRotation();
isActive()¶
Returns true if the handler is enabled and has detected the start of a zoom/rotate gesture.
Returns
boolean: true if the handler is enabled and has detected the start of a zoom/rotate gesture.
isEnable()¶
Returns a Boolean indicating whether the "keyboard rotate and zoom" interaction is enabled.
Returns
boolean: true if the "keyboard rotate and zoom" interaction is enabled.
DoubleClickZoomHandler¶
The DoubleClickZoomHandler allows the user to zoom the map at a point by double clicking or double tapping.
Instance Members¶
disable()¶
Disables the "double click to zoom" interaction.
Example
map.doubleClickZoom.disable();
enable()¶
Enables the "double click to zoom" interaction.
Example
map.doubleClickZoom.enable();
isActive()¶
Returns a Boolean indicating whether the "double click to zoom" interaction is active, i.e. currently being used.
Returns
boolean: true if the "double click to zoom" interaction is active.
isEnabled()¶
Returns a Boolean indicating whether the "double click to zoom" interaction is enabled.
Returns
boolean: true if the "double click to zoom" interaction is enabled.
TouchZoomRotateHandler¶
The TouchZoomRotateHandler allows the user to zoom and rotate the map by pinching on a touchscreen.
They can zoom with one finger by double tapping and dragging. On the second tap, hold the finger down and drag up or down to zoom in or out.
Instance Members¶
disable()¶
Disables the "pinch to rotate and zoom" interaction.
Example
map.touchZoomRotate.disable();
disableRotation()¶
Disables the "pinch to rotate" interaction, leaving the "pinch to zoom" interaction enabled.
Example
map.touchZoomRotate.disableRotation();
enable(options?)¶
Enables the "pinch to rotate and zoom" interaction.
Parameters
options(Object?)Options object.
Name
Description
options.around
string?
If "center" is passed, map will zoom around the center
Example
map.touchZoomRotate.enable();
map.touchZoomRotate.enable({ around: 'center' });
enableRotation()¶
Enables the "pinch to rotate" interaction.
Example
map.touchZoomRotate.enable();
map.touchZoomRotate.enableRotation();
isActive()¶
Returns true if the handler is enabled and has detected the start of a zoom/rotate gesture.
Returns
boolean: //eslint-disable-line
isEnabled()¶
Returns a Boolean indicating whether the "pinch to rotate and zoom" interaction is enabled.
Returns
boolean: true if the "pinch to rotate and zoom" interaction is enabled.
TouchPitchHandler¶
The TouchPitchHandler allows the user to pitch the map by dragging up and down with two fingers.
Extends TwoTouchHandler.
new TouchPitchHandler()
Instance Members¶
disable()¶
Disables the "drag to pitch" interaction.
Example
map.touchPitch.disable();
enable()¶
Enables the "drag to pitch" interaction.
Example
map.touchPitch.enable();
isActive()¶
Returns a Boolean indicating whether the "drag to pitch" interaction is active, i.e. currently being used.
Returns
boolean: true if the "drag to pitch" interaction is active.
isEnable()¶
Returns a Boolean indicating whether the "drag to pitch" interaction is enabled.
Returns
boolean: true if the "drag to pitch" interaction is enabled.