From 852f6552c7dae58996893ba271c672d082f71fca Mon Sep 17 00:00:00 2001 From: philip Date: Sat, 11 Jan 2020 17:26:52 +0000 Subject: [PATCH] Fix pixel rounding --- src/ol/reproj.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/ol/reproj.js b/src/ol/reproj.js index 2e3fd7f1ec2..518e8155720 100644 --- a/src/ol/reproj.js +++ b/src/ol/reproj.js @@ -176,6 +176,10 @@ export function render(width, height, pixelRatio, context.scale(pixelRatio, pixelRatio); + function pixelRound(value) { + return Math.round(value * pixelRatio) / pixelRatio; + } + context.globalCompositeOperation = 'lighter'; const sourceDataExtent = createEmpty(); @@ -271,12 +275,12 @@ export function render(width, height, pixelRatio, if (isBrokenDiagonalRendering()) { // Make sure that everything is on pixel boundaries - const u0r = Math.round(u0); - const v0r = Math.round(v0); - const u1r = Math.round(u1); - const v1r = Math.round(v1); - const u2r = Math.round(u2); - const v2r = Math.round(v2); + const u0r = pixelRound(u0); + const v0r = pixelRound(v0); + const u1r = pixelRound(u1); + const v1r = pixelRound(v1); + const u2r = pixelRound(u2); + const v2r = pixelRound(v2); // Make sure that all lines are horizontal or vertical context.moveTo(u1r, v1r); // This is the diagonal line. Do it in 4 steps @@ -285,10 +289,10 @@ export function render(width, height, pixelRatio, const vd = v0r - v1r; for (let step = 0; step < steps; step++) { // Go horizontally - context.lineTo(u1r + Math.round((step + 1) * ud / steps), v1r + Math.round(step * vd / (steps - 1))); + context.lineTo(u1r + pixelRound((step + 1) * ud / steps), v1r + pixelRound(step * vd / (steps - 1))); // Go vertically if (step != (steps - 1)) { - context.lineTo(u1r + Math.round((step + 1) * ud / steps), v1r + Math.round((step + 1) * vd / (steps - 1))); + context.lineTo(u1r + pixelRound((step + 1) * ud / steps), v1r + pixelRound((step + 1) * vd / (steps - 1))); } } // We are almost at u0r, v0r