[mapguide-users] Remove layer C#
Jackie Ng
jackie.ng at aecsystems.com.au
Wed Sep 5 20:26:41 EDT 2007
Remove() is expecting a MgLayerBase object, you are passing in a string.
Hence the compilation error.
Maybe try something like this instead:
MgMap map = new MgMap(siteConnection);
map.Open(mgMapName);
MgLayerCollection layerCol = map.GetLayers();
string layerName = "myLayer";
MgLayer layerToRemove = null;
foreach(MgLayer layer in layerCol)
{
if(layer.Name == layerName)
{
layerToRemove = layer;
break;
}
}
if(layerToRemove != null)
{
layerCol.Remove(layerToRemove);
}
- Jackie.
Alex Fordyce wrote:
>
> I'm to see if a layer exists and remove it if it exists. The layer would
> have been saved as a temporary resource. Here is the code.
>
> // get the map
> MgMap map = new MgMap(siteConnection);
> map.Open(mgMapName);
>
> MgLayerCollection layerCol = map.GetLayers();
>
> if(layerCol.Contains("myLayer"))
> {
> layerCol.Remove("myLayer");
> }
>
> .... Add myLayer code here .....
>
> I get the following error whether or not the layer exists:
>
> Compiler Error Message: CS1502: The best overloaded method match for
> 'OSGeo.MapGuide.MgLayerCollection.Remove(OSGeo.MapGuide.MgLayerBase)' has
> some invalid arguments
>
> Source Error:
>
> Line 42: if(layerCol.Contains("myLayer"))
> Line 43: {
> Line 44: layerCol.Remove("myLayer");
> Line 45: }
> Line 46:
>
> Anyone have any suggestions?
>
> Thanks in advance.
>
> alex
>
--
View this message in context: http://www.nabble.com/Remove-layer-C--tf4388428s16610.html#a12513568
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list