Consecutively adding nodes through model.addNodeData will overwrite the previous node


new Binding(‘location’, ‘loc’, Point.parse).makeTwoWay(Point.stringify)

When I continued to manually create nodes through mode.addNodeData(loc was null), all nodes were overwritten.

Is there any way to get the proper position before adding?

Somehow each Node needs to get a real location or else the Node cannot be drawn anywhere. One way is through a binding, but if there is no source value, that won’t help. Since you seem to be adding node data programmatically, the user is not positioning them manually, so that does not help either. If there is a layout, that will do it automatically upon committing the transaction, but either you must not have one or you have not yet finished the transaction, so a layout is not helping give nodes locations either.

If all of those ways of giving nodes real locations are not available, then your code needs to assign the locations. Since you have a binding, you can either set the property on the node data object, or you can find the corresponding Node with Diagram.findNodeForData and assign its Node.location or Node.position.