It’s correct to start the tool the first time. In the subsequent action, starting the tool to make another link from another port, it still uses the the previously selected port.
I setup a timer to log the diagram.toolManager.linkingTool.startObject of the two actions periodically. The log shows two different object (determined by __gohashid).
The fromLinkable and toLinkable is already set though, It still didnt work.
To describe more specifically, the link will connects the two ports correctly after dropped, while the temporary port is still placed on the previous selected port (not current startObject).
The code I gave above does not exhibit that problem. Could you please provide a stand-alone sample that allows me to reproduce the problem? Please delete everything that is not necessary to cause the problem.
I cannot make a simple example to describe the issue… However, I found that if I don’t make a custom link template for LinkingTool.temporaryLink. The code works just fine.
OK, so what was your LinkingTool.temporaryLink? Note that that is not a template, but must be an actual Link that will be added and removed from the diagram as the LinkingTool is used.
I figure out that it may be related to curve: go.Link.JumpOver setting. I reused the link template for LinkingTool.temporaryLink so I said it’s a template. Without such setting, the link behaved as expected.
Actually, I’ve switched to a clean implementation (without data bindings) when I found that using default links solved the problem. The issue still exists if curve: go.Link.JumpOver is set…
Hmmm. I still don’t have any problem when the user draws a new link by clicking on the node, thereby explicitly invoking the LinkingTool as in the code I posted above, with an addition in Diagram initialization that set LinkingTool.temporaryLink:
I tried to make a simple example to describe the issue but failed. In a simple example, there’re no problems about curve: go.Link.JumpOver. I still don’t know why…
Maybe it’s related to the link templates with heavy data bindings and curve: go.Link.JumpOver is set?
Maybe your problem has nothing to do with Link.curve, and maybe I didn’t see the problem because the nodes were too close to each other when I tried it. Try adding this line to initialize the LinkingTool when starting it programmatically:
$(go.Node, . . .,
{
click: function(e, node) {
var diag = e.diagram;
e.handled = true;
diag.currentTool.doCancel();
// programmatically start the LinkingTool at this node's default port
var tool = diag.toolManager.linkingTool;
tool.startObject = node.findPort(""); // or whichever one you want...
tool.temporaryToNode.location = diag.lastInput.documentPoint;
diag.currentTool = tool; // now it is running, but not activated
tool.doActivate();
}
},
. . .
Are you using something like the code I posted above? The code doesn’t have to be invoked from a click event handler – that’s just a convenient way that my test example starts the LinkingTool.
I am unable to see any problem with the position or size of the LinkingTool.temporaryFromNode or LinkingTool.temporaryFromPort when starting the LinkingTool programmatically in that way.