■ ListSourceDataAdapter 클래스를 사용해 데이터 소스에서 벡터 항목을 자동으로 생성하는 방법을 보여준다.
▶ 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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Globalization; using System.Linq; using System.Windows.Forms; using System.Xml.Linq; using DevExpress.Utils; 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(); #region 툴팁 컨트롤러를 설정한다. ToolTipController toolTipController = new ToolTipController(); toolTipController.AllowHtmlText = true; #endregion #region 이미지 컬렉션을 설정한다. ImageCollection imageCollection = new ImageCollection(); imageCollection.ImageSize = new Size(20, 20); Bitmap bitmap = new Bitmap("IMAGE\\ship_small.png"); imageCollection.Images.Add(bitmap); #endregion #region 난파선 항목 리스트를 설정한다. List<ShipwreckItem> shipwreckItemList = GetShipwreckItemList("DATA\\ships.xml"); #endregion #region 미니 맵을 설정한다. MiniMap miniMap = new MiniMap(); miniMap.Alignment = MiniMapAlignment.BottomLeft; #endregion #region 미니 맵 빙 맵 데이터 공급자를 설정한다. BingMapDataProvider miniMapBingMapDataProvider = new BingMapDataProvider(); miniMapBingMapDataProvider.BingKey = this.bingKey; #endregion #region 미니 맵 이미지 타일 레이어를 설정한다. MiniMapImageTilesLayer miniMapImageTilesLayer = new MiniMapImageTilesLayer(); miniMapImageTilesLayer.DataProvider = miniMapBingMapDataProvider; miniMap.Layers.Add(miniMapImageTilesLayer); #endregion #region 미니 맵 리스트 소스 데이터 어댑터를 설정한다. ListSourceDataAdapter miniMapListSourceDataAdapter = new ListSourceDataAdapter(); miniMapListSourceDataAdapter.DefaultMapItemType = MapItemType.Dot; miniMapListSourceDataAdapter.Mappings.Latitude = "Latitude"; miniMapListSourceDataAdapter.Mappings.Longitude = "Longitude"; miniMapListSourceDataAdapter.DataSource = shipwreckItemList; miniMapListSourceDataAdapter.PropertyMappings.Add(new MapItemFillMapping() { DefaultValue = Color.Red }); miniMapListSourceDataAdapter.PropertyMappings.Add(new MapItemStrokeMapping() { DefaultValue = Color.White }); miniMapListSourceDataAdapter.PropertyMappings.Add(new MapItemStrokeWidthMapping() { DefaultValue = 2 }); miniMapListSourceDataAdapter.PropertyMappings.Add(new MapDotSizeMapping() { DefaultValue = 8 }); #endregion #region 미니 맵 벡터 항목 레이어를 설정한다. MiniMapVectorItemsLayer miniMapVectorItemsLayer = new MiniMapVectorItemsLayer(); miniMapVectorItemsLayer.Data = miniMapListSourceDataAdapter; miniMap.Layers.Add(miniMapVectorItemsLayer); #endregion #region 맵 컨트롤을 설정한다. MapControl mapControl = new MapControl(); mapControl.Parent = this; mapControl.Dock = DockStyle.Fill; mapControl.ImageList = imageCollection; mapControl.ToolTipController = toolTipController; mapControl.CenterPoint = new GeoPoint(-37.2, 143.2); mapControl.ZoomLevel = 5; mapControl.MiniMap = miniMap; #endregion #region 빙 맵 데이터 공급자를 설정한다. BingMapDataProvider bingMapDataProvider = new BingMapDataProvider(); bingMapDataProvider.BingKey = this.bingKey; #endregion #region 이미지 레이어를 설정한다. ImageLayer imageLayer = new ImageLayer(); imageLayer.DataProvider = bingMapDataProvider; mapControl.Layers.Add(imageLayer); #endregion #region 리스트 소스 데이터 어댑터를 설정한다. ListSourceDataAdapter listSourceDataAdapter = new ListSourceDataAdapter(); listSourceDataAdapter.DataSource = shipwreckItemList; listSourceDataAdapter.Mappings.Latitude = "Latitude"; listSourceDataAdapter.Mappings.Longitude = "Longitude"; listSourceDataAdapter.AttributeMappings.Add(new MapItemAttributeMapping() { Member = "Name" , Name = "Name" }); listSourceDataAdapter.AttributeMappings.Add(new MapItemAttributeMapping() { Member = "Year" , Name = "Year" }); listSourceDataAdapter.AttributeMappings.Add(new MapItemAttributeMapping() { Member = "Description", Name = "Description" }); #endregion #region 벡터 항목 레이어를 설정한다. VectorItemsLayer vectorItemsLayer = new VectorItemsLayer(); vectorItemsLayer.Data = listSourceDataAdapter; vectorItemsLayer.ToolTipPattern = "<b>{Name} ({Year})</b> \r\n{Description}"; vectorItemsLayer.ItemImageIndex = 0; mapControl.Layers.Add(vectorItemsLayer); #endregion #region 색상 리스트 레전드를 설정한다. ColorListLegend colorListLegend = new ColorListLegend(); colorListLegend.ImageList = mapControl.ImageList; colorListLegend.CustomItems.Add ( new ColorLegendItem() { ImageIndex = 0, Text = "Shipwreck" } ); mapControl.Legends.Add(colorListLegend); #endregion } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 난파선 항목 리스트 구하기 - GetShipwreckItemList(filePath) /// <summary> /// 난파선 항목 리스트 구하기 /// </summary> /// <param name="filePath">파일 경로</param> /// <returns>난파선 항목 리스트</returns> private List<ShipwreckItem> GetShipwreckItemList(string filePath) { return XDocument.Load(filePath) .Element("Ships") .Elements("Ship") .Select ( e => new ShipwreckItem ( year : Convert.ToInt32 (e.Element("Year" ).Value, CultureInfo.InvariantCulture), name : e.Element("Name" ).Value, description : e.Element("Description").Value, latitude : Convert.ToDouble(e.Element("Latitude" ).Value, CultureInfo.InvariantCulture), longitude : Convert.ToDouble(e.Element("Longitude" ).Value, CultureInfo.InvariantCulture) ) ) .ToList(); } #endregion } } |