Mini Kabibi Habibi
Imports Microsoft.VisualBasic
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Collections.Generic
Namespace DevExpress.XtraMap.Demos
Partial Public Class ShapefileSupport
Inherits MapTutorialControl
Private Const PoliticalToolTipPattern As String = "{NAME}"
Private Const GdpToolTipPattern As String = "{NAME}: ${GDP_MD_EST:#,0}M"
Private Const PopulationToolTipPattern As String = "{NAME}: {POP_EST:#,##0,,}M"
Private politicalColorizer As ChoroplethColorizer
Private gdpColorizer As ChoroplethColorizer
Private populationColorizer As ChoroplethColorizer
Private legendAlignment As LegendAlignment
Private ReadOnly Property FileLayer() As VectorFileLayer
Get
Return CType(mapControl1.Layers(0), VectorFileLayer)
End Get
End Property
Public Sub New()
InitializeComponent()
FileLayer.FileLoader = CreateShapefileLoader()
politicalColorizer = CreatePoliticalColorizer()
gdpColorizer = CreateGDPColorizer()
populationColorizer = CreatePopulationColorizer()
cbLegendAlign.SelectedIndex = 0
rgMode.SelectedIndex = 1
End Sub
Private Function CreateShapefileLoader() As ShapefileLoader
Dim loader As New ShapefileLoader()
loader.FileUri = New Uri("file:\\" & DemoUtils.GetRelativePath("Countries.shp"), UriKind.RelativeOrAbsolute)
Return loader
End Function
Private Function CreatePoliticalColorizer() As ChoroplethColorizer
Dim colorizer As New ChoroplethColorizer()
colorizer.RangeStops.AddRange(New List(Of Double) (New Double() {0, 9}))
colorizer.Colors.AddRange(New List(Of Color) (New Color() {Color.FromArgb(&H8D, &HD3, &HC7), Color.FromArgb(&HFF, &HFF, &HB3), Color.FromArgb(&HBE, &HBA, &HDA), Color.FromArgb(&HFB, &H80, &H72), Color.FromArgb(&H80, &HB1, &HD3), Color.FromArgb(&HFD, &HB4, &H62), Color.FromArgb(&HB3, &HDE, &H69), Color.FromArgb(&HFC, &HCD, &HE5), Color.FromArgb(&HD9, &HD9, &HD9), Color.FromArgb(&HBC, &H80, &HBD)}))
colorizer.ValueProvider = New ShapeAttributeValueProvider() With {.AttributeName = "MAP_COLOR"}
Return colorizer
End Function
Private Function CreateGDPColorizer() As ChoroplethColorizer
Dim colorizer As New ChoroplethColorizer()
Dim legend As New ColorScaleLegend()
legend.Header = "GDP by Countries"
legend.Description = "In US dollars"
legend.RangeStopsFormat = "0,B"
colorizer.Legend = legend
colorizer.RangeStops.AddRange(New List(Of Double) (New Double() {0, 3000, 10000, 18000, 28000, 44000, 82000, 185000, 1000000, 2500000, 15000000}))
colorizer.Colors.AddRange(New List(Of Color) (New Color() {Color.FromArgb(&H5F, &H8B, &H95), Color.FromArgb(&H79, &H96, &H89), Color.FromArgb(&HA2, &HA8, &H75), Color.FromArgb(&HCE, &HBB, &H5F), Color.FromArgb(&HF2, &HCB, &H4E), Color.FromArgb(&HF1, &HC1, &H49), Color.FromArgb(&HE5, &HA8, &H4D), Color.FromArgb(&HD6, &H86, &H4E), Color.FromArgb(&HC5, &H64, &H50), Color.FromArgb(&HBA, &H4D, &H51)}))
colorizer.ValueProvider = New ShapeAttributeValueProvider() With {.AttributeName = "GDP_MD_EST"}
Return colorizer
End Function
Private Function CreatePopulationColorizer() As ChoroplethColorizer
Dim colorizer As New ChoroplethColorizer()
Dim legend As New ColorListLegend()
legend.RangeStopsFormat = "0,,M"
legend.Header = ""
legend.Description = ""
colorizer.Legend = legend
colorizer.RangeStops.AddRange(New List(Of Double) (New Double() {0, 1000000, 2000000, 5000000, 10000000, 25000000, 50000000, 100000000, 1000000000, 1500000000}))
colorizer.Colors.AddRange(New List(Of Color) (New Color() {Color.FromArgb(&HFA, &HDC, &HF5), Color.FromArgb(&HBF, &H84, &HB6)}))
colorizer.ValueProvider = New ShapeAttributeValueProvider() With {.AttributeName = "POP_EST"}
Return colorizer
End Function
Private Sub UpdateMapColorizer(ByVal colorizer As MapColorizer, ByVal toolTipPattern As String)
mapControl1.Colorizer = colorizer
FileLayer.ToolTipPattern = toolTipPattern
UpdateLegendAligment()
End Sub
Private Sub rgMode_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles rgMode.SelectedIndexChanged
Select Case rgMode.SelectedIndex
Case 0
UpdateMapColorizer(politicalColorizer, PoliticalToolTipPattern)
Case 1
UpdateMapColorizer(gdpColorizer, GdpToolTipPattern)
Case 2
UpdateMapColorizer(populationColorizer, PopulationToolTipPattern)
End Select
Dim showLegendOptions As Boolean = mapControl1.Colorizer IsNot politicalColorizer
lblLegendAlign.Visible = showLegendOptions
cbLegendAlign.Visible = showLegendOptions
End Sub
Private Sub cbLegendAlign_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cbLegendAlign.SelectedIndexChanged
Me.legendAlignment = GetLegendAlignment(TryCast(cbLegendAlign.EditValue, String))
UpdateLegendAligment()
End Sub
Private Function GetLegendAlignment(ByVal value As String) As LegendAlignment
If String.IsNullOrEmpty(value) Then
Return LegendAlignment.TopRight
End If
Return CType(System.Enum.Parse(GetType(LegendAlignment), value), LegendAlignment)
End Function
Private Sub UpdateLegendAligment()
Dim choroplethColorizer As ChoroplethColorizer = TryCast(mapControl1.Colorizer, ChoroplethColorizer)
If choroplethColorizer IsNot Nothing AndAlso choroplethColorizer.Legend IsNot Nothing Then
choroplethColorizer.Legend.Alignment = legendAlignment
End If
End Sub
End Class
End Namespace