[gnome-maps/wip/fix-geoloc: 11/11] MapView: pan to new user locations



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

    MapView: pan to new user locations
    
    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.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=704537

 src/mainWindow.js |   15 ++++++++++-----
 src/mapView.js    |   23 ++++++++++-------------
 2 files changed, 20 insertions(+), 18 deletions(-)
---
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 8aef8a4..a524f3c 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._onUserLocationChanged.bind(this));
+        Application.settings.connect('changed::track-user-location',
+                                     this._onUserLocationChanged.bind(this));
     },
 
     _connectMapMove: function() {
@@ -132,6 +131,12 @@ const MainWindow = new Lang.Class({
         }
     },
 
+    _onUserLocationChanged: 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 c5dc949..5478fe5 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) {
@@ -136,19 +139,13 @@ const MapView = new Lang.Class({
         return box.covers(this._userLocation.latitude, this._userLocation.longitude);
     },
 
-    _showUserLocation: function() {
-        this._geoclue = new Geoclue.Geoclue();
-
-        let onLocationChanged = Lang.bind(this,
-            function() {
-                if (this._geoclue.location == null)
-                    return;
+    _updateUserLocation: function() {
+        if (!this._geoclue.location)
+            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]