Node selectionChanged go back to previous view order

Hi,

I have node selectionChanged implemented where it temporarily moves the node into the “Foreground” layer while selected, then back to the default layer when deselected.
The pattern is very similar to this layers example: GoJS Layers -- Northwoods Software

What I’d like to happen:
After selecting and deselecting a node, it returns to it’s view order based on the node order in the array.

What happens now:
After selecting and deselecting a node, the most recently selected node stays on top, even if it was previously behind.
This can be also be seen in this layers demo: GoJS Layers -- Northwoods Software
The zOrder example on that page keeps everything in order, but it does not change layers like I want

Any solutions on how to implement this would be greatly appreciated! Thanks in advance

If you want to control the z-ordering of Parts in one Layer, you have to control their Part.zOrder property.
GoJS Layers -- Northwoods Software

1 Like

Thanks walter! That’s was one solution I was thinking about.
One other option I was considering but wasn’t sure if it’s a good approach is to re-render the entire nodes array after deselection so the nodes are rendered in the order they exist in the array. Is there an efficient way to do that?

No, it should always be more efficient to re-order existing Nodes than it is to re-create all of those Nodes. Maybe it doesn’t matter when you just have a few Nodes, but when there are a lot, it matters.

Note that having a zOrder Binding shouldn’t prevent the working of your existing binding of layerName when Part.isSelected. In fact, it will ensure that multiple nodes selected will appear in the same order in the selection Layer

1 Like