[mapguide-users] Trouble Adding Existing Layers Programmatically

Jackie Ng jumpinjackie at gmail.com
Mon May 25 02:54:05 EDT 2009


The duplicate object is most likely caused by the line:

map.GetLayers().Add(listLayer)

If there is a possibility of this code path being executed more than once,
you should check for the existence of the layer (by name) before adding it
to the map.

- Jackie


Jamo wrote:
> 
> Anyone able to tell me why this would not be working?
> I'm trying to add a layer that already exists in the repositry... it
> errors with duplicate object.... ? though it is not in the map as of yet.
> 
> or is it because this is attempting to create a new layer in the repositry
> ? MgLayer listLayer = new MgLayer(LibLayer, ResourceService); ?
> 
> I'm attempting to add the layers programatically when a user selects them,
> however it could be just as good to add the layer to the map definition,
> which of these would you prefer?
> 
> 
>      
> MapGuideApi.MgInitializeWebTier(Request.ServerVariables["APPL_PHYSICAL_PATH"]
> + "../webconfig.ini");
>       MgUserInformation userInfo = new MgUserInformation(sessionID);
>       MgSite site = new MgSite();
>       //connect to site
>       site.Open(userInfo);
> 
>       MgSiteConnection siteConnection = new MgSiteConnection();
>       //open site connection
>       siteConnection.Open(userInfo);
>       MgResourceService ResourceService =
> siteConnection.CreateService(MgServiceType.ResourceService) as
> MgResourceService;
>       MgFeatureService FeatureService =
> siteConnection.CreateService(MgServiceType.FeatureService) as
> MgFeatureService;
> 
> 
>       MgMap map = new MgMap(siteConnection);
>       map.Open(mapName);
>       MgResourceIdentifier LibLayer = new
> MgResourceIdentifier("Library://Markup/" + mapName + "/" +
> LayersDDL.SelectedItem.Text + ".LayerDefinition");
> 
>       MgLayer listLayer = new MgLayer(LibLayer, ResourceService);
> 
>       map.GetLayers().Add(listLayer);
>       map.Save(ResourceService);
> 
> 

-- 
View this message in context: http://n2.nabble.com/Trouble-Adding-Existing-Layers-Programmatically-tp1807961p2968260.html
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list