Reputation: 51
When adding a stroke to a Konva polygon (Line
with closed: = true
), half the width of the stroke is added to the size of the polygon.
Example: https://codesandbox.io/s/loving-kirch-8692q
This is a problem, when there are two touching polygons, since the two strokes overlap.
Is there a way to prevent this?
Upvotes: 1
Views: 987
Reputation: 51
I found a solution using globalCompositeOperation
. An example can be found here.
Upvotes: 1
Reputation: 20288
That is how strokes work in 2d canvas API. The workaround is to make a polygon smaller by half of the stroke size:
const strokeWidth = 5;
const halfStroke = strokeWidth / 2;
const poly1 = new Konva.Line({
points: [
10 + halfStroke,
10 + halfStroke,
10 + halfStroke,
50 - halfStroke,
50 - halfStroke,
50 - halfStroke,
50 - halfStroke,
10 + halfStroke
],
fill: "#00D2FF",
stroke: "black",
strokeWidth: 5,
closed: true
});
Demo: https://codesandbox.io/s/konva-stroke-9okr6
Upvotes: 1