-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.vb
68 lines (59 loc) · 2.75 KB
/
MainWindow.xaml.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Imports DevExpress.Xpf.Map
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes
Namespace DXMapShapeFile1
''' <summary>
''' Interaction logic for MainWindow.xaml
''' </summary>
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub vLayer_MouseDoubleClick(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
Dim point As GeoPoint = CType(mapControl.ScreenPointToCoordPoint(e.GetPosition(mapControl)), GeoPoint)
Dim hi = mapControl.CalcHitInfo(e.GetPosition(mapControl))
For Each item In vectorLayer.Data.DisplayItems
If IsPointInsideItem(item, point) Then
Me.Title = item.Attributes("NAME").Value.ToString()
End If
Next item
End Sub
Private Function IsPointInsideItem(ByVal item As MapItem, ByVal point As GeoPoint) As Boolean
Dim polygon As MapPolygon = TryCast(item, MapPolygon)
If polygon IsNot Nothing Then
Return IsPointInside(polygon.Points.Cast(Of GeoPoint)().ToArray(), point)
End If
Dim path As MapPath = TryCast(item, MapPath)
If path IsNot Nothing Then
Dim segments = CType(path.Data, MapPathGeometry).Figures.SelectMany(Function(f) f.Segments).Cast(Of MapPolyLineSegment)()
Return segments.Any(Function(segment) IsPointInside(segment.Points.Cast(Of GeoPoint)().ToArray(), point))
End If
Return False
End Function
Private Function IsPointInside(ByVal polygon() As GeoPoint, ByVal testPoint As GeoPoint) As Boolean
Dim result As Boolean = False
Dim j As Integer = polygon.Count() - 1
For i As Integer = 0 To polygon.Count() - 1
If polygon(i).Latitude < testPoint.Latitude AndAlso polygon(j).Latitude >= testPoint.Latitude OrElse polygon(j).Latitude < testPoint.Latitude AndAlso polygon(i).Latitude >= testPoint.Latitude Then
If polygon(i).Longitude + (testPoint.Latitude - polygon(i).Latitude) / (polygon(j).Latitude - polygon(i).Latitude) * (polygon(j).Longitude - polygon(i).Longitude) < testPoint.Longitude Then
result = Not result
End If
End If
j = i
Next i
Return result
End Function
End Class
End Namespace