Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle scaled output canvas correctly #10982

Merged
merged 1 commit into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/ol/render/canvas/Executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ class Executor {

/**
* @param {CanvasRenderingContext2D} context Context.
* @param {number} contextScale Scale of the context.
* @param {number} x X.
* @param {number} y Y.
* @param {import("../canvas.js").Label|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} imageOrLabel Image.
Expand All @@ -313,6 +314,7 @@ class Executor {
*/
replayImageOrLabel_(
context,
contextScale,
x,
y,
imageOrLabel,
Expand Down Expand Up @@ -395,9 +397,9 @@ class Executor {
? (strokeInstruction[2] * scale) / 2
: 0;
const intersects =
tmpExtent[0] - strokePadding <= canvas.width &&
tmpExtent[0] - strokePadding <= canvas.width / contextScale &&
tmpExtent[2] + strokePadding >= 0 &&
tmpExtent[1] - strokePadding <= canvas.height &&
tmpExtent[1] - strokePadding <= canvas.height / contextScale &&
tmpExtent[3] + strokePadding >= 0;

if (snapToPixel) {
Expand Down Expand Up @@ -593,6 +595,7 @@ class Executor {
/**
* @private
* @param {CanvasRenderingContext2D} context Context.
* @param {number} contextScale Scale of the context.
* @param {import("../../transform.js").Transform} transform Transform.
* @param {Array<*>} instructions Instructions array.
* @param {boolean} snapToPixel Snap point symbols and text to integer pixels.
Expand All @@ -604,6 +607,7 @@ class Executor {
*/
execute_(
context,
contextScale,
transform,
instructions,
snapToPixel,
Expand Down Expand Up @@ -826,6 +830,7 @@ class Executor {
}
this.replayImageOrLabel_(
context,
contextScale,
pixelCoordinates[d],
pixelCoordinates[d + 1],
image,
Expand Down Expand Up @@ -918,6 +923,7 @@ class Executor {
offsetY;
this.replayImageOrLabel_(
context,
contextScale,
/** @type {number} */ (part[0]),
/** @type {number} */ (part[1]),
label,
Expand Down Expand Up @@ -947,6 +953,7 @@ class Executor {
anchorY = baseline * label.height - offsetY;
this.replayImageOrLabel_(
context,
contextScale,
/** @type {number} */ (part[0]),
/** @type {number} */ (part[1]),
label,
Expand Down Expand Up @@ -1064,14 +1071,16 @@ class Executor {

/**
* @param {CanvasRenderingContext2D} context Context.
* @param {number} contextScale Scale of the context.
* @param {import("../../transform.js").Transform} transform Transform.
* @param {number} viewRotation View rotation.
* @param {boolean} snapToPixel Snap point symbols and text to integer pixels.
*/
execute(context, transform, viewRotation, snapToPixel) {
execute(context, contextScale, transform, viewRotation, snapToPixel) {
this.viewRotation_ = viewRotation;
this.execute_(
context,
contextScale,
transform,
this.instructions,
snapToPixel,
Expand Down Expand Up @@ -1101,6 +1110,7 @@ class Executor {
this.viewRotation_ = viewRotation;
return this.execute_(
context,
1,
transform,
this.hitDetectionInstructions,
true,
Expand Down
12 changes: 10 additions & 2 deletions src/ol/render/canvas/ExecutorGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ class ExecutorGroup {

/**
* @param {CanvasRenderingContext2D} context Context.
* @param {number} contextScale Scale of the context.
* @param {import("../../transform.js").Transform} transform Transform.
* @param {number} viewRotation View rotation.
* @param {boolean} snapToPixel Snap point symbols and test to integer pixel.
Expand All @@ -319,6 +320,7 @@ class ExecutorGroup {
*/
execute(
context,
contextScale,
transform,
viewRotation,
snapToPixel,
Expand Down Expand Up @@ -357,7 +359,13 @@ class ExecutorGroup {
declutter.push(replay, transform.slice(0));
}
} else {
replay.execute(context, transform, viewRotation, snapToPixel);
replay.execute(
context,
contextScale,
transform,
viewRotation,
snapToPixel
);
}
}
}
Expand Down Expand Up @@ -476,7 +484,7 @@ export function replayDeclutter(
});
}
const transform = executorData[i++];
executor.execute(context, transform, rotation, snapToPixel);
executor.execute(context, 1, transform, rotation, snapToPixel);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/ol/renderer/canvas/VectorLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
const declutterReplays = this.getLayer().getDeclutter() ? {} : null;
replayGroup.execute(
context,
1,
transform,
rotation,
snapToPixel,
Expand Down Expand Up @@ -255,6 +256,7 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
);
replayGroup.execute(
context,
1,
transform,
rotation,
snapToPixel,
Expand All @@ -279,6 +281,7 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
);
replayGroup.execute(
context,
1,
transform,
rotation,
snapToPixel,
Expand Down
2 changes: 2 additions & 0 deletions src/ol/renderer/canvas/VectorTileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
}
executorGroup.execute(
context,
1,
transform,
rotation,
hifi,
Expand Down Expand Up @@ -813,6 +814,7 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
const executorGroup = executorGroups[i];
executorGroup.execute(
context,
renderScale,
transform,
0,
true,
Expand Down
2 changes: 1 addition & 1 deletion test/spec/ol/render/canvas/textbuilder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function executeInstructions(
const executor = new Executor(0.02, 1, false, builder.finish());
sinon.spy(executor, 'drawLabelWithPointPlacement_');
const replayImageOrLabelStub = sinon.stub(executor, 'replayImageOrLabel_');
executor.execute(context, transform);
executor.execute(context, 1, transform);
expect(executor.drawLabelWithPointPlacement_.callCount).to.be(
expectedDrawTextImageCalls
);
Expand Down
2 changes: 1 addition & 1 deletion test/spec/ol/renderer/canvas/builder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('ol.render.canvas.BuilderGroup', function () {
!!overlaps,
builder.finish()
);
executor.execute(context, transform, 0, false);
executor.execute(context, 1, transform, 0, false);
}

beforeEach(function () {
Expand Down