[gnome-maps/wip/fix-geoloc: 3/8] MapLocation: move zoomToFit-functionality



commit f669e847e220647a654d04f1bd825e7f7943dfa3
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Wed Jul 10 18:22:34 2013 +0200

    MapLocation: move zoomToFit-functionality
    
    Move and rename zoom to fit-functionality to MapLocation since it's
    probably not very general anyways.

 src/mapLocation.js |   26 ++++++++++++++++++++++----
 src/utils.js       |   15 ---------------
 2 files changed, 22 insertions(+), 19 deletions(-)
---
diff --git a/src/mapLocation.js b/src/mapLocation.js
index ce8fe9f..6e277a3 100644
--- a/src/mapLocation.js
+++ b/src/mapLocation.js
@@ -47,11 +47,9 @@ const MapLocation = new Lang.Class({
     goTo: function(animate) {
         log("Going to " + this.description);
 
-        let zoom = Utils.getZoomLevelForAccuracy(this.accuracy);
-
         if (!animate) {
             this._view.center_on(this.latitude, this.longitude);
-            this._view.set_zoom_level(zoom);
+            this.zoomToFit();
             this.emit('gone-to');
 
             return;
@@ -70,7 +68,7 @@ const MapLocation = new Lang.Class({
 
             id = this._view.connect("animation-completed::go-to", (function() {
                 this._view.disconnect(id);
-                this._view.set_zoom_level(zoom);
+                this.zoomToFit();
                 this.emit('gone-to');
             }).bind(this));
 
@@ -95,5 +93,25 @@ const MapLocation = new Lang.Class({
         this.show(layer);
         this.goTo(animate);
     },
+
+    /**
+     *  Zoom to the maximal zoom-level that fits the accuracy circle
+     */
+    zoomToFit: function() {
+        let zoom;
+        if (this.accuracy == Geocode.LOCATION_ACCURACY_UNKNOWN)
+             zoom = 12; // Accuracy is usually city-level when unknown
+        else if (this.accuracy <= Geocode.LOCATION_ACCURACY_STREET)
+            zoom = 16;
+        else if (this.accuracy <= Geocode.LOCATION_ACCURACY_CITY)
+            zoom = 12;
+        else if (this.accuracy <= Geocode.LOCATION_ACCURACY_REGION)
+            zoom = 10;
+        else if (this.accuracy <= Geocode.LOCATION_ACCURACY_COUNTRY)
+            zoom = 6;
+        else
+            zoom = 3;
+        this._view.set_zoom_level(zoom);
+    }
 });
 Signals.addSignalMethods(MapLocation.prototype);
diff --git a/src/utils.js b/src/utils.js
index 09df902..44f72e4 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -89,21 +89,6 @@ function initActions(actionMap, simpleActionEntries, context) {
     });
 }
 
-// accuracy: double value in meters
-function getZoomLevelForAccuracy(accuracy) {
-    if (accuracy == Geocode.LOCATION_ACCURACY_UNKNOWN)
-        return 12; // Accuracy is usually city-level when unknown
-    else if (accuracy <= Geocode.LOCATION_ACCURACY_STREET)
-        return 16;
-    else if (accuracy <= Geocode.LOCATION_ACCURACY_CITY)
-        return 12;
-    else if (accuracy <= Geocode.LOCATION_ACCURACY_REGION)
-        return 10;
-    else if (accuracy <= Geocode.LOCATION_ACCURACY_COUNTRY)
-        return 6;
-    else
-        return 3;
-}
 
 function getDescriptionForAccuracy(accuracy) {
     if (accuracy == Geocode.LOCATION_ACCURACY_UNKNOWN)


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