[gnome-maps/wip/fix-geoloc: 10/10] Fix map not panning to new user location



commit a14588ed98c2df6fde4d537f455bc664ab09fa11
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Thu Jul 18 06:40:50 2013 +0200

    Fix map not panning to new user location
    
    Fix a bug where when a new user location is found the map wouldn't pan
    to it even if the track-user-location setting is enabled.
    This patch doesn't make the map not animate if the new location was
    found on start of the program.

 src/mainWindow.js |   15 ++++++++++-----
 src/mapView.js    |   27 ++++++++++++---------------
 2 files changed, 22 insertions(+), 20 deletions(-)
---
diff --git a/src/mainWindow.js b/src/mainWindow.js
index d7b5bfc..5421a4d 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -110,11 +110,10 @@ const MainWindow = new Lang.Class({
         this.mapView.connect('gone-to-user-location',
                              this._connectMapMove.bind(this));
 
-        Application.settings.connect('changed::track-user-location', (function() {
-            if(Application.settings.get_boolean('track-user-location')) {
-                this.mapView.gotoUserLocation(true);
-            }
-        }).bind(this));
+        this.mapView.connect('user-location-changed',
+                             this._onUserLocationChange.bind(this));
+        Application.settings.connect('changed::track-user-location',
+                                     this._onUserLocationChange.bind(this));
     },
 
     _connectMapMove: function() {
@@ -133,6 +132,12 @@ const MainWindow = new Lang.Class({
         }
     },
 
+    _onUserLocationChange: function() {
+        if(Application.settings.get_boolean('track-user-location')) {
+            this.mapView.gotoUserLocation(true);
+        }
+    },
+
     _saveWindowGeometry: function() {
         let window = this.window.get_window();
         let state = window.get_state();
diff --git a/src/mapView.js b/src/mapView.js
index 22a332a..5ca2015 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -77,7 +77,10 @@ const MapView = new Lang.Class({
         this._factory = Champlain.MapSourceFactory.dup_default();
         this.setMapType(MapType.STREET);
 
-        this._showUserLocation();
+        this._geoclue = new Geoclue.Geoclue();
+        this._updateUserLocation();
+        this._geoclue.connect("location-changed",
+                              this._updateUserLocation.bind(this));
     },
 
     setMapType: function(mapType) {
@@ -141,21 +144,15 @@ const MapView = new Lang.Class({
                     this._userLocation.longitude);
     },
 
-    _showUserLocation: function() {
-        this._geoclue = new Geoclue.Geoclue();
+    _updateUserLocation: function() {
+        if (this._geoclue.location == null)
+            return;
 
-        let onLocationChanged = Lang.bind(this,
-            function() {
-                if (this._geoclue.location == null)
-                    return;
-
-                this._userLocation =
-                    new UserLocation.UserLocation(this._geoclue.location,
-                                                  this);
-                this._userLocation.show(this._userLocationLayer);
-            });
-        this._geoclue.connect("location-changed", onLocationChanged);
-        onLocationChanged();
+        this._userLocation
+            = new UserLocation.UserLocation(this._geoclue.location,
+                                            this);
+        this._userLocation.show(this._userLocationLayer);
+        this.emit('user-location-changed');
     },
 
     _showLocations: function(locations) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]