From fcf6e81430981fca3ce8a71b193ac3c4c4da4680 Mon Sep 17 00:00:00 2001 From: Kai Volland Date: Fri, 8 Mar 2019 11:29:36 +0100 Subject: [PATCH] Fixes issue with ScaleLine Math.pow with negative exponents is inaccurate in chrome v74. `toFixed` is called on the result to fix this. --- src/ol/control/ScaleLine.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ol/control/ScaleLine.js b/src/ol/control/ScaleLine.js index f7d349f21a..57902cb09c 100644 --- a/src/ol/control/ScaleLine.js +++ b/src/ol/control/ScaleLine.js @@ -260,10 +260,11 @@ class ScaleLine extends Control { let i = 3 * Math.floor( Math.log(this.minWidth_ * pointResolution) / Math.log(10)); - let count, width; + let count, width, decimalCount; while (true) { - count = LEADING_DIGITS[((i % 3) + 3) % 3] * - Math.pow(10, Math.floor(i / 3)); + decimalCount = Math.floor(i / 3); + const decimal = Math.pow(10, decimalCount); + count = LEADING_DIGITS[((i % 3) + 3) % 3] * decimal; width = Math.round(count / pointResolution); if (isNaN(width)) { this.element.style.display = 'none'; @@ -274,12 +275,11 @@ class ScaleLine extends Control { } ++i; } - let html; if (this.scaleBar_) { html = this.createScaleBar(width, count, suffix); } else { - html = count + ' ' + suffix; + html = count.toFixed(decimalCount < 0 ? -decimalCount : 0) + ' ' + suffix; } if (this.renderedHTML_ != html) {