Skip to main content

Keyboard

Keyboard

We implemented a built-in keyboard listener to make one central place where keyboard events can be accessed (without adding a listener yourself).

The following methods are available on map.pm.Keyboard:

MethodReturnsDescription
getLastKeyEvent(type = 'current')ObjectReturns the last event. Also keydown and keyup can be passed, to get the specific one.
getPressedKey()StringReturns the current pressed key. KeyboardEvent.key
isShiftKeyPressed()BooleanReturns true if the Shift key is currently pressed.
isAltKeyPressed()BooleanReturns true if the Alt key is currently pressed.
isCtrlKeyPressed()BooleanReturns true if the Ctrl key is currently pressed.
isMetaKeyPressed()BooleanReturns true if the Meta key is currently pressed.

The following events are available on a map instance:

EventParamsDescriptionOutput
pm:keyeventeFired when keydown or keyup on the document is fired. eventType = keydown / keyup, focusOn = document / mapevent, eventType, focusOn

Exit Mode on Escape

You can enable the exitModeOnEscape global option to allow users to deactivate any active mode by pressing the Escape key.

map.pm.setGlobalOptions({ exitModeOnEscape: true });

This works with all modes including drawing modes (Polygon, Line, Marker, Rectangle, Circle, CircleMarker), as well as Edit, Drag, Removal, Rotate, and Cut modes.

The option defaults to false for backward compatibility.

Finish Drawing on Enter

You can enable the finishOnEnter global option to allow users to finish drawing shapes by pressing the Enter key when enough vertices are placed.

map.pm.setGlobalOptions({ finishOnEnter: true });

This works with:

  • Line: Requires at least 2 vertices
  • Polygon: Requires at least 3 vertices

The option defaults to false for backward compatibility.