This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
/
Form1.cs
115 lines (92 loc) · 3.66 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
using DevExpress.Utils;
using DevExpress.XtraMap;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace Manual_Colorization {
public partial class Form1 : Form {
const string areaValueAttrName = "AreaValue";
const string polygonNameAttrName = "PolygonName";
public Form1() {
InitializeComponent();
InitializeMap();
}
void InitializeMap() {
// Create a map control and add it to the form.
MapControl map = new MapControl() { Dock = DockStyle.Fill };
this.Controls.Add(map);
// Create a layer to display vector data.
VectorItemsLayer itemsLayer = new VectorItemsLayer();
map.Layers.Add(itemsLayer);
// Generate a data storage for the layer.
itemsLayer.Data = CreateData();
// Create a colorizer for the layer.
itemsLayer.Colorizer = CreateColorizer();
// Create a legend for the layer.
map.Legends.Add(CreateLegend(itemsLayer));
// Specify tooltips for the map.
map.ToolTipController = new ToolTipController() { AllowHtmlText = true };
}
private MapItemStorage CreateData() {
MapItemStorage storage = new MapItemStorage();
// Create the first triangle.
storage.Items.Add(
CreatePolygon(800, "Small triangle",
new GeoPoint[] {
new GeoPoint(0, 0), new GeoPoint(0, 40),
new GeoPoint(40, 0), new GeoPoint(0, 0)
}
)
);
// Create the second triangle.
storage.Items.Add(
CreatePolygon(1800, "Large triangle",
new GeoPoint[] {
new GeoPoint(0, 0), new GeoPoint(0, -60),
new GeoPoint(-60, 0), new GeoPoint(0, 0)
}
)
);
return storage;
}
#region #CreatePolygon
private MapPolygon CreatePolygon(double areaValue, string polygonName, GeoPoint[] points) {
MapPolygon item = new MapPolygon();
item.Attributes.Add(new MapItemAttribute() {
Name = areaValueAttrName,
Type = typeof(double),
Value = areaValue
});
item.Attributes.Add(new MapItemAttribute() {
Name = polygonNameAttrName,
Type = typeof(string),
Value = polygonName
});
item.ToolTipPattern = "{" + polygonNameAttrName + "}=<b>{" + areaValueAttrName + "}</b>";
foreach (GeoPoint point in points) {
item.Points.Add(point);
}
return item;
}
#endregion #CreatePolygon
private MapColorizer CreateColorizer() {
ChoroplethColorizer colorizer = new ChoroplethColorizer();
colorizer.ValueProvider = new ShapeAttributeValueProvider {
AttributeName = areaValueAttrName
};
colorizer.RangeStops.AddRange(new List<double> { 0, 1000, 2000 });
colorizer.ColorItems.AddRange(new List<ColorizerColorItem> {
new ColorizerColorItem(Color.Yellow),
new ColorizerColorItem(Color.Red)
});
return colorizer;
}
private MapLegendBase CreateLegend(MapItemsLayerBase layer) {
ColorScaleLegend legend = new ColorScaleLegend();
legend.Header = "Area";
legend.Layer = layer;
return legend;
}
}
}