diff options
author | Marcus Lundblad <ml@update.uu.se> | 2021-11-29 22:48:20 +0100 |
---|---|---|
committer | Marcus Lundblad <ml@update.uu.se> | 2022-01-06 23:25:40 +0100 |
commit | cffa794fe6423cd6bd040f7bb1af21ed5d4c0c53 (patch) | |
tree | dd27447b4c4c09d4954393037e8a15f159f3c3dd | |
parent | 9d3fab7f7bc3d2da5a39dcfb55d5ef9d5be6d76e (diff) | |
download | gnome-maps-wip/mlundblad/place-zoom-levels.tar.gz |
mapWalker: Use place zoom level helperwip/mlundblad/place-zoom-levels
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.
-rw-r--r-- | src/mapWalker.js | 33 |
1 files 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); } } |