with fabric I'm trying to create a line with two circle endpoints. I can move the circles at the endpoints and the line updates. However if I move the line the circles don't move. Any suggestions?
JSFiddle here http://jsfiddle.net/gfk0r2pf/10/
var self = this;
var canvas = new fabric.Canvas('c', {
selection: true
});
var line = new fabric.Line([50, 50, 100, 100], {
fill: 'red',
stroke: 'red',
strokeWidth: 2,
selectable: true,
hasControls: false,
hasBorders: false,
centeredRotation: false,
centeredScaling: false,
//originX: 'center',
//originY: 'center'
});
var circle1 = new fabric.Circle({
radius: 5,
fill: 'green',
left: 45,
top: 45,
hasControls: false,
hasBorders: false,
name: 'circle1'
});
var circle2 = new fabric.Circle({
radius: 5,
fill: 'green',
left: 95,
top: 95,
hasControls: false,
hasBorders: false,
name: 'circle2'
});
canvas.on('object:moving', function (options) {
var objType = options.target.get('type');
var p = options.target;
if (objType == 'line') {
circle1.set({ x1: line.x1, y1: line.y1 });
circle2.set({ left: line.x2, top: line.y2 });
}
if (objType == 'circle') {
if (p.name == 'circle1') {
line.set({
x1: circle1.getCenterPoint().x, y1: circle1.getCenterPoint().y, selectable: true
});
} else {
if (p.name == 'circle2') {
line.set({
x2: circle2.getCenterPoint().x, y2: circle2.getCenterPoint().y, selectable: true
});
}
}
}
line.setCoords();
circle1.setCoords();
circle2.setCoords();
canvas.renderAll();
});
canvas.add(line);
canvas.add(circle1);
canvas.add(circle2);
canvas.renderAll();
I had gone through your fiddle and fixed the problem , Please check it. Now it seems working.. check it this http://jsfiddle.net/Ahammadalipk/gfk0r2pf/14/