From 339c704202380a51e512b760eafbd8f4fa33d210 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Fri, 7 Oct 2022 16:46:23 -0400 Subject: [PATCH] fix: Fix an issue cropping large canvas quads --- src/canvas/quadFeature.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/canvas/quadFeature.js b/src/canvas/quadFeature.js index dad410440a..9ae4b27120 100644 --- a/src/canvas/quadFeature.js +++ b/src/canvas/quadFeature.js @@ -172,8 +172,10 @@ var canvas_quadFeature = function (arg) { var p0 = map.gcsToDisplay({x: quad.pos[0], y: quad.pos[1]}, null), p2 = map.gcsToDisplay({x: quad.pos[6], y: quad.pos[7]}, null), p3 = map.gcsToDisplay({x: quad.pos[9], y: quad.pos[10]}, null); - context2d.setTransform((p3.x - p2.x) / w, (p3.y - p2.y) / w, - (p0.x - p2.x) / h, (p0.y - p2.y) / h, + const cw = Math.min(w, quad.crop ? quad.crop.x || w : w); + const ch = Math.min(h, quad.crop ? quad.crop.y || h : h); + context2d.setTransform((p3.x - p2.x) / cw, (p3.y - p2.y) / cw, + (p0.x - p2.x) / ch, (p0.y - p2.y) / ch, p2.x, p2.y); if (quad.opacity !== opacity) { opacity = quad.opacity; @@ -191,7 +193,7 @@ var canvas_quadFeature = function (arg) { if (w && h && cropw > 0 && croph > 0 && cropx1 > cropx0 && cropy1 > cropy0) { context2d.drawImage( src, - cropx0, cropy0, Math.floor((cropx1 - cropx0) * cropw / w), Math.floor((cropy1 - cropy0) * croph / h), + cropx0, cropy0, Math.floor((cropx1 - cropx0) * cropw / cw), Math.floor((cropy1 - cropy0) * croph / ch), 0, 0, cropw, croph); } }