summaryrefslogtreecommitdiff
path: root/loleaflet
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2020-09-01 16:24:18 +0100
committerJan Holesovsky <kendy@collabora.com>2020-09-17 15:03:01 +0200
commit3b7595701168199b2d8aa8e302a2ce866aa6c434 (patch)
tree877e5e215a9a8d2fcf71e4314de77fe068e47071 /loleaflet
parent1be56e18a52eb783ba790a56293dc99ded0ed0c4 (diff)
calc canvas: ensure that the fraction width rounds to the pixel width.
Slave CSS geometry from integral canvas pixels, don't attempt the reverse. Change-Id: I369ed1bea3c4a5a199192aa1e84bb4e03dcb2e94
Diffstat (limited to 'loleaflet')
-rw-r--r--loleaflet/src/layer/tile/CanvasTileLayer.js17
1 files changed, 13 insertions, 4 deletions
diff --git a/loleaflet/src/layer/tile/CanvasTileLayer.js b/loleaflet/src/layer/tile/CanvasTileLayer.js
index 4983fef2a..8ef3cb886 100644
--- a/loleaflet/src/layer/tile/CanvasTileLayer.js
+++ b/loleaflet/src/layer/tile/CanvasTileLayer.js
@@ -96,11 +96,20 @@ L.CanvasTilePainter = L.Class.extend({
},
_setCanvasSize: function (widthCSSPx, heightCSSPx) {
- this._canvas.style.width = widthCSSPx + 'px';
- this._canvas.style.height = heightCSSPx + 'px';
- this._canvas.width = Math.floor(widthCSSPx * this._dpiScale);
- this._canvas.height = Math.floor(heightCSSPx * this._dpiScale);
+ var pixWidth = Math.floor(widthCSSPx * this._dpiScale);
+ var pixHeight = Math.floor(heightCSSPx * this._dpiScale);
+ // real pixels have to be integral
+ this._canvas.width = pixWidth;
+ this._canvas.height = pixHeight;
+
+ // CSS pixels can be fractional, but need to round to the same real pixels
+ var cssWidth = pixWidth / this._dpiScale; // NB. beware
+ var cssHeight = pixHeight / this._dpiScale;
+ this._canvas.style.width = cssWidth.toFixed(4) + 'px';
+ this._canvas.style.height = cssHeight.toFixed(4) + 'px';
+
+ // FIXME: is this a good idea ? :
this._width = parseInt(this._canvas.style.width);
this._height = parseInt(this._canvas.style.height);
this.clear();