[mapguide-users] Add new layer to map

sekko970 sekko970 at virgilio.it
Tue Jan 20 08:36:07 EST 2009


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

-- 
View this message in context: http://n2.nabble.com/Add-new-layer-to-map-tp2186494p2186494.html
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list