-
-
Notifications
You must be signed in to change notification settings - Fork 147
Open
Description
i am adding custom object like arrow from blow code drow arrow is working fine
but when i retrieved from json it will gives me error
ERROR TypeError: Cannot read property 'fromObject' of undefined
at fabric.js:1062
below is my code for draw arrow
this.LineWithArrow = fabric.util.createClass(fabric.Line, {
type: 'lineWithArrow',
hasBorders: false,
hasControls: true,
_getCacheCanvasDimensions() {
var dim = this.callSuper('_getCacheCanvasDimensions');
dim.width += 15;
dim.height += 15;
return dim;
},
_render(ctx) {
this.callSuper('_render', ctx);
ctx.save();
const xDiff = this.x2 - this.x1;
const yDiff = this.y2 - this.y1;
const angle = Math.atan2(yDiff, xDiff);
ctx.translate((this.x2 - this.x1) / 2, (this.y2 - this.y1) / 2);
ctx.rotate(angle);
ctx.beginPath();
// Move 5px in front of line to start the arrow so it does not have the square line end showing in front (0,0)
ctx.moveTo(this.strokeWidth * 2, 0);
ctx.lineTo(this.strokeWidth * -1.5, this.strokeWidth * 1.5);
ctx.lineTo(this.strokeWidth * -1.5, this.strokeWidth * -1.5);
ctx.closePath();
ctx.fillStyle = this.stroke;
ctx.fill();
ctx.restore();
},
});
this.LineWithArrow.fromObject = (object, callback) => {
callback && callback(new this.LineWithArrow([object.x1, object.y1, object.x2, object.y2], object));
};
bytesleo
Metadata
Metadata
Assignees
Labels
No labels