-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
135 lines (117 loc) · 4.69 KB
/
Form1.cs
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
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraMap;
namespace MiniMapLayers {
public partial class Form1 : Form {
const string dataFilepath = "../../Data/Ships.xml";
const string imageFilepath = "../../Images/Ship.png";
const string bingKey = "Your Bing Key Here";
public Form1() {
InitializeComponent();
}
object LoadData(string path) {
DataSet ds = new DataSet();
ds.ReadXml(path);
DataTable table = ds.Tables[0];
return table;
}
private void Form1_Load(object sender, System.EventArgs e) {
#region #AssignToolTipController
object data = LoadData(dataFilepath);
mapControl.ToolTipController = new ToolTipController() {
AllowHtmlText = true
};
#endregion #AssignToolTipController
#region #AssignImageList
mapControl.ImageList = CreateImageList();
#endregion #AssignImageList
#region #AddLayer
mapControl.Layers.Add(CreateVectorLayer(data));
#endregion #AddLayer
#region #AssignMiniMap
mapControl.MiniMap = CreateMiniMap(data);
#endregion #AssignMiniMap
#region #AddLegend
mapControl.Legends.Add(CreateLegend());
#endregion #AddLegend
}
#region #ImageCollection
object CreateImageList() {
ImageCollection collection = new ImageCollection() {
ImageSize = new Size(40, 40)
};
collection.Images.Add(new Bitmap(imageFilepath));
return collection;
}
#endregion #ImageCollection
#region #ColorListLegend
MapLegendBase CreateLegend() {
ColorListLegend legend = new ColorListLegend() {
ImageList = mapControl.ImageList,
Alignment = LegendAlignment.TopRight
};
legend.CustomItems.Add(new ColorLegendItem() {
ImageIndex = 0,
Text = "Shipwreck Location"
});
return legend;
}
#endregion #ColorListLegend
#region #MiniMap
MiniMap CreateMiniMap(object data) {
MiniMap miniMap = new MiniMap() {
Height = 200,
Width = 300,
Behavior = new FixedMiniMapBehavior() {
CenterPoint = new GeoPoint(-35, 140),
ZoomLevel = 3
}
};
MiniMapImageTilesLayer mapLayer = new MiniMapImageTilesLayer() {
DataProvider = new BingMapDataProvider() {
BingKey = bingKey,
Kind = BingMapKind.Area
}
};
MiniMapVectorItemsLayer vectorLayer = new MiniMapVectorItemsLayer();
ListSourceDataAdapter adapter = new ListSourceDataAdapter();
adapter.DataSource = data;
adapter.Mappings.Latitude = "Latitude";
adapter.Mappings.Longitude = "Longitude";
adapter.DefaultMapItemType = MapItemType.Dot;
adapter.PropertyMappings.Add(
new MapDotSizeMapping() { DefaultValue = 10 }
);
vectorLayer.Data = adapter;
vectorLayer.ItemStyle.Fill = Color.FromArgb(74, 212, 255);
vectorLayer.ItemStyle.Stroke = Color.Gray;
miniMap.Layers.Add(mapLayer);
miniMap.Layers.Add(vectorLayer);
return miniMap;
}
#endregion #MiniMap
#region #VectorItemsLayer
LayerBase CreateVectorLayer(object data) {
ListSourceDataAdapter adapter = new ListSourceDataAdapter() {
DataSource = data,
DefaultMapItemType = MapItemType.Custom
};
adapter.Mappings.Latitude = "Latitude";
adapter.Mappings.Longitude = "Longitude";
adapter.AttributeMappings.Add(new MapItemAttributeMapping() {Name = "Name", Member = "Name"});
adapter.AttributeMappings.Add(new MapItemAttributeMapping() {Name = "Year", Member = "Year"});
adapter.AttributeMappings.Add(new MapItemAttributeMapping() {Name = "Description", Member = "Description"});
VectorItemsLayer layer = new VectorItemsLayer() {
Data = adapter,
ItemImageIndex = 0,
EnableSelection = false,
EnableHighlighting = false,
ToolTipPattern = "<b>{Name} ({Year})</b>\n{Description}"
};
return layer;
}
#endregion #VectorItemsLayer
}
}