change index of layer

Sep 28, 2011 at 4:08 PM

can i change order layer?

for example my layer ist 

t1

t2

t3

 

i need to change t3 position with t1.

 

thank you

Coordinator
Sep 28, 2011 at 11:08 PM

you need to remove all layers and readd them in the order you want

Hth FObermaier

Developer
Sep 29, 2011 at 6:03 AM

For faster You can use follow:

 

int layerIndex =3;

int layerTo=1;
SharpMap.Layers.ILayer layer = myMap.Layers[layerIndex];
myMap.Layers.RemoveAt(layerIndex);
myMap.Layers.Insert(layerTo - 1, layer);

 

Oct 14, 2011 at 9:51 AM
Edited Oct 14, 2011 at 9:52 AM

In SharpMap.Layers.LayerCollection

 

public new void Insert(int index, ILayer layer)       

{

          if (index > Count || index < 0)

            {

                throw new ArgumentOutOfRangeException("index", index, "Index not in range");

            }

            //Items.Insert(index, layer);

          //Raise the Add New Event

            base.InsertItem(0, layer);

 }

Shouldn't be base.Insert(index, layer) ?

Developer
Oct 15, 2011 at 6:12 AM

I have not used LayerCollection class. Follow me should be .

Oct 15, 2011 at 11:25 AM
trieuvy wrote:

For faster You can use follow:

 

int layerIndex =3;

int layerTo=1;
SharpMap.Layers.ILayer layer = myMap.Layers[layerIndex];
myMap.Layers.RemoveAt(layerIndex);
myMap.Layers.Insert(layerTo - 1, layer);

 

I don't understsand, myMap.Layers is actually a LayerCollection

Developer
Oct 16, 2011 at 6:28 AM

Hi Steelraiden,

Sorry, I have a mistake. I use older version of Sharpmap. Old version Sharpmap have not used  LayerCollection class. Maps.cs follow : this.Layers = new Collection<SharpMap.Layers.ILayer>();

TrieuVy

Oct 16, 2011 at 8:48 AM

Hi trieuvy,

Ok but in the current trunk the Insert method doesn't work properly, since it just insert a specified layer in position 0 whatever is the index passed in the function

Oct 16, 2011 at 1:24 PM

yes inert method only inaaert layer in position 0!

Developer
Oct 17, 2011 at 2:42 AM
Edited Oct 17, 2011 at 2:44 AM

Hi,

Follow frank_am:  Insert at 0 for : "now raises the LayerListChange event when the insert method is called".

You  can change to Items.Insert(index, layer);  for your need.

Or : remove all layers and readd them in the order you want

TrieuVy.