Maximum layers

Oct 16, 2014 at 10:24 PM
Hi,

What is the maximum amount of layers which I can use?

I want to use NShape for a visualization application which visualizes workorder locations on a floor plan (bitmap). The floor plan will be on layer 0 as a bitmap/background and all the workorders will be shown on separate layers. The workorder info is loaded from a sql db and has x,y info and a fixed shape (circle).

The problem is that the amount of workorders may be 1000 or more. Can NShape handle this well (creating a new layer for each workorder and draw a single circle on it)?

Thanx...
Coordinator
Oct 17, 2014 at 3:00 PM
The maximum number of layers in NShape is 31.

Extending this limit to 63 could be done with acceptable effort but extending it to more than thousand layers will be difficult when it comes to drawing speed and memory footprint. As NShape was designed to be scalable to large amounts of shapes, this is difficult.

On the other side, you could implement the your own layer management and map only the visibility to NShape layers:
  • Define Shape-WorkorderLayer mappings
  • Define 1 NShape layers and set it to invisible when initializing the display
  • When the user switches the visibility of a WorkorderLayer, assign all shapes of this WorkorderLayer to the invisible NShape layer (using DiagramSetController.AssignShapesToLayers) and refresh the display.
Hope this helps...
Oct 17, 2014 at 10:55 PM
@KurtHolzinger,

I looked into the source code and already saw the number of layers being restricted to a fixed number. I got into the layer approach since it isn't possible to toggle a shapes visibility by code.

I need to further investigate NShape and see how it might fit my needs.

Thanx for the quick reply...
Aug 23, 2016 at 3:02 AM
I also meet the similar problem, I am trying to import AutoCAD (*.dwg) file format into NShape,
normally dwg has 100+ layers, so I think it's better that NShape could support 256 layers.

I don't know if I can search the code and simply change Max_Layer_Number to 256, then it works.
Any suggestions?
Coordinator
Nov 11, 2016 at 9:15 AM
Edited Nov 11, 2016 at 11:49 AM
The problem is that layers are implemented as flags (32 bit at the moment), so changing the maximum layers to 63 will obviously not be such a great deal, whereas changing to >100 will be.
At the moment, this requirement cannot be implemented with reasonable effort.

I spoke with the NShape architecture team about the problem and we will not extend the maximum layer count in the near future. What we can talk about, is a IsVisible property for shapes, so you could implement the layers in your application and hide shapes.

Another workaround would be to implement the layer management in your application (the Shape class has a string property "Data" where user defined content can be stored) and use the existing layer system for showing/hiding shapes:
One layer is set to visible, the other one to invisible. Whenever s shape should change it's visibility, call
diagram.RemoveShapeFromLayers(shape, LayerIds.All);
diagram.AddShapeToLayers(shape, newLayerIds);
Due to the current implementation, layer assignment is fast as hell - so there should be no performance impact from the layer assignments at all.
For optimization, you can call
((IDiagrampresenter)display).SuspendUpdate() 
before the layer assignments and
((IDiagrampresenter)display).ResumeUpdate() 
afterwards in order to suppress the automatic re-drawing of the shapes after layer assignment.