Layer Management

I am trying to do the following:

  1. When creating an object using a tool like (DragCreatingTool) I want to assign the layerName property of the main Node after it is inserted.

  2. I want to persist all layers in the diagram.layers collection, and I also want to make sure that all nodes are properly associated with their respective layers.

  3. I want to load the persisted drawing with all layer information rendered from the saved drawing in step 2.

If you are talking about the DragCreatingTool specifically, you could override DragCreatingTool.insertPart (or just modify the code) to call the base method and then modify the resulting Part or Node however you like, including by setting properties on the Part.data.

The natural place to store that information is on the Model.modelData object, which will exist even if there are no nodes or links at all. I assume an Array as a property value would make sense. You’ll want to extend your model loading code to first make sure all of the layers listed in your modelData object exist in the Diagram. Then you can replace the Diagram.model to cause all of the Nodes to be created. If you have a Binding on Part.layerName, the parts will automatically be assigned to the appropriate Layers.

On saving the model, you’ll want to make sure that the modelData object has your array of layer information on it. Model.toJson will automaticalyl write it out. I recommend not saving information about any temporary layers (i.e. where Layer.isTemporary is true).

I was going down that route and wanted to make sure there wasn’t a more straightforward way.

Thanks Walter.

ERIC