/
Form1.cs
61 lines (54 loc) · 2.16 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
using DevExpress.XtraMap;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
using System.Xml.Linq;
namespace ClustererSample {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
#region #Clusterer
VectorItemsLayer VectorLayer { get { return (VectorItemsLayer)map.Layers["VectorLayer"]; } }
ListSourceDataAdapter DataAdapter { get { return (ListSourceDataAdapter)VectorLayer.Data; } }
private void Form1_Load(object sender, EventArgs e) {
DataAdapter.DataSource = LoadData();
DistanceBasedClusterer clusterer = new DistanceBasedClusterer {
GroupProvider = new AttributeGroupProvider {
AttributeName = "LocationName"
}
};
clusterer.SetClusterItemFactory(new CustomClusterItemFactory());
DataAdapter.Clusterer = clusterer;
}
#endregion #Clusterer
List<Tree> LoadData() {
List<Tree> trees = new List<Tree>();
XDocument doc = XDocument.Load("Data\\TreesCl.xml");
foreach(XElement xTree in doc.Element("RowSet").Elements("Row")) {
trees.Add(new Tree {
Latitude = Convert.ToDouble(xTree.Element("lat").Value, CultureInfo.InvariantCulture),
Longitude = Convert.ToDouble(xTree.Element("lon").Value,CultureInfo.InvariantCulture),
LocationName = xTree.Element("location").Value.ToString(CultureInfo.InvariantCulture)
});
}
return trees;
}
}
#region #Factory
class CustomClusterItemFactory : IClusterItemFactory {
public MapItem CreateClusterItem(IList<MapItem> objects) {
MapDot dot = new MapDot();
dot.ClusteredItems = objects;
dot.TitleOptions.Pattern = objects.Count.ToString();
return dot;
}
}
#endregion #Factory
class Tree {
public double Latitude { get; set; }
public double Longitude { get; set; }
public string LocationName { get; set; }
}
}