[mapguide-users] Initializing resourceService within VB.Net

Jason Birch Jason.Birch at nanaimo.ca
Fri Apr 7 13:56:46 EDT 2006


Next time you're in Nanaimo, give me a shout; I'd be happy to stand you
a beer :)

Jason 

-----Original Message-----
From: Kori Maleski [mailto:km at pat.ca] 
Sent: Friday, April 07, 2006 10:49
To: users at mapguide.osgeo.org
Subject: Re: [mapguide-users] Initializing resourceService within VB.Net


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

            'Connect
            MapGuideApi.InitializeSockets()
            'InitializeWebTier()

            '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()
            l_oSite.Open(l_oCred)

            Dim l_oFeatureSrvc As MgFeatureService =
l_oSite.CreateService(MgServiceType.FeatureService)
            Dim l_oResourceSrvc As MgResourceService =
l_oSite.CreateService(MgServiceType.ResourceService)


            '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
MgCoordinateSystemFactory
                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 =
l_oMGCoordinateSystemFactory.Create(l_sWKTproj)
                'Lower Left Coordinate
                Dim l_oMGCoordinateLatLonLL As MgCoordinate =
l_oMGGeometryFactory.CreateCoordinateXY(l_dMinX, l_dMinY)
                Dim l_oMGCoordinateXYLL As MgCoordinate =
l_oMGCoordinateSystem.ConvertFromLonLat(l_oMGCoordinateLatLonLL)
                'Upper Right Coordinate
                Dim l_oMGCoordinateLatLonUR As MgCoordinate =
l_oMGGeometryFactory.CreateCoordinateXY(l_dMaxX, l_dMaxY)
                Dim l_oMGCoordinateXYUR As MgCoordinate =
l_oMGCoordinateSystem.ConvertFromLonLat(l_oMGCoordinateLatLonUR)

                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()
                Else
                    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 =
l_oMap.GetLayerGroups()

            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 =
l_oLayer.GetFeatureClassName()
            'Set Filter to Selection IDs
            Dim l_oQuery As New MgFeatureQueryOptions()
            l_oQuery.SetFilter(l_sFilter)

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

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

            Else 'Nested Layer Groups
                ' Split LayerGroup parameter
                Dim l_oLayerGroupArray As String() =
l_sLayerGroups.Split("|"c)
                Dim i As Integer
                For i = 0 To l_oLayerGroupArray.GetUpperBound(0)
                    l_oLayerGroup =
l_cLayerGroups.GetItem(l_oLayerGroupArray(i).ToString())
                    l_oLayerGroup.SetVisible(True)
                Next
            End If


            'Turn Layer Visibility On
            l_oLayer.SetVisible(True)
            'Save Map
            l_oMap.Save(l_oResourceSrvc)

            '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
            MapGuideApi.TerminateSockets()

        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-t140997
6.html#a3808359
Sent from the OSGeo MapGuide forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe at mapguide.osgeo.org
For additional commands, e-mail: users-help at mapguide.osgeo.org






More information about the Mapguide-users mailing list