Autodesk MapGuide Enterprise Developer
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Displaying a selection set
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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(_Selection
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(_Selection Xml)
End Sub
Solved! Go to Solution.
Re: Displaying a selection set
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Re: Displaying a selection set
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Re: Displaying a selection set
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Re: Displaying a selection set
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks Scott, that worked like a charm.

