■ ChoroplethColorizer 클래스를 사용해 수동으로 추가된 도형을 색상 표시하는 방법을 보여준다.
▶ 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 |
using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using DevExpress.Utils; using DevExpress.XtraEditors; using DevExpress.XtraMap; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); #region 툴팁 컨트롤러를 설정한다. ToolTipController toolTipController = new ToolTipController(); toolTipController.AllowHtmlText = true; #endregion #region 맵 컨트롤을 설정한다. MapControl mapControl = new MapControl(); mapControl.Parent = this; mapControl.Dock = DockStyle.Fill; mapControl.ToolTipController = toolTipController; #endregion #region 맵 항목 저장소를 설정한다. MapItemStorage mapItemStorage = new MapItemStorage(); mapItemStorage.Items.Add ( GetMapPolygon ( 800, "Small triangle", new GeoPoint[] { new GeoPoint(0 , 0 ), new GeoPoint(0 , 40), new GeoPoint(40, 0 ), new GeoPoint(0 , 0 ) } ) ); mapItemStorage.Items.Add ( GetMapPolygon ( 1800, "Large triangle", new GeoPoint[] { new GeoPoint( 0 , 0 ), new GeoPoint( 0 , -60), new GeoPoint(-60, 0 ), new GeoPoint( 0 , 0 ) } ) ); #endregion #region 도형 어트리뷰트 값 공급자를 설정한다. ShapeAttributeValueProvider shapeAttributeValueProvider = new ShapeAttributeValueProvider(); shapeAttributeValueProvider.AttributeName = "AreaValue"; #endregion #region CHOROPLETH 색상화기를 설정한다. ChoroplethColorizer choroplethColorizer = new ChoroplethColorizer(); choroplethColorizer.ValueProvider = shapeAttributeValueProvider; choroplethColorizer.RangeStops.AddRange ( new List<double> { 0, 1000, 2000 } ); choroplethColorizer.ColorItems.AddRange ( new List<ColorizerColorItem> { new ColorizerColorItem(Color.Yellow), new ColorizerColorItem(Color.Red ) } ); #endregion #region 벡터 항목 레이어를 설정한다. VectorItemsLayer vectorItemsLayer = new VectorItemsLayer(); vectorItemsLayer.Data = mapItemStorage; vectorItemsLayer.Colorizer = choroplethColorizer; mapControl.Layers.Add(vectorItemsLayer); #endregion #region 색상 스케일 레전드를 설정한다. ColorScaleLegend colorScaleLegend = new ColorScaleLegend(); colorScaleLegend.Header = "Area"; colorScaleLegend.Layer = vectorItemsLayer; mapControl.Legends.Add(colorScaleLegend); #endregion } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 맵 다각형 구하기 - GetMapPolygon(areaValue, polygonName, pointArray) /// <summary> /// 맵 다각형 구하기 /// </summary> /// <param name="areaValue">영역 값</param> /// <param name="polygonName">다각형 명칭</param> /// <param name="pointArray">포인트 배열</param> /// <returns>맵 다각형</returns> private MapPolygon GetMapPolygon(double areaValue, string polygonName, GeoPoint[] pointArray) { MapPolygon mapPolygon = new MapPolygon(); mapPolygon.Attributes.Add ( new MapItemAttribute() { Name = "AreaValue", Type = typeof(double), Value = areaValue } ); mapPolygon.Attributes.Add ( new MapItemAttribute() { Name = "PolygonName", Type = typeof(string), Value = polygonName } ); mapPolygon.ToolTipPattern = "{PolygonName}=<b>{AreaValue}</b>"; foreach(GeoPoint point in pointArray) { mapPolygon.Points.Add(point); } return mapPolygon; } #endregion } } |