[mapguide-users] Initializing resourceService within VB.Net

Kori Maleski km at pat.ca
Fri Apr 7 13:49:24 EDT 2006

Merry Christmas

I deserve a beer for this...

#Region "::: MapGuide API Functions"

        Public Function ZoomSelection(ByVal l_sZoomSelectionType As String,
ByVal l_sSession As String, ByVal l_sMapName As String, ByVal l_sLayerGroups
As String, ByVal l_sLayer As String, ByVal l_sFilter As String, Optional
ByVal l_dMinY As Double = 0, Optional ByVal l_dMinX As Double = 0, Optional
ByVal l_dMaxY As Double = 0, Optional ByVal l_dMaxX As Double = 0) As String

            Dim l_dY As Double = 0
            Dim l_dX As Double = 0
            Dim l_dWidth As Double = 0
            Dim l_dHeight As Double = 0


            'Establish Map session
            Dim l_oCred As New MgUserInformation(l_sSession)

            'connect to the site and get a feature service and a resource
service instances
            Dim l_oSite As New MgSiteConnection()

            Dim l_oFeatureSrvc As MgFeatureService =
            Dim l_oResourceSrvc As MgResourceService =

            'Create a temporary map runtime object
            Dim l_oMap As New MgMap()
            l_oMap.Open(l_oResourceSrvc, l_sMapName)

            'If performing a Zoom
            If l_sZoomSelectionType <> "SelectAll" Then

                Dim l_oMGCoordinateSystemFactory As New
                Dim l_oMGGeometryFactory As New MgGeometryFactory
                'Get Current map projection
                Dim l_sWKTproj As String = l_oMap.GetMapSRS()
                'Create Coordinate System object to Reproject points
                Dim l_oMGCoordinateSystem As MgCoordinateSystem =
                'Lower Left Coordinate
                Dim l_oMGCoordinateLatLonLL As MgCoordinate =
l_oMGGeometryFactory.CreateCoordinateXY(l_dMinX, l_dMinY)
                Dim l_oMGCoordinateXYLL As MgCoordinate =
                'Upper Right Coordinate
                Dim l_oMGCoordinateLatLonUR As MgCoordinate =
l_oMGGeometryFactory.CreateCoordinateXY(l_dMaxX, l_dMaxY)
                Dim l_oMGCoordinateXYUR As MgCoordinate =

                If l_oMGCoordinateXYUR.GetX() = l_oMGCoordinateXYLL.GetX()
And l_oMGCoordinateXYUR.GetY() - l_oMGCoordinateXYLL.GetY() Then
                    l_dX = l_oMGCoordinateXYUR.GetX()
                    l_dY = l_oMGCoordinateXYUR.GetY()
                    l_dX = (l_oMGCoordinateXYUR.GetX() -
l_oMGCoordinateXYLL.GetX()) / 2 + l_oMGCoordinateXYLL.GetX()
                    l_dY = (l_oMGCoordinateXYUR.GetY() -
l_oMGCoordinateXYLL.GetY()) / 2 + l_oMGCoordinateXYLL.GetY()
                End If

                'Get Map Width and Height
                l_dWidth = (l_oMGCoordinateXYUR.GetX() -
l_oMGCoordinateXYLL.GetX()) * 2
                l_dHeight = (l_oMGCoordinateXYUR.GetY() -
l_oMGCoordinateXYLL.GetY()) * 2
                'Which one is bigger
                If l_dHeight > l_dWidth Then
                    l_dWidth = l_dHeight

                End If
            End If

            Dim l_oLayerGroup As MgLayerGroup = Nothing
            Dim l_cLayerGroups As MgLayerGroupCollection =

            Dim l_oLayer As MgLayer = Nothing
            Dim l_cLayers As MgLayerCollection = l_oMap.GetLayers()

            'Get Layer by Name
            l_oLayer = l_cLayers.GetItem(l_sLayer)

            Dim l_sFeatureClassName As String =
            'Set Filter to Selection IDs
            Dim l_oQuery As New MgFeatureQueryOptions()

            'Get Feature Resource
            Dim l_ofeatureSource As MgResourceIdentifier = New
            'Get Feature Reader
            Dim l_ofeatures As MgFeatureReader =
l_oFeatureSrvc.SelectFeatures(l_ofeatureSource, l_sFeatureClassName,

            'Turn Layer Group Visibility On
            If l_sLayerGroups.Contains("|") = False Then
                l_oLayerGroup = l_cLayerGroups.GetItem(l_sLayerGroups)

            Else 'Nested Layer Groups
                ' Split LayerGroup parameter
                Dim l_oLayerGroupArray As String() =
                Dim i As Integer
                For i = 0 To l_oLayerGroupArray.GetUpperBound(0)
                    l_oLayerGroup =
            End If

            'Turn Layer Visibility On
            'Save Map

            'Generate XML to selection this feature
            Dim l_oSel As MgSelection = New MgSelection(l_oMap)
            'Add Features to selection
            l_oSel.AddFeatures(l_oLayer, l_ofeatures, 0)

            Dim selText As String = l_oSel.ToXml()

            'Set Javascript Function

            'If performing a Zoom and Select
            If l_sZoomSelectionType = "ZoomSelected" Then

                ZoomSelection = String.Format("ZoomSelection( {0}, {1}, {2},
'{3}' );", l_dX, l_dY, l_dWidth, selText)
                Session("MapSelectionDataXML") = selText
                'Zoom Only
            ElseIf l_sZoomSelectionType = "ZoomGoTo" Then
                ZoomSelection = String.Format("ZoomGoTo( {0}, {1}, '1200'
);", l_dX, l_dY)

                'Select Only
            ElseIf l_sZoomSelectionType = "SelectAll" Then
                ZoomSelection = String.Format("SelectAll('{0}' );", selText)
                Session("MapSelectionDataXML") = selText
            End If

            'Close Connection

        End Function

#End Region

Kori Maleski
Senior Technical Consultant 


Pacific Alliance Technologies
Suite 400 - 534 17 Ave. SW Calgary, AB CANADA T2S 0B1
TEL: 403.770.1917	 FAX: 877.691.9149 TOL: 877.691.9171  www.pat.ca

View this message in context: http://www.nabble.com/Initializing-resourceService-within-VB.Net-t1409976.html#a3808359
Sent from the OSGeo MapGuide forum at Nabble.com.

More information about the Mapguide-users mailing list