summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Lundblad <ml@dfupdate.se>2023-05-03 21:28:34 +0200
committerMarcus Lundblad <ml@dfupdate.se>2023-05-03 22:00:33 +0200
commitdfb7de4954c942e4cd1cd541f4c305a6c8367910 (patch)
tree28791ac78dfa1ff72c8d8d5f69735232abbe7174
parent1e8b9b79770d4da7795db76d819c291261c0c877 (diff)
downloadgnome-maps-dfb7de4954c942e4cd1cd541f4c305a6c8367910.tar.gz
mapView: Save and restore map rotation
Save map rotation and used stored value when starting up.
-rw-r--r--src/mapView.js36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/mapView.js b/src/mapView.js
index 537373a7..d4915c16 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -135,6 +135,7 @@ export class MapView extends Gtk.Overlay {
this._mainWindow = mainWindow;
this._storeId = 0;
+ this._storeRotationId = 0;
this.map = this._initMap();
this.child = this.map;
@@ -145,8 +146,10 @@ export class MapView extends Gtk.Overlay {
this._initScale();
this._initLayers();
- if (Application.normalStartup)
+ if (Application.normalStartup) {
this._goToStoredLocation();
+ this._setStoredRotation();
+ }
this.shapeLayerStore = new Gio.ListStore(GObject.TYPE_OBJECT);
@@ -268,6 +271,7 @@ export class MapView extends Gtk.Overlay {
map.viewport.min_zoom_level = MapMinZoom;
map.viewport.connect('notify::latitude', this._onViewMoved.bind(this));
+ map.viewport.connect('notify::rotation', this._onViewRotated.bind(this));
// switching map type will set view min-zoom-level from map source
map.viewport.connect('notify::min-zoom-level', () => {
if (map.viewport.min_zoom_level < MapMinZoom) {
@@ -694,6 +698,14 @@ export class MapView extends Gtk.Overlay {
}
}
+ _storeRotation() {
+ let viewport = this.map.viewport;
+ let rotation = viewport.rotation;
+
+ if (!isNaN(rotation))
+ Application.settings.set('rotation', rotation);
+ }
+
_goToStoredLocation() {
let location = Application.settings.get('last-viewed-location');
@@ -727,6 +739,18 @@ export class MapView extends Gtk.Overlay {
}
}
+ _setStoredRotation() {
+ let rotation = Application.settings.get('rotation');
+
+ if (rotation < 0.0 || rotation >= 2 * Math.PI) {
+ // safeguard agains out-of-bounds rotation values
+ Utils.debug('Invalid stored rotation, set no rotation');
+ rotation = 0;
+ }
+
+ this.map.viewport.rotation = rotation;
+ }
+
gotoBBox(bbox, linear) {
if (!bbox.isValid()) {
Utils.debug('Bounding box is invalid');
@@ -958,6 +982,16 @@ export class MapView extends Gtk.Overlay {
});
}
+ _onViewRotated() {
+ if (this._storeRotationId !== 0)
+ return;
+
+ this._storeRotationId = GLib.timeout_add(null, _LOCATION_STORE_TIMEOUT, () => {
+ this._storeRotationId = 0;
+ this._storeRotation();
+ });
+ }
+
onSetMarkerSelected(selectedMarker) {
this.emit('marker-selected', selectedMarker);
}