When a user double clicks or uses a context menu to add a new node, the createNode function is called passing the position where the user wants to create the node. The node is created successfully at the specified location; however, when I create multiple nodes and then refresh the page, all newly created nodes move and overlap at the same position as the last created node. How do I make it so that it saves the location of each node individually? Here is the code of my function that is called. I have tried both committing the diagram and the model (see commented code).
function createNode(location) {
fileDiagram.commit(function() {
var model = fileDiagram.model;
// model.startTransaction("add node");
model.addNodeData({ text: "RELATION", fields:[{name:"", dataType:"", isUnderline:false}], location:location });
// model.commitTransaction("add node");
});
}
What you see is the Diagram.layout arranging the nodes when you load a diagram model. If you have a Binding of the Node.location for all of your nodes in your model data, and if you have set Diagram.layout to an instance of some type of Layout, then I suggest that you set Layout.isInitial to false.
No issues found when using go-debug.js and, yes, I read the link you provided. I am using documentPoint instead of a new go.Point to set the location. Could that be part of the problem?
function(e) { createNode(e.documentPoint); }
vs.
function(e) { createNode( new go.Point(somepoint) ); }
Thanks for your help. I am not sure where the issue is either. I don’t touch location at any other point. I guess I will just stick with the solution I posted…