Можно ли в Konva.Transformer заполнять якоря формой? Я имею в виду, мне нужно добавить еще один слой, чтобы сделать собственные якоря, или я могу сделать что-то прямо в компоненте Transformer?
return (
<>
<Rect
x = {100}
y = {100}
fill = "red"
width = {200}
height = {100}
ref = {rectRef}
/>
<Transformer
ref = {transformerRef}
rotateEnabled
rotateAnchorOffset = {48}
keepRatio = {false}
anchorFill = {'yellow'}
borderDash = {[5,10]}
padding = {10}
/>
На данный момент [email protected]
не поддерживает такие функции.
В качестве обходного пути вы можете:
patternImage
. const trRef = React.useRef();
const anchorShapeCanvas = React.useMemo(() => {
const canvas = document.createElement("canvas");
canvas.width = 12;
canvas.height = 12;
const ctx = canvas.getContext("2d");
ctx.strokeStyle = "black";
ctx.beginPath();
ctx.lineTo(0, 0);
ctx.lineTo(12, 0);
ctx.lineTo(12, 4);
ctx.lineTo(4, 4);
ctx.lineTo(4, 12);
ctx.lineTo(0, 12);
ctx.closePath();
ctx.stroke();
ctx.stroke = "2px";
return canvas;
}, []);
React.useEffect(() => {
if (isSelected) {
// we need to attach transformer manually
trRef.current.nodes([shapeRef.current]);
trRef.current.find(".top-left").fillPriority("pattern");
trRef.current.find(".top-left").fillPatternImage(anchorShapeCanvas);
trRef.current.find(".top-left").strokeEnabled(false);
trRef.current.getLayer().batchDraw();
}
}, [isSelected]);