[mapguide-users] Remove layer C#

Alex Fordyce afordyce at ix.netcom.com
Thu Sep 6 12:14:30 EDT 2007


Worked perfectly. Thank you very much. Now my application allows the user to
create multiple queries on the same "query layer". Rather than creating a
new layer for each query. 

Thanks again. 




Jackie Ng wrote:
> 
> 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#a12526003
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list