/
WaypointMapItemControlProvider.vb
161 lines (154 loc) · 7.25 KB
/
WaypointMapItemControlProvider.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWin
Imports DevExpress.XtraMap
Imports DevExpress.XtraReports.UI
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.IO
Imports System.Linq
Imports System.Reflection
Imports System.Windows.Forms
Namespace DevExpress.DashboardWin.CustomItemExtension
Public Class WaypointMapItemControlProvider
Inherits CustomControlProviderBase
Public Shared ReadOnly Property BingCopyright() As String
Get
Return "Copyright © " & Date.Now.Year & " Microsoft and its suppliers. All rights reserved."
End Get
End Property
Private ReadOnly defaultLineColor As Color = Color.FromArgb(125, 255, 212, 106)
Private ReadOnly highlightLineColor As Color = Color.FromArgb(200, 255, 212, 106)
Private ReadOnly SelectionLineColor As Color = Color.FromArgb(255, 255, 212, 106)
Private dashboardItem As CustomDashboardItem(Of WaypointMapItemMetadata)
Private map As MapControl
Private vectorLayer As VectorItemsLayer
Private mapItemStorage As MapItemStorage
Private validationInfoItem As MapOverlayTextItem
Private flatData As DashboardFlatDataSource
Private skipSelectionEvent As Boolean = False
Protected Overrides ReadOnly Property Control() As Control
Get
Return map
End Get
End Property
Public Sub New(ByVal dashboardItem As CustomDashboardItem(Of WaypointMapItemMetadata), ByVal bingKey As String)
Me.dashboardItem = dashboardItem
map = New MapControl()
AddHandler map.MapItemClick, AddressOf MapItemClickHandler
AddHandler map.SelectionChanged, AddressOf Map_SelectionChanged
map.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder
map.EnableRotation = False
map.NavigationPanelOptions.Visible = False
Dim imageLayer As New ImageLayer() With {.Transparency = 1}
mapItemStorage = New MapItemStorage()
vectorLayer = New VectorItemsLayer()
vectorLayer.Data = mapItemStorage
map.Layers.Add(imageLayer)
map.Layers.Add(vectorLayer)
imageLayer.DataProvider = New BingMapDataProvider() With {.BingKey = bingKey}
SetupMapOverlays()
End Sub
Protected Overrides Sub UpdateControl(ByVal customItemData As CustomItemData)
flatData = customItemData.GetFlatData()
mapItemStorage.Items.BeginUpdate()
mapItemStorage.Items.Clear()
If ValidateBindings() Then
PopulateMapItems(flatData)
End If
mapItemStorage.Items.EndUpdate()
map.ZoomToFitLayerItems()
SetSelectionMode()
End Sub
Protected Overrides Sub SetSelection(ByVal selection As CustomItemSelection)
skipSelectionEvent = True
vectorLayer.SelectedItems.Clear()
Dim selectedRows As IList(Of DashboardFlatDataSourceRow) = selection.GetDashboardFlatDataSourceRows(flatData)
Dim selectedLines = mapItemStorage.Items.Where(Function(item) selectedRows.Contains(item.Tag))
vectorLayer.SelectedItems.AddRange(selectedLines.ToList())
skipSelectionEvent = False
End Sub
Protected Overrides Function GetPrintableControl(ByVal customItemData As CustomItemData, ByVal exportInfo As CustomItemExportInfo) As XRControl
Dim container As New PrintableComponentContainer()
container.PrintableComponent = map
Return container
End Function
Private Sub Map_SelectionChanged(ByVal sender As Object, ByVal e As MapSelectionChangedEventArgs)
If skipSelectionEvent Then
Return
End If
Dim selectedRows = e.Selection.OfType(Of MapPolyline)().Select(Function(polyline) polyline.Tag).OfType(Of DashboardFlatDataSourceRow)()
If selectedRows.Count() > 0 AndAlso Interactivity.CanSetMasterFilter Then
Interactivity.SetMasterFilter(selectedRows)
ElseIf Interactivity.CanClearMasterFilter Then
Interactivity.ClearMasterFilter()
End If
End Sub
Private Sub MapItemClickHandler(ByVal sender As Object, ByVal e As MapItemClickEventArgs)
e.Handled = e.MouseArgs.Button = MouseButtons.Right
End Sub
Private Function ValidateBindings() As Boolean
If Interactivity.IsDrillDownEnabled Then
validationInfoItem.Text = "Waypoint Map Item does not support Drill-Down"
validationInfoItem.Visible = True
Return False
Else
validationInfoItem.Visible = False
End If
Return dashboardItem.Metadata.SourceLatitude IsNot Nothing AndAlso dashboardItem.Metadata.SourceLongitude IsNot Nothing AndAlso dashboardItem.Metadata.TargetLatitude IsNot Nothing AndAlso dashboardItem.Metadata.TargetLongitude IsNot Nothing
End Function
Private Sub PopulateMapItems(ByVal flatData As DashboardFlatDataSource)
For Each dataRow As DashboardFlatDataSourceRow In flatData
Dim startPoint As New CartesianPoint(Convert.ToDouble(flatData.GetValue(dashboardItem.Metadata.SourceLongitude.UniqueId, dataRow)), Convert.ToDouble(flatData.GetValue(dashboardItem.Metadata.SourceLatitude.UniqueId, dataRow)))
Dim endPoint As New CartesianPoint(Convert.ToDouble(flatData.GetValue(dashboardItem.Metadata.TargetLongitude.UniqueId, dataRow)), Convert.ToDouble(flatData.GetValue(dashboardItem.Metadata.TargetLatitude.UniqueId, dataRow)))
Dim polyline = New MapPolyline() With {.Tag = dataRow}
polyline.Points.AddRange(New CartesianPoint() { startPoint, endPoint })
SetPolylineDrawOptions(polyline)
mapItemStorage.Items.Add(polyline)
Next dataRow
End Sub
Private Sub SetSelectionMode()
Select Case Interactivity.MasterFilterMode
Case DashboardItemMasterFilterMode.None
map.SelectionMode = ElementSelectionMode.None
vectorLayer.EnableHighlighting = False
Return
Case DashboardItemMasterFilterMode.Multiple
map.SelectionMode = ElementSelectionMode.Extended
vectorLayer.EnableHighlighting = True
Case DashboardItemMasterFilterMode.Single
map.SelectionMode = ElementSelectionMode.Single
vectorLayer.EnableHighlighting = True
End Select
End Sub
Private Sub SetPolylineDrawOptions(ByVal shape As MapPolyline)
shape.IsGeodesic = True
shape.Stroke = defaultLineColor
shape.StrokeWidth = 3
shape.SelectedStroke = SelectionLineColor
shape.SelectedStrokeWidth = 4
shape.HighlightedStroke = highlightLineColor
shape.HighlightedStrokeWidth = 4
End Sub
Private Sub SetupMapOverlays()
Dim validationOverlay As New MapOverlay() With {.Alignment = ContentAlignment.MiddleCenter}
validationInfoItem = New MapOverlayTextItem() With {.Visible = False}
validationOverlay.Items.Add(validationInfoItem)
map.Overlays.Add(validationOverlay)
Dim copyrightOverlay As New MapOverlay() With {.Alignment = ContentAlignment.BottomRight}
Using stream As Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("DevExpress.DashboardWin.CustomItemExtension.Images.BingLogo.png")
If stream IsNot Nothing Then
Dim copyrightImageItem As New MapOverlayImageItem()
copyrightImageItem.Image = Image.FromStream(stream)
copyrightImageItem.Alignment = ContentAlignment.MiddleLeft
copyrightOverlay.Items.Add(copyrightImageItem)
End If
End Using
Dim copyrightLabelItem As New MapOverlayTextItem()
copyrightLabelItem.Text = BingCopyright
copyrightLabelItem.Alignment = ContentAlignment.MiddleRight
copyrightOverlay.Items.Add(copyrightLabelItem)
map.Overlays.Add(copyrightOverlay)
End Sub
End Class
End Namespace