From 58efe1f850d5c2d613a97339ad4caad0af1cc661 Mon Sep 17 00:00:00 2001 From: Lutz Helm Date: Thu, 14 Mar 2019 11:29:14 +0100 Subject: [PATCH] Limit IIIF tile source percentages to 10 decimals max IIIF Image API versions 1 and 2 recommend limiting the number of decimals digits to 10 at most. --- src/ol/source/IIIF.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/ol/source/IIIF.js b/src/ol/source/IIIF.js index 4748ccd0d3..ec49e7a9b7 100644 --- a/src/ol/source/IIIF.js +++ b/src/ol/source/IIIF.js @@ -34,6 +34,9 @@ import TileImage from './TileImage.js'; * @property {boolean} [wrapX=false] */ +function formatPercentage(percentage) { + return percentage.toLocaleString('en', {maximumFractionDigits: 10}); +} /** * @classdesc @@ -191,10 +194,10 @@ class IIIF extends TileImage { } else if (!supportsArbitraryTiling || features.includes('regionByPx')) { regionParam = regionX + ',' + regionY + ',' + regionW + ',' + regionH; } else if (features.includes('regionByPct')) { - const pctX = regionX / width * 100, - pctY = regionY / height * 100, - pctW = regionW / width * 100, - pctH = regionH / height * 100; + const pctX = formatPercentage(regionX / width * 100), + pctY = formatPercentage(regionY / height * 100), + pctW = formatPercentage(regionW / width * 100), + pctH = formatPercentage(regionH / height * 100); regionParam = 'pct:' + pctX + ',' + pctY + ',' + pctW + ',' + pctH; } if (version == Versions.VERSION3 && (!supportsArbitraryTiling || features.includes('sizeByWh'))) { @@ -206,7 +209,7 @@ class IIIF extends TileImage { } else if (features.includes('sizeByWh')) { sizeParam = sizeW + ',' + sizeH; } else if (features.includes('sizeByPct')) { - sizeParam = 'pct:' + (100 / scale); + sizeParam = 'pct:' + formatPercentage(100 / scale); } } else { regionParam = 'full';