Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
285
Get MapElement by Name
posted

I have a map with 2 layers and it is set to show the second layer once the map is zoomed in on. It is also set up to zoom in to the map element when the element is clicked on. There are a number of other shapefiles that need to be added to the project, but I only want them to be added if that area of the map is clicked on. How do I get the name of the element that has been clicked and pass it as a variable so it can be added as a map layer? This is assuming my shapefiles would be named the same as the map element name.

Thanks.

Parents
No Data
Reply
  • 285
    Suggested Answer
    posted

    I was able to answer my own question. For those of you who would like to do the same thing, you must assign a name to each of your map elements first. Here is the code I used:

    Private Sub xamWebMap_ElementClick(ByVal sender As Object, ByVal e As MapElementClickEventArgs)
            Dim map1 As XamWebMap = DirectCast(sender, XamWebMap)
            Dim i As Integer
            i += 1
            For Each ele As MapElement In map1.Layers(0).Elements
                Dim builder As New StringBuilder()
                ele.Name = builder.Append("name" + i.ToString()).ToString
                i = i + 1
            Next
            Dim elementName As String = e.Element.Name

            map1.WindowFit(e.Element)
            Dim layer As MapLayer = DirectCast(map1.Layers.FindName(elementName).ElementAt(0), MapLayer)
            Dim elements As IEnumerable(Of MapElement) = TryCast(layer.Elements.FindElement("Caption", "Counties"), IEnumerable(Of MapElement))
            For Each element As MapElement In layer.Elements
                pop.IsOpen = False
                element.IsClickable = False
            Next
            If elements.Count() > 0 Then
                pop.IsOpen = True
                Dim element As MapElement = TryCast(elements.ElementAt(0), MapElement)
                element.Caption = Nothing
            End If
        End Sub

    Its not pretty, but it works. If someone has a better way of doing this I'm all ears.
Children