Infrastructure Map Server Developer

Infrastructure Map Server Developer

Active Contributor
Posts: 26
Registered: ‎09-10-2009
Message 1 of 5 (2,061 Views)
Accepted Solution

Displaying a selection set

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



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

    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)
    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: 
End Sub


Valued Mentor
Posts: 277
Registered: ‎10-06-2008
Message 2 of 5 (2,047 Views)

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 code executes on the (web) server-side.


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


- Jackie

Active Contributor
Posts: 26
Registered: ‎09-10-2009
Message 3 of 5 (2,035 Views)

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,



New Member
Posts: 1
Registered: ‎01-22-2001
Message 4 of 5 (1,983 Views)

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
End Sub




Active Contributor
Posts: 26
Registered: ‎09-10-2009
Message 5 of 5 (1,981 Views)

Re: Displaying a selection set

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

Thanks Scott, that worked like a charm.

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.