summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcus Lundblad <ml@update.uu.se>2021-02-22 22:41:20 +0100
committerMarcus Lundblad <ml@update.uu.se>2021-04-03 22:59:09 +0200
commit315bc3ec8bf220fe3e414f38e31353ee968451ca (patch)
tree46d4b34547a6415ae0584bc8c20b5ac22cfba2a6 /src
parente46f1758d7dea515528033533a6c7d42325e027f (diff)
downloadgnome-maps-315bc3ec8bf220fe3e414f38e31353ee968451ca.tar.gz
mapView: Add method to get fitting zoom level
Add a method to get the lowest zoom level above the current level that fits a given bounding box at the current position.
Diffstat (limited to 'src')
-rw-r--r--src/mapView.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/mapView.js b/src/mapView.js
index 60bf1785..0d407c01 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -711,6 +711,33 @@ var MapView = GObject.registerClass({
new MapWalker.MapWalker(place, this).goTo(true, linear);
}
+ getZoomLevelFittingBBox(bbox) {
+ let mapSource = this.view.get_map_source();
+ let goodSize = false;
+ let zoomLevel = this.view.max_zoom_level;
+
+ do {
+
+ let minX = mapSource.get_x(zoomLevel, bbox.left);
+ let minY = mapSource.get_y(zoomLevel, bbox.bottom);
+ let maxX = mapSource.get_x(zoomLevel, bbox.right);
+ let maxY = mapSource.get_y(zoomLevel, bbox.top);
+
+ if (minY - maxY <= this.view.height &&
+ maxX - minX <= this.view.width)
+ goodSize = true;
+ else
+ zoomLevel--;
+
+ if (zoomLevel <= this.view.min_zoom_level) {
+ zoomLevel = this.view.min_zoom_level;
+ goodSize = true;
+ }
+ } while (!goodSize);
+
+ return zoomLevel;
+ }
+
showTurnPoint(turnPoint) {
if (this._turnPointMarker)
this._turnPointMarker.destroy();