This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Form1.vb
63 lines (50 loc) · 2.77 KB
/
Form1.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
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraMap
Namespace WinForms_MapControl_KeyColorColorizer
Partial Public Class Form1
Inherits Form
Private Const filepath As String = "..\..\Data\Hotel1.shp"
Public Sub New()
InitializeComponent()
InitializeMap()
End Sub
Private Sub InitializeMap()
' Create a Map control.
Dim map As New MapControl() With {.Dock = DockStyle.Fill, .CoordinateSystem = New CartesianMapCoordinateSystem(), .CenterPoint = New CartesianPoint(-100, -50), .MaxZoomLevel = 3, .MinZoomLevel = 1}
Me.Controls.Add(map)
' #Region "#CreateLayer"
' Create a vector layer and add it to the map.
Dim hotelLayer As New VectorItemsLayer() With {.Data = CreateData(), .Colorizer = CreateColorizer()}
map.Layers.Add(hotelLayer)
' #End Region ' #CreateLayer
' #Region "#AddLegend"
' Add a legend to the map.
map.Legends.Add(New ColorListLegend() With {.Header = "Room Type", .Layer = hotelLayer})
' #End Region ' #AddLegend
End Sub
#Region "#CreateData"
' Creates a shapefile data adapter.
Private Function CreateData() As IMapDataAdapter
Dim baseUri As New Uri(System.Reflection.Assembly.GetEntryAssembly().Location)
Dim adapter As New ShapefileDataAdapter() With {.SourceCoordinateSystem = New CartesianSourceCoordinateSystem(), .FileUri = New Uri(baseUri, filepath)}
Return adapter
End Function
#End Region ' #CreateData
#Region "#CreateColorizer"
' Creates a key color colorizer.
Private Function CreateColorizer() As MapColorizer
Dim colorizer As New KeyColorColorizer() With {.ItemKeyProvider = New AttributeItemKeyProvider() With {.AttributeName = "CATEGORY"}, .PredefinedColorSchema = PredefinedColorSchema.Palette}
colorizer.Keys.Add(New ColorizerKeyItem() With {.Key = 1, .Name = "Restaurant"})
colorizer.Keys.Add(New ColorizerKeyItem() With {.Key = 2, .Name = "Business room"})
colorizer.Keys.Add(New ColorizerKeyItem() With {.Key = 3, .Name = "Bathroom"})
colorizer.Keys.Add(New ColorizerKeyItem() With {.Key = 4, .Name = "Living room"})
colorizer.Keys.Add(New ColorizerKeyItem() With {.Key = 5, .Name = "Other"})
colorizer.Keys.Add(New ColorizerKeyItem() With {.Key = 6, .Name = "Service room"})
colorizer.Keys.Add(New ColorizerKeyItem() With {.Key = 7, .Name = "Pool"})
colorizer.Keys.Add(New ColorizerKeyItem() With {.Key = 8, .Name = "Gym"})
Return colorizer
End Function
#End Region ' #CreateColorizer
End Class
End Namespace