Insert link programmatically between two closest ports of nodes

I have nodes which have four ports each.
grafik
I want to add a link between two nodes programmatically, using the two ports which are closest to each other.

With the linkingTool.insertLink(), I need explicitly specify the ports though.

Is there any functionality in gojs I can use to automatically determine the clostest ports of two nodes or do I need to implement my own calculation to get the two clostest ports?

Why do you need four separate ports when your app does not seem to need them for either logical or physical reasons?

If your nodes only had one port at the icon and had “…Side” spots links would automatically connect at the nearest side.

But if you really need four ports, you might be able to override LinkingTool.insertLink to call the super method with the desired arguments.

You mean a single port and go.Spot.AllSides? Good point, need to check what this would mean for us.

I believe you mean LinkingTool.insertLink? Still, I would manually need to iterate over all ports and find the ports with the shortest distance, right? Or is there some functionality in goJS which can tell me for two given nodes the two ports closest to each other?

Yes, I meant insertLink. No, there’s no standard way of choosing the “best” port – the criteria are different for most apps.

Okay, thanks!