■ IClusterItemFactory 인터페이스를 사용해 벡터 항목을 집계하는 방법을 보여준다.
▶ Tree.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 |
namespace TestProject { /// <summary> /// 트리 /// </summary> public class Tree { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 위도 - Latitude /// <summary> /// 위도 /// </summary> public double Latitude { get; set; } #endregion #region 경도 - Longitude /// <summary> /// 경도 /// </summary> public double Longitude { get; set; } #endregion #region 위치명 - LocationName /// <summary> /// 위치명 /// </summary> public string LocationName { get; set; } #endregion } } |
▶ CustomClusterItemFactory.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 |
using System.Collections.Generic; using DevExpress.XtraMap; namespace TestProject { /// <summary> /// 커스텀 클러스터 항목 팩토리 /// </summary> public class CustomClusterItemFactory : IClusterItemFactory { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 클러스터 항목 생성하기 - CreateClusterItem(mapItemList) /// <summary> /// 클러스터 항목 생성하기 /// </summary> /// <param name="mapItemList">맵 항목 리스트</param> /// <returns>클러스터 항목</returns> public MapItem CreateClusterItem(IList<MapItem> mapItemList) { MapDot mapDot = new MapDot(); mapDot.ClusteredItems = mapItemList; mapDot.TitleOptions.Pattern = mapItemList.Count.ToString(); return mapDot; } #endregion } } |
▶ MainForm.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 System; using System.Collections.Generic; using System.Globalization; using System.Xml.Linq; using DevExpress.XtraEditors; using DevExpress.XtraMap; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 빙 맵 키 /// </summary> private string bingKey = "INPUT YOUR BING KEY"; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); Load += Form_Load; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 폼 로드시 처리하기 - Form_Load(sender, e) /// <summary> /// 폼 로드시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Form_Load(object sender, EventArgs e) { #region 빙 맵 데이터 공급자를 설정한다. this.bingMapDataProvider.BingKey = this.bingKey; #endregion #region 어트리뷰트 그룹 공급자를 설정한다. AttributeGroupProvider attributeGroupProvider = new AttributeGroupProvider(); attributeGroupProvider.AttributeName = "LocationName"; #endregion #region 거리 기반 클러스터러를 설정한다. DistanceBasedClusterer distanceBasedClusterer = new DistanceBasedClusterer(); distanceBasedClusterer.GroupProvider = attributeGroupProvider; #endregion #region 커스텀 클러스터 항목 팩토리를 설정한다. CustomClusterItemFactory customClusterItemFactory = new CustomClusterItemFactory(); distanceBasedClusterer.SetClusterItemFactory(customClusterItemFactory); #endregion #region 트리 리스트를 설정한다. List<Tree> treeList = new List<Tree>(); XDocument document = XDocument.Load("DATA\\TreesCl.xml"); foreach(XElement element in document.Element("RowSet").Elements("Row")) { treeList.Add ( new Tree { Latitude = Convert.ToDouble(element.Element("lat" ).Value, CultureInfo.InvariantCulture), Longitude = Convert.ToDouble(element.Element("lon" ).Value, CultureInfo.InvariantCulture), LocationName = element.Element("location").Value.ToString(CultureInfo.InvariantCulture) } ); } #endregion #region 리스트 소스 데이터 어댑터를 설정한다. this.listSourceDataAdapter.DataSource = treeList; this.listSourceDataAdapter.Clusterer = distanceBasedClusterer; #endregion } #endregion } } |