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
Solved! Go to Solution.
Solved by soudemans. Go to Solution.
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
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
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