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
Add Shepfiles Dynamically
posted

I have a shapefile at the county level and need to add 50+ shapefiles at the precinct level, but only if the county is clicked on. This is the function I have:

    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("precinct" + i.ToString()).ToString
            i = i + 1
        Next
        Dim elementName As String = e.Element.Name
        map1.WindowFit(e.Element)

        Dim newLayer As New MapLayer()
        newLayer.LayerName = elementName
        newLayer.VisibleFromScale = 3
        map1.Layers.Add(newLayer)

        Dim reader As New ShapeFileReader()
        Dim converter As New DataMapping.Converter()

        reader.Uri = "Shapefiles/" + elementName
        reader.DataMapping = TryCast(converter.ConvertFromString("Caption=NAME"), DataMapping)
        newLayer.Reader = reader

        Dim layer As MapLayer = DirectCast(map1.Layers.FindName(elementName).ElementAt(0), MapLayer)
        Dim elements As IEnumerable(Of MapElement) = TryCast(layer.Elements.FindElement("Caption", "Name"), 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

I am naming all of the shapefiles precinct1, precinct2 and so on. Can anyone help?

Thanks

Parents Reply Children
No Data