Hi walter,
I am using below code for getting all the nearest node and comparing each and every node distance with the last dropped node
I have doubt here when I am calculating the distance
let distance = part.actualBounds.center.distanceSquaredPoint(droppt) < dist
what does it means for center
automaticConnection() {
this.diagram.startTransaction(“add link”);
let modelData = this.diagram.model.nodeDataArray;
let index = this.diagram.model.nodeDataArray.length;
var dropedNodeKey = this.diagram.model.nodeDataArray[index - 1].key;
var droppt = this.diagram.lastInput.documentPoint;
var nearby = this.diagram.findPartsNear(droppt, 300, true, true);
if (nearby.count > 1) {
var dist = Infinity;
var closest = null;
nearby.each(function (part) {
let distance = part.actualBounds.center.distanceSquaredPoint(droppt) < dist
let isNodePart = part instanceof go.Node;
if (isNodePart && part.data.key != dropedNodeKey) {
dist = part.actualBounds.center.distanceSquaredPoint(droppt);
closest = part;
}
})
if (closest !== null) {
this.diagram.model.addLinkData({ from: closest.data.key, to: dropedNodeKey, });
}
}
this.diagram.commitTransaction(“add link”);
}

what is happening here when I will drop 2nd node it will connect to with the first node that’s correct but when I will drop 3rd node it should connect with the 2nd node. but again it is connecting with the first node that’s the problem.
can you look my code and check distance calculation part how I am doing is correct or wrong