■ MapEditor 클래스의 ShowEditorPanel 속성을 사용해 맵 에디터 패널을 표시하는 방법을 보여준다.
▶ 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 |
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 이미지 컬렉션을 설정한다. 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 맵 컨트롤을 설정한다. MapControl mapControl = new MapControl(); mapControl.Parent = this; mapControl.Dock = DockStyle.Fill; mapControl.ImageList = imageCollection; mapControl.CenterPoint = new GeoPoint(-37.2, 143.2); mapControl.ZoomLevel = 5; mapControl.MapEditor.ShowEditorPanel = true; #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.ItemImageIndex = 0; mapControl.Layers.Add(vectorItemsLayer); #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 } } |