summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Lundblad <ml@dfupdate.se>2023-05-03 21:43:40 +0200
committerMarcus Lundblad <ml@dfupdate.se>2023-05-06 23:55:31 +0200
commit5e9c97b3d9a6779a03eecece6c549c908fd8a633 (patch)
tree962180c95cd8e02c077068a728ae5c69d9eac77d
parentdfb7de4954c942e4cd1cd541f4c305a6c8367910 (diff)
downloadgnome-maps-5e9c97b3d9a6779a03eecece6c549c908fd8a633.tar.gz
mainWindow: Add actions to rotate the map
Adds actions with keyboard shortcuts to rotate the map and reset rotation.
-rw-r--r--src/mainWindow.js32
1 files changed, 32 insertions, 0 deletions
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: ['<Primary>minus', 'KP_Subtract', '<Primary>KP_Subtract'],
onActivate: () => this._mapView.zoomOut()
},
+ 'rotate-clockwise': {
+ accels: ['<Primary>Right'],
+ onActivate: () => this._rotateMap(Math.PI / 32)
+ },
+ 'rotate-counter-clockwise': {
+ accels: ['<Primary>Left'],
+ onActivate: () => this._rotateMap(-Math.PI / 32)
+ },
+ 'reset-rotation': {
+ accels: ['<Primary>Up'],
+ onActivate: () => { this._mapView.map.viewport.rotation = 0.0; }
+ },
'show-scale': {
accels: ['<Primary>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 });