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:
| Method | Returns | Description |
|---|---|---|
getLastKeyEvent(type = 'current') | Object | Returns the last event. Also keydown and keyup can be passed, to get the specific one. |
| getPressedKey() | String | Returns the current pressed key. KeyboardEvent.key |
| isShiftKeyPressed() | Boolean | Returns true if the Shift key is currently pressed. |
| isAltKeyPressed() | Boolean | Returns true if the Alt key is currently pressed. |
| isCtrlKeyPressed() | Boolean | Returns true if the Ctrl key is currently pressed. |
| isMetaKeyPressed() | Boolean | Returns true if the Meta key is currently pressed. |
The following events are available on a map instance:
| Event | Params | Description | Output |
|---|---|---|---|
| pm:keyevent | e | Fired when keydown or keyup on the document is fired. eventType = keydown / keyup, focusOn = document / map | event, 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.