■ MapControl 클래스의 DrawMapItem 이벤트를 사용해 벡터 항목을 커스텀 그리는 방법을 보여준다.
▶ MapItemFactory.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 |
using DevExpress.XtraMap; namespace TestProject { /// <summary> /// 맵 항목 팩토리 /// </summary> public class MapItemFactory : DefaultMapItemFactory { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 항목 초기화하기 - InitializeItem(item, source) /// <summary> /// 항목 초기화하기 /// </summary> /// <param name="item">항목</param> /// <param name="source">소스</param> protected override void InitializeItem(MapItem item, object source) { base.InitializeItem(item, source); MapRectangle rectangle = item as MapRectangle; if(rectangle != null) { rectangle.Width = 1000; rectangle.Height = 1000; } } #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 |
using System.Drawing; using DevExpress.XtraEditors; using DevExpress.XtraMap; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.mapControl.SetMapItemFactory(new MapItemFactory()); this.listSourceDataAdapter.DataSource = TestList.Instance; this.mapControl.DrawMapItem += mapControl_DrawMapItem; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 맵 컨트롤 맵 항목 그리기 - mapControl_DrawMapItem(sender, e) /// <summary> /// 맵 컨트롤 맵 항목 그리기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void mapControl_DrawMapItem(object sender, DrawMapItemEventArgs e) { Color color1 = (Color)e.Item.Attributes["Tag"].Value; Color color2 = Color.FromArgb(255 - color1.R, 255 - color1.G, 255 - color1.B); e.Fill = e.IsHighlighted ? color2 : color1; e.Stroke = e.IsHighlighted ? color1 : color2; e.StrokeWidth = e.IsHighlighted ? 5 : 2; } #endregion } } |