ThinkGeo.com    |     Documentation    |     Premium Support

Layer Order Vs Standard controls order

I have a curious question. I have noticed that the first layer added will be the bottom-most layer in a map which does make sense. My question relates to how other controls and objects interact with this order. For instance, a tree view's first object is displayed top most. If I want to maintain my layers in a tree view and dynamically add layers to the map, they will be in opposite order.


I would like to always have the top most layer in the map be the top most object in the tree view so that it is intuitive to the user. I'm pretty sure this is something that many people have run into so I am interested in what some user's solutions have been.


While this particular circumstance relates to my Desktop Application, with the Web Application I got around this by binding a Checkbox list to a SQL statement and reversed the order depending on whether I was adding the layers to the map control or binding to the Checkbox list. This was kind of hacky and I thought others might have a better approach.


Thanks. 



Hi Nelson. I haven't had to do this, and others would probably have a much neater solution, but perhaps I can add some value:P 



When you add your layers to the map control, perhaps keep a reference to them in a    List< KeyValuePair< int, InMemoryFeatureLayer> >   or similar.


That way you can set the key of the KeyValuePair as a rank to keep track of the order that you add your layers. You can also use a simple Linq Statement to reverse this order when binding to the checkboxlist "list.OrderByDescending(entity => entity.Key)". 



I'm not sure that you will find a built in method, but a simple list with a reference to the layers you add may help. 



Regards 

Brendan



Nelson, 



Also you can add your own Extension Method to the LayerOverlay, which will make it very easy to use. 



Creating the following class 


   public static class LayerOverLayExtension
    {
        public static Layer GetLayerReversed(this LayerOverlay layerOverlay, int index)
        {
            // usually you need to do the parameter checking for "index", here just ignore it to make it simple
            return layerOverlay.Layers[layerOverlay.Layers.Count - index - 1];
        }

Then you can call the method directly. 


winformsMap1.StaticOverlay.GetLayerReversed(0);

Thanks, 



Ben 

 



I think that’s a more elegant solution:P

Thank you both. Very neat!

It's my pleasure:)