[gnome-maps/wip/mlundblad/place-zoom-levels] mapWalker: Use place zoom level helper




commit cffa794fe6423cd6bd040f7bb1af21ed5d4c0c53
Author: Marcus Lundblad <ml update uu se>
Date:   Mon Nov 29 22:48:20 2021 +0100

    mapWalker: Use place zoom level helper
    
    Use the helper module to get default
    zoom level based on place type and
    use as the fallback zoom level
    when no bounding box is present
    and also as mimimum zoom level
    to ensure good context.

 src/mapWalker.js | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)
---
diff --git a/src/mapWalker.js b/src/mapWalker.js
index 16366077..dcef258c 100644
--- a/src/mapWalker.js
+++ b/src/mapWalker.js
@@ -22,11 +22,11 @@
  */
 
 const Clutter = imports.gi.Clutter;
-const Geocode = imports.gi.GeocodeGlib;
 const GObject = imports.gi.GObject;
 
 const BoundingBox = imports.boundingBox;
 const Location = imports.location;
+const PlaceZoom = imports.placeZoom;
 const Utils = imports.utils;
 
 const _MAX_DISTANCE = 19850; // half of Earth's circumference (km)
@@ -62,24 +62,23 @@ var MapWalker = GObject.registerClass({
     zoomToFit() {
         let zoom;
 
-        if (this._boundingBox !== null && this._boundingBox.isValid()) {
-            zoom = this._mapView.getZoomLevelFittingBBox(this._boundingBox);
-        } else if (this.place.initialZoom) {
+        if (this.place.initialZoom) {
             zoom = this.place.initialZoom;
         } else {
-            switch (this.place.place_type) {
-                case Geocode.PlaceType.STREET:
-                    zoom = 16;
-                    break;
-                case Geocode.PlaceType.TOWN:
-                    zoom = 11;
-                    break;
-                case Geocode.PlaceType.COUNTRY:
-                    zoom = 6;
-                    break;
-                default:
-                    zoom = this._view.max_zoom_level;
-                    break;
+            zoom = PlaceZoom.getZoomLevelForPlace(this.place) ??
+                   this._view.max_zoom_level;
+
+            /* If the place has a bounding box, use the lower of the default
+             * zoom level based on the place's type and the zoom level needed
+             * fit the bounding box. This way we ensure the bounding box will
+             * be all visible and we also have an appropriate amount
+             * of context for the place
+             */
+            if (this._boundingBox !== null && this._boundingBox.isValid()) {
+                let bboxZoom =
+                    this._mapView.getZoomLevelFittingBBox(this._boundingBox);
+
+                zoom = Math.min(zoom, bboxZoom);
             }
         }
 


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