[mapguide-users] Trouble Adding Existing Layers Programmatically
Kenneth Skovhede, GEOGRAF A/S
ks at geograf.dk
Mon May 25 03:01:21 EDT 2009
Also, to clear up any confusion:
The MgMap object is the runtime map.
The MgLayer objects are layers attached to the runtime map (runtime layers).
"new MgLayer" does not create anything (other than the object itself).
You reference a LayerDefinition in an MgLayer, you do not create the layer.
You can think of the runtime map as a binary copy of the MapDefinition.
The runtime layers only contain a few attributes (visible, show in
legend, etc.),
and otherwise just reference the layer.
If you were to modify the MapDefinition, you would have to restart the
viewer to display the changes.
Also, any other user who happens to start the viewer after the update
will see the changes.
Changes to the runtime map only happens for the current user, so you can
alter the runtime map as much
as you like, and still allow other users to see the map as expected.
You can probably decide what is the best solution in your case, but
unless you are building
a new map editor, you are likely best off with the runtime map.
Regards, Kenneth Skovhede, GEOGRAF A/S
Jackie Ng skrev:
> 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);
>>
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20090525/2fd25021/attachment.html
More information about the mapguide-users
mailing list