You can keep the actor+useCase connected by repositioning the connecting line when actor or useCase are dragged.
Assume you have 3 kinetic nodes or groups:
- An actor node,
- A useCase node,
- A kinetic line dedicated to connecting them.
Set up dragmove event handlers for actor and useCase.
// when the actor is dragged, reposition the connecting line
actor.on('dragmove', function () {
connectThem(actor,useCase,connectingLine);
});
// when the useCase is dragged, reposition the connecting line
useCase.on('dragmove', function () {
connectThem(actor,useCase,connectingLine);
});
In the dragmove handler, get the actor and useCase positions and reposition the connecting line.
// reposition the line to connect the actor & useCase
function connectThem(actor,useCase,connectingLine){
// get the XY of the actor+useCase to connect
var x1 = actor.getX();
var y1 = actor.getY();
var x2 = useCase.getX();
var y2 = useCase.getY();
// reposition the connecting line
connectingLine.setPoints([x1,y1,x2,y2]);
// send the connecting line to the back
connectingLine.setZIndex(0);
// redraw the layer
layer.draw();
};