[gnome-maps/wip/mlundblad/place-zoom-levels] 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] mapWalker: Use place zoom level helper
- Date: Thu, 6 Jan 2022 21:29:52 +0000 (UTC)
commit acacc670507a325b6864d3b035bdf51c9b9c9096
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 | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
---
diff --git a/src/mapWalker.js b/src/mapWalker.js
index 16366077..08db80a0 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 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]