Camera Keyboard Control
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.

Simple Example:

1
Component({
2
selector: 'keyboard-control-layer',
3
template: '',
4
})
5
export class KeyboardControlLayerComponent implements OnInit, OnDestroy {
6
constructor(private keyboardControlService: KeyboardControlService) {}
7
8
ngOnInit() {
9
this.keyboardControlService.setKeyboardControls({
10
W: { action: KeyboardAction.CAMERA_FORWARD },
11
S: { action: KeyboardAction.CAMERA_BACKWARD },
12
D: { action: KeyboardAction.CAMERA_RIGHT },
13
A: { action: KeyboardAction.CAMERA_LEFT },
14
});
15
}
16
17
ngOnDestroy() {
18
this.keyboardControlService.removeKeyboardControls();
19
}
20
}
Copied!

Advanced Example:

1
Component({
2
selector: 'keyboard-control-layer',
3
template: '',
4
})
5
export class KeyboardControlLayerComponent implements OnInit, OnDestroy {
6
constructor(private keyboardControlService: KeyboardControlService) {}
7
8
private myCustomValue = 10;
9
10
ngOnInit() {
11
this.keyboardControlService.setKeyboardControls({
12
W: {
13
action: KeyboardAction.CAMERA_FORWARD,
14
validate: (camera, scene, params, key) => {
15
// Replace `checkCamera` you with your validation logic
16
if (checkCamera(camera) || params.customParams === true) {
17
return true;
18
}
19
20
return false;
21
},
22
params: () => {
23
return {
24
myValue: this.myCustomValue,
25
};
26
},
27
}
28
});
29
}
30
31
ngOnDestroy() {
32
this.keyboardControlService.removeKeyboardControls();
33
}
34
}
Copied!
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.
Last modified 1yr ago