Service that manages keyboard keys and execute camera actions per request.
Just inject the keyboard control service into any layer, under your ac-map
component, And define your keyboard handlers using setKeyboardControls
.
Provided and created by the ac-map
component, so each map has it own KeyboardControlService
instance.
Component({selector: 'keyboard-control-layer',template: '',})export class KeyboardControlLayerComponent implements OnInit, OnDestroy {constructor(private keyboardControlService: KeyboardControlService) {}​ngOnInit() {this.keyboardControlService.setKeyboardControls({W: { action: KeyboardAction.CAMERA_FORWARD },S: { action: KeyboardAction.CAMERA_BACKWARD },D: { action: KeyboardAction.CAMERA_RIGHT },A: { action: KeyboardAction.CAMERA_LEFT },});}​ngOnDestroy() {this.keyboardControlService.removeKeyboardControls();}}
Component({selector: 'keyboard-control-layer',template: '',})export class KeyboardControlLayerComponent implements OnInit, OnDestroy {constructor(private keyboardControlService: KeyboardControlService) {}​private myCustomValue = 10;​ngOnInit() {this.keyboardControlService.setKeyboardControls({W: {action: KeyboardAction.CAMERA_FORWARD,validate: (camera, scene, params, key) => {// Replace `checkCamera` you with your validation logicif (checkCamera(camera) || params.customParams === true) {return true;}​return false;},params: () => {return {myValue: this.myCustomValue,};},}});}​ngOnDestroy() {this.keyboardControlService.removeKeyboardControls();}}
Predefined keyboard actions:
KeyboardAction.CAMERA_FORWARD
- Moves the camera forward, accepts a numeric parameter named moveRate
that controls
the factor of movement, according to the camera height.
KeyboardAction.CAMERA_BACKWARD
- Moves the camera backward, accepts a numeric parameter named moveRate
that controls
the factor of movement, according to the camera height.
KeyboardAction.CAMERA_UP
- Moves the camera up, accepts a numeric parameter named moveRate
that controls
the factor of movement, according to the camera height.
KeyboardAction.CAMERA_DOWN
- Moves the camera down, accepts a numeric parameter named moveRate
that controls
the factor of movement, according to the camera height.
KeyboardAction.CAMERA_RIGHT
- Moves the camera right, accepts a numeric parameter named moveRate
that controls
the factor of movement, according to the camera height.
KeyboardAction.CAMERA_LEFT
- Moves the camera left, accepts a numeric parameter named moveRate
that controls
the factor of movement, according to the camera height.
KeyboardAction.CAMERA_LOOK_RIGHT
- Changes the camera to look to the right, accepts a numeric parameter named lookFactor
that
controls the factor of looking, according to the camera current position.
KeyboardAction.CAMERA_LOOK_LEFT
- Changes the camera to look to the left, accepts a numeric parameter named lookFactor
that
controls the factor of looking, according to the camera current position.
KeyboardAction.CAMERA_LOOK_UP
- Changes the camera to look up, accepts a numeric parameter named lookFactor
that controls
the factor of looking, according to the camera current position.
KeyboardAction.CAMERA_LOOK_DOWN
- Changes the camera to look down, accepts a numeric parameter named lookFactor
that controls
the factor of looking, according to the camera current position.
KeyboardAction.CAMERA_TWIST_RIGHT
- Twists the camera to the right, accepts a numeric parameter named amount
that controls
the twist amount
KeyboardAction.CAMERA_TWIST_LEFT
- Twists the camera to the left, accepts a numeric parameter named amount
that controls
the twist amount
KeyboardAction.CAMERA_ROTATE_RIGHT
- Rotates the camera to the right, accepts a numeric parameter named angle
that controls
the rotation angle
KeyboardAction.CAMERA_ROTATE_LEFT
- Rotates the camera to the left, accepts a numeric parameter named angle
that controls
the rotation angle
KeyboardAction.CAMERA_ROTATE_UP
- Rotates the camera upwards, accepts a numeric parameter named angle
that controls
the rotation angle
KeyboardAction.CAMERA_ROTATE_DOWN
- Rotates the camera downwards, accepts a numeric parameter named angle
that controls
the rotation angle
KeyboardAction.CAMERA_ZOOM_IN
- Zoom in into the current camera center position, accepts a numeric parameter named
amount
that controls the amount of zoom in meters.
KeyboardAction.CAMERA_ZOOM_OUT
- Zoom out from the current camera center position, accepts a numeric parameter named
amount
that controls the amount of zoom in meters.