[mapguide-users] Add new layer to map

Kenneth Skovhede, GEOGRAF A/S ks at geograf.dk
Wed Jan 21 03:00:42 EST 2009


You probably have to use the MgLayer class, and not the semi-absctract 
base class MgLayerBase:

Dim newLayer As New MgLayer(resID, resourceSrvc)


Regards, Kenneth Skovhede, GEOGRAF A/S



sekko970 skrev:
> Dear all,
> I need to add a layer to my map from XML definition.
>
> This is my code:
>
>     Public Sub CreateLater(ByVal sessionID As String, ByVal mapName As
> String, _
>                                    ByVal newLayerName As String, ByVal
> groupName As String)
>
>         Dim userInfo As New MgUserInformation
>         userInfo.SetMgSessionId(sessionID)
>
>         Dim siteConn As New MgSiteConnection
>         siteConn.Open(userInfo)
>
>         Dim resourceSrvc As MgResourceService =
> siteConn.CreateService(MgServiceType.ResourceService)
>         Dim map As New MgMap()
>         map.Open(resourceSrvc, mapName)
>
>         'Loading XML layer
>         Dim newLayerXML As New XmlDocument
>         newLayerXML.Load(Me.MapPath("NewLayer.xml"))
>
>         'Saving new layer in session repository
>         Dim byteSource As New
> MgByteSource(Encoding.UTF8.GetBytes(newLayerXML.OuterXml),
> newLayerXML.OuterXml.Length)
>         byteSource.SetMimeType(MgMimeType.Xml)
>         Dim resID As New MgResourceIdentifier("Session:" & sessionID & "//"
> & newLayerName & "." & MgResourceType.LayerDefinition)
>         resourceSrvc.SetResource(resID, byteSource.GetReader(), Nothing)
>         Dim newLayer As New MgLayerBase(resID, resourceSrvc)
>
>         'Add new layer to group
>         Dim layerGroup As MgLayerGroup = Nothing
>         If map.GetLayerGroups().Contains(groupName) Then
>             layerGroup = map.GetLayerGroups.GetItem(groupName)
>         Else
>             layerGroup = New MgLayerGroup(groupName)
>             layerGroup.SetVisible(True)
>             layerGroup.SetDisplayInLegend(True)
>             layerGroup.SetLegendLabel(groupName)
>             map.GetLayerGroups.Add(layerGroup)
>         End If
>         newLayer.SetGroup(layerGroup)
>
>         'Insert new layer to map
>         newLayer.SetName(newLayerName)
>         newLayer.SetVisible(True)
>         newLayer.SetLegendLabel(newLayerName)
>         newLayer.SetDisplayInLegend(True)
>         map.GetLayers.Insert(0, newLayer)
>
>         map.Save(resourceSrvc)
>
> Saving the map, an MgNotImplementedException occurs.
>
> Where is my mistake?
>
> Thanks in advance for your help.
> Fabio
>
>   


More information about the mapguide-users mailing list