From 19adc5cd547068c7db99e8e83e6a4901f13bbc09 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Sat, 26 Apr 2025 20:49:20 +0200 Subject: [PATCH] consistently round non-integer initial zoom when zooming in/out MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …when using the zoom buttons or +/- keyboard shortcuts (i.e. does not affect the mouse-wheel/pinch zooming) Also: make zoom in/out transition slightly faster. In sum, this allows to zoom in/out multiple levels in quick succession, and using the zoom buttons should be more intuive: they don't snap to very-close zoom levels anymore (e.g. hitting `+` when the current zoom was 15.97 would previously result in a final zoom of 16.00, which is not really what a user would need. Now the zooming in results in a final zoom level of 17.00, which is "actually properly zoomed in". initial zoom | operation | final zoom (new) | final zoom (old code) ----- | --- | ----- | ----- 16.00 | `+` | 17.00 | 17.00 16.00 | `-` | 15.00 | 15.00 16.10 | `+` | 17.00 | 17.00 16.10 | `-` | 15.00 | 15.00 15.90 | `+` | 17.00 | 16.00 15.90 | `-` | 15.00 | 14.00 --- CHANGELOG.md | 1 + modules/renderer/map.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d7de0153..e1bcb5132 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ _Breaking developer changes, which may affect downstream projects or sites that #### :sparkles: Usability & Accessibility * Show full relation label as hover-text in _membership editor_, disambiguate relations with duplicate labels by appending the relation id ([#10492]) +* More consistently round non-integer initial zoom when zooming in/out when using the zoom buttons or `+`/`-` keyboard shortcuts #### :scissors: Operations * Preserve the sum of certain tags (`step_count`, `parking:*:capacity`) during _join_ operation ([#10492], thanks [@ChaitanyaKadu03]) * Preserve total value of `parking:*:capacity` tags during _split_ operation by distributing it proportionally to the resulting ways ([#10492]) diff --git a/modules/renderer/map.js b/modules/renderer/map.js index b5d71a369..6141f24ba 100644 --- a/modules/renderer/map.js +++ b/modules/renderer/map.js @@ -825,11 +825,11 @@ export function rendererMap(context) { function zoomIn(delta) { - setCenterZoom(map.center(), ~~map.zoom() + delta, 250, true); + setCenterZoom(map.center(), Math.trunc(map.zoom() + 0.45) + delta, 150, true); } function zoomOut(delta) { - setCenterZoom(map.center(), ~~map.zoom() - delta, 250, true); + setCenterZoom(map.center(), Math.ceil(map.zoom() - 0.45) - delta, 150, true); } map.zoomIn = function() { zoomIn(1); };