Skip to content

Commit

Permalink
fix: Fix an issue cropping large canvas quads
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Oct 7, 2022
1 parent 21d227b commit 339c704
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/canvas/quadFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 339c704

Please sign in to comment.