Deleting/Removing a vector layer

Topics: General Topics
Jan 15, 2007 at 4:42 AM
Ok, I give up... How do you delete a single layer from the SharpMap map? There only seems to be the Clear() method which deletes ALL layers:

//remove all existing layers
mapImage1.Map.Layers.Clear();

I would expect either a Delete/Remove method here:

for (int i = 0; i < mapImage1.Map.Layers.Count; i++)
{
if (mapImage1.Map.Layersi.LayerName == "myLayerToDelete")
{
mapImage1.Map.Layersi.???????();
}
}


- Dirk
Coordinator
Jan 15, 2007 at 7:32 AM
Hi Dirk

Don't give up!

Just try:

mapImage1.Map.Layer.RemoveAt(i);


Christian
Mainz / Germany


Jan 15, 2007 at 11:11 AM
Christian -

Huh? This code won't compile:

for (int i = 0; i < mapImage1.Map.Layers.Count; i++)
{
if (mapImage1.Map.Layersi.LayerName == "myNewChurches")
{
mapImage1.Map.Layer.RemoveAti;
}
}

I'm not seeing a "RemoveAt" method in the Object Browser? Is this in the version 0.9 binaries that I'm using or in some newer source code version?

- Dirk

BTW - any chance you can fix your link to your SimpleChart example?
Coordinator
Jan 15, 2007 at 11:31 AM
Okay,

My sample was for the latest change set, but in V0.9 it should be same syntax.

BR
/Christian
Jan 15, 2007 at 12:34 PM
RemoveAt() is part of Layers not Layer.

for (int i = 0; i < mapImage1.Map.Layers.Count; i++)
{
if (mapImage1.Map.Layersi.LayerName == "myNewChurches")
{
mapImage1.Map.Layers.RemoveAt(i);
}
}

:-)
Coordinator
Jan 15, 2007 at 2:24 PM
Yeah,

You are right! Sorry for this misleading.

Christian
Jan 16, 2007 at 3:36 AM
Christian & FatBoyJim -

Thanks for the clarifications. I finally realized what I did wrong - two typos and a poor assumption on the same line of code! I put:

mapImage1.Map.Layer.RemoveAti;

instead of:

mapImage1.Map.Layers.RemoveAt(i);

I feel like Homer Simpson. Sorry for the confusion but more importantly, thanks for helping me get this working.

- Dirk