[gnome-maps/wip/mlundblad/place-zoom-levels: 4/4] mapWalker: Use place zoom level helper
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/place-zoom-levels: 4/4] mapWalker: Use place zoom level helper
- Date: Sun, 12 Dec 2021 22:25:08 +0000 (UTC)
commit 25d78f5f5254cc70e36681215633538a4604c594
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 when
no bounding box is available.
src/mapWalker.js | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
---
diff --git a/src/mapWalker.js b/src/mapWalker.js
index 16366077..c5d6e3ea 100644
--- a/src/mapWalker.js
+++ b/src/mapWalker.js
@@ -27,6 +27,7 @@ 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 +63,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 lowe 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
+ * 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]