첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainForm.cs

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
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요