Saving Location of Node with addNodeData

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.

BTW: GoJS Nodes -- Northwoods Software

I bind the location for the node using:

fileDiagram.nodeTemplate =
    $(go.Node, "Auto",
        { ... },
        new go.Binding("location", "location").makeTwoWay()
    )

…and I don’t have a layout set for the diagram. That being said, I tried setting a layout but got the same results:

layout: $(go.Layout, { isInitial: false, isOngoing: false })

Before refresh:
image

After refresh (the two entities are stacked on top of each other):
image
Any other ideas?

I figured it out. I needed to bind the position as well:

new go.Binding("position", "location").makeTwoWay()

No, binding either Node.position or Node.location should be sufficient.

Are you using go-debug.js? Are there any warnings or errors in the console window? Have you read GoJS Data Binding -- Northwoods Software ?

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) ); }

That use of Point is fine.

I think there is some problem with the way that you are persisting the model. But I have no idea of what you are doing, so I can’t suggest anything.

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…