首页 > 解决方案 > 在 GMap 的 polyoverlays 中删除特定的多边形

问题描述

我正在尝试找到一种方法,让软件在天气警报超时时删除特定的多边形。

它创建得很好,但我在如何根据其名称/ID 删除它时遇到问题。

下面是代码。

 Public Sub DrawPolygon(ByVal m As Integer, n As Integer)

        ' now draw on alert map
        Dim i As Integer
        Dim fld() As String
        Dim dLat As Double, dLong As Double

        Dim Red As String
        Dim Green As String
        Dim Blue As String
        Dim plotColor As String

        Dim dLatMax As Double = 0.0
        Dim dLongMax As Double = -180.0
        Dim dLatMin As Double = 90.0
        Dim dLongMin As Double = 180.0

        Dim drawColor As Color

        For k = 0 To MasterNWSAlerts.Count - 1

            If MasterNWSAlerts(k).inputalert.IndexOf(CountyDB(m).alertsTable(n).sAlert) <> -1 Then

                Red = Val("&H" & Mid(MasterNWSAlerts(k).plotColor, 1, 2))
                Green = Val("&H" & Mid(MasterNWSAlerts(k).plotColor, 3, 2))
                Blue = Val("&H" & Mid(MasterNWSAlerts(k).plotColor, 5, 2))

                plotColor = MasterNWSAlerts(k).plotColor

                Exit For
            End If
        Next


        drawColor = ConvertToRbg(plotColor)

        fld = CountyDB(m).alertsTable(n).polygon.Split(" ")

        Dim points = New List(Of PointLatLng)

        For i = 0 To fld.Count - 1 Step 2

            dLat = Val(fld(i)) / 100
            dLong = (Val(fld(i + 1)) / 100) * -1

            If dLat > dLatMax Then dLatMax = dLat
            If dLong > dLongMax Then dLongMax = dLong

            If dLat < dLatMin Then dLatMin = dLat
            If dLong < dLongMin Then dLongMin = dLong

            points.Add(New PointLatLng(dLat, dLong))

        Next

        dLat = Val(fld(0)) / 100
        dLong = (Val(fld(1)) / 100) * -1

        points.Add(New PointLatLng(dLat, dLong))

        Dim polygon = New GMapPolygon(points, CountyDB(m).alertsTable(n).alertID)

        polygon.Fill = New SolidBrush(Color.FromArgb(0, drawColor))

        polygon.Stroke = New Pen(drawColor, 2)

        polygon.IsHitTestVisible = True

        polyOverlay.Polygons.Add(polygon)

        GMapControl.Overlays.Add(polyOverlay)

        ' recenter map

        If ConfigurationSettings.bAutoCenterAutoZoomEnabled Then

            GMapControl.Position = CalculateCenterOfPolygon(points)

            Dim rect As New RectLatLng(dLatMax, dLongMin, dLongMax - dLongMin, dLatMax - dLatMin)

            GMapControl.SetZoomToFitRect(rect)

            ConfigurationSettings.AlertMapCenterLatitude = dLat
            ConfigurationSettings.AlertMapCenterLongitude = dLong

        End If

        ' next commands force repaint

        '  GMapControl.Width += 1
        ' GMapControl.Width -= 1

        GMapControl.Refresh()

        ActivePolygons += 1

        'fill in text box with latest alert

        ToolStripStatusLabel1.Text = UCase(CountyDB(m).alertsTable(n).sAlert)
        AlertMapTextBox.Text = CountyDB(m).alertsTable(n).detailedText

        ' now save off map into file

        SaveAlertMapImage(CountyDB(m).alertsTable(n).alertID)

    End Sub

    Public Sub DeletePolygon(ByVal m As Integer, ByVal alertindex As Integer)

        If CountyDB(m).alertsTable(alertindex).polygon <> vbNullString Then

*** this is where I am having the issue - how to selected the appropriate polygon within polyoverlay

            Dim polygon = New GMapPolygon(CountyDB(m).alertsTable(alertindex).alertID)

            'GMapControl.Overlays()

            ActivePolygons -= 1

            GMapControl.Refresh()

        End If

    End Sub

标签: vb.net

解决方案


推荐阅读