From 5e9c97b3d9a6779a03eecece6c549c908fd8a633 Mon Sep 17 00:00:00 2001 From: Marcus Lundblad Date: Wed, 3 May 2023 21:43:40 +0200 Subject: mainWindow: Add actions to rotate the map Adds actions with keyboard shortcuts to rotate the map and reset rotation. --- src/mainWindow.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/mainWindow.js b/src/mainWindow.js index e99a1414..2b63aee0 100644 --- a/src/mainWindow.js +++ b/src/mainWindow.js @@ -220,6 +220,18 @@ export class MainWindow extends Gtk.ApplicationWindow { accels: ['minus', 'KP_Subtract', 'KP_Subtract'], onActivate: () => this._mapView.zoomOut() }, + 'rotate-clockwise': { + accels: ['Right'], + onActivate: () => this._rotateMap(Math.PI / 32) + }, + 'rotate-counter-clockwise': { + accels: ['Left'], + onActivate: () => this._rotateMap(-Math.PI / 32) + }, + 'reset-rotation': { + accels: ['Up'], + onActivate: () => { this._mapView.map.viewport.rotation = 0.0; } + }, 'show-scale': { accels: ['S'], paramType: 'b', @@ -486,6 +498,26 @@ export class MainWindow extends Gtk.ApplicationWindow { dialog.show(); } + _rotateMap(angle) { + let rotation = this._mapView.map.viewport.rotation; + + rotation += angle; + + // keep the rotation in [0..2 * PI) + if (rotation < 0) + rotation += 2 * Math.PI + else if (rotation >= 2 * Math.PI) + rotation -= 2 * Math.PI; + + /* if the resulting angle is close to 0, snap back to 0 to avoid + * rounding errors adding when doing multiple rotations + */ + if (rotation < 0.01 || 2 * Math.PI - rotation < 0.01) + rotation = 0; + + this._mapView.map.viewport.rotation = rotation; + } + _printRouteActivate() { if (this._mapView.routeShowing) { let operation = new PrintOperation({ mainWindow: this }); -- cgit v1.2.1