• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Autodesk MapGuide Enterprise Developer

    Reply
    Active Contributor
    Posts: 26
    Registered: ‎09-10-2009
    Accepted Solution

    Displaying a selection set

    1635 Views, 4 Replies
    07-23-2010 01:08 PM

    Hi,

     

    I am working on the classic "how to isolate a particular layer from a bunch of selected features and then highlight them" using VB. I have gotten as far as isolating the features, but I have not been able to find a way to update the map showing the selected features.  I have had to piece this function together from code samples in C# and Javascript.  The final piece is the 

    "Parent.Parent.mapFrame.SetSelectionXML(_SelectionXml)" at the bottom for which I cannot find a VB equivalent

     

    Any help would be much appreciated?  Code below:

     

    Protected Sub Page_Load(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles Me.Load
        Dim featureReader As MgFeatureReader
        ' Initialize MapGuide
        InitMapGuide()
    
        Dim map As New MgMap(_SiteConnection)
        map.Open(_ResourceService, _MapName)
        Dim selection As New MgSelection(map, _SelectionXml)
    
        Dim subFilterSize As Int16 = 20
        Dim SelectionString As String
        Dim layer As MgLayer = map.GetLayers().GetItem("Hydrants")
        Dim QueryOptions As MgFeatureQueryOptions = _ 
            New MgFeatureQueryOptions()
    
        SelectionString = selection.GenerateFilter _
            (layer, layer.FeatureClassName)
        QueryOptions.SetFilter(SelectionString)
        featureReader = selection.GetSelectedFeatures _
            (layer, layer.FeatureClassName, False)
        selection = New MgSelection(map)
        selection.AddFeatures(layer, featureReader, 0)
        _SelectionXml = selection.ToXml
    
        'This is the JavaScrip for which I cannot find
        '   a VB equivalent: 
        'Parent.Parent.mapFrame.SetSelectionXML(_SelectionXml)
    End Sub

     

    Please use plain text.
    Mentor
    Posts: 238
    Registered: ‎10-06-2008

    Re: Displaying a selection set

    07-29-2010 06:21 PM in reply to: soudemans

    parent.parent.mapFrame.SetSelectionXML is javascript call that executes client-side (in your web browser).

     

    Your VB.net code executes on the (web) server-side.

     

    Your VB.net code should not be calling this method (which doesn't exist), but rather it should be writing the javascript call to this method.

     

    - Jackie

    Please use plain text.
    Active Contributor
    Posts: 26
    Registered: ‎09-10-2009

    Re: Displaying a selection set

    07-30-2010 01:17 PM in reply to: soudemans

    Thanks for your suggestion Jackie,

     

    But being that I am rather new at this and since I did spent the better part of today trying to figure out how to implement your suggestion (without much success) would it be possible for you to include a bit of code to show how this is done, preferably some code that relates to the "mapguide" problem at hand?  Thanks,

     

    Sierk

    Please use plain text.
    New Member
    Posts: 1
    Registered: ‎01-22-2001

    Re: Displaying a selection set

    08-17-2010 05:24 AM in reply to: soudemans

    Hi Sierk,

     

    Here's a handy function that sends the appropriate JavaScript to the client to select features on the map based on an MgSelection object. You should be able to call this from your code just after you use selection.AddFeatures.

     

    - Scott

     

     

    ''' <summary>
    ''' Highlights the selected features on the map.
    ''' </summary>
    ''' <param name="selection">The MgSelectionBase object.</param>
    Public Sub HighlightFeatures(selectionSet As MgSelectionBase)
    	' Escape any single quotes 
    	Dim xml As String = selectionSet.ToXml().Replace("'", "\'")
    
    	' Build the JavaScript code to set the active selection
    	Dim s As String = "<script language=""javascript"">" & vbLf
    	s += "window.onload = function()" & vbLf
    	s += "{" & vbLf
    	s += "  var main = parent.parent;" & vbLf
    	s += "  var map = main.GetMapFrame();" & vbLf
    	s += "  map.SetSelectionXML('" & xml & "');" & vbLf
    	s += "}" & vbLf
    	s += "</script>" & vbLf
    
    	' Use the HttpResponse object to send this code to the client
    	Response.Write(s)
    End Sub

     

     

     

    Please use plain text.
    Active Contributor
    Posts: 26
    Registered: ‎09-10-2009

    Re: Displaying a selection set

    08-17-2010 06:31 AM in reply to: soudemans

    Thanks Scott, that worked like a charm.

    Please use plain text.