[gnome-maps] Fix view adjustment for 1 search result



commit 37d0e25fb082927a0c93742fbbd8ad6bb3d5eccd
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Mar 27 04:41:02 2013 +0200

    Fix view adjustment for 1 search result
    
    View adjustment after search was broken if there was only 1 hit. This
    patch fixes it by simply asking the view to go to the single location
    found.

 src/mainToolbar.js |   49 ++++++++++++++++++++++++++++---------------------
 1 files changed, 28 insertions(+), 21 deletions(-)
---
diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index 85389bb..0fea279 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -73,11 +73,6 @@ const MainToolbar = new Lang.Class({
         if (locations.length == 0)
             return;
 
-        let min_latitude = 90;
-        let max_latitude = -90;
-        let min_longitude = 180;
-        let max_longitude = -180;
-
         locations.forEach(Lang.bind(this,
             function(location) {
                 log ("location: " + location);
@@ -86,23 +81,35 @@ const MainToolbar = new Lang.Class({
                 marker.set_location(location.latitude, location.longitude);
                 this._markerLayer.add_marker(marker);
                 log ("Added marker at " + location.latitude + ", " + location.longitude);
-
-                if (location.latitude > max_latitude)
-                    max_latitude = location.latitude;
-                if (location.latitude < min_latitude)
-                    min_latitude = location.latitude;
-                if (location.longitude > max_longitude)
-                    max_longitude = location.longitude;
-                if (location.longitude < min_longitude)
-                    min_longitude = location.longitude;
             }));
 
-        let bbox = new Champlain.BoundingBox();
-        bbox.left = min_longitude;
-        bbox.right = max_longitude;
-        bbox.bottom = min_latitude;
-        bbox.top = max_latitude;
-
-        this._mainWindow.view.ensure_visible (bbox, true);
+        if (locations.length == 1)
+            this._mainWindow.view.go_to(locations[0].latitude, locations[0].longitude);
+        else {
+            let min_latitude = 90;
+            let max_latitude = -90;
+            let min_longitude = 180;
+            let max_longitude = -180;
+
+            locations.forEach(Lang.bind(this,
+                function(location) {
+                    if (location.latitude > max_latitude)
+                        max_latitude = location.latitude;
+                    if (location.latitude < min_latitude)
+                        min_latitude = location.latitude;
+                    if (location.longitude > max_longitude)
+                        max_longitude = location.longitude;
+                    if (location.longitude < min_longitude)
+                        min_longitude = location.longitude;
+                }));
+
+            let bbox = new Champlain.BoundingBox();
+            bbox.left = min_longitude;
+            bbox.right = max_longitude;
+            bbox.bottom = min_latitude;
+            bbox.top = max_latitude;
+
+            this._mainWindow.view.ensure_visible(bbox, true);
+        }
     }
 });


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