[gnome-maps] mapLocation: set zoom-level to cover place bbox



commit f6163e3206854322b7a3a784b3c082baa6d6e99a
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Wed Jan 29 15:58:27 2014 +0100

    mapLocation: set zoom-level to cover place bbox
    
    Find and use the first zoom-level that covers the place
    bounding box.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=722865

 src/mapLocation.js |   71 +++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 51 insertions(+), 20 deletions(-)
---
diff --git a/src/mapLocation.js b/src/mapLocation.js
index 3c56086..c01029c 100644
--- a/src/mapLocation.js
+++ b/src/mapLocation.js
@@ -121,26 +121,38 @@ const MapLocation = new Lang.Class({
     zoomToFit: function() {
         let zoom;
 
-        switch (this.placeType) {
-        case Geocode.PlaceType.STREET:
-            zoom = 16;
-            break;
-
-        case Geocode.PlaceType.CITY:
-            zoom = 11;
-            break;
-
-        case Geocode.PlaceType.REGION:
-            zoom = 10;
-            break;
-
-        case Geocode.PlaceType.COUNTRY:
-            zoom = 6;
-            break;
-
-        default:
-            zoom = 11;
-            break;
+        if (this.bbox !== null) {
+            let max = this._view.max_zoom_level;
+            let min = this._view.min_zoom_level;
+            for (let i = max; i >= min; i--) {
+                let zoom_box = this._view.get_bounding_box_for_zoom_level(i);
+                if (this._boxCovers(zoom_box)) {
+                    zoom = i;
+                    break;
+                }
+            }
+        } else {
+            switch (this.placeType) {
+            case Geocode.PlaceType.STREET:
+                zoom = 16;
+                break;
+
+            case Geocode.PlaceType.CITY:
+                zoom = 11;
+                break;
+
+            case Geocode.PlaceType.REGION:
+                zoom = 10;
+                break;
+
+            case Geocode.PlaceType.COUNTRY:
+                zoom = 6;
+                break;
+
+            default:
+                zoom = 11;
+                break;
+            }
         }
         this._view.set_zoom_level(zoom);
     },
@@ -176,6 +188,25 @@ const MapLocation = new Lang.Class({
         }
     },
 
+    _boxCovers: function(coverBox) {
+        if (this.bbox === null)
+            return false;
+
+        if (coverBox.left > this.bbox.left)
+            return false;
+
+        if (coverBox.right < this.bbox.right)
+            return false;
+
+        if (coverBox.top < this.bbox.top)
+            return false;
+
+        if (coverBox.bottom > this.bbox.bottom)
+            return false;
+
+        return true;
+    },
+
     _updateGoToDuration: function(fromLocation) {
         let toLocation = new Geocode.Location({
             latitude: this.latitude,


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