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

TestProject.zip
다운로드

▶ MapData.cs

using System;

using DevExpress.XtraMap;

namespace TestProject
{
    /// <summary>
    /// 맵 데이터
    /// </summary>
    public class MapData
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 파일 경로 - FilePath

        /// <summary>
        /// 파일 경로
        /// </summary>
        public string FilePath { get; set; }

        #endregion
        #region 소스 좌표계 - SourceCoordinateSystem

        /// <summary>
        /// 소스 좌표계
        /// </summary>
        public SourceCoordinateSystem SourceCoordinateSystem { get; set; }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 문자열 구하기 - ToString()

        /// <summary>
        /// 문자열 구하기
        /// </summary>
        /// <returns>문자열</returns>
        public override string ToString()
        {
            return String.Format("{0}; with {1}", FilePath, SourceCoordinateSystem.CoordinateConverter);
        }

        #endregion
    }
}

 

728x90

 

▶ MainForm.cs

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;

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";

        /// <summary>
        /// 도형 파일 데이터 어댑터
        /// </summary>
        private ShapefileDataAdapter shapefileDataAdapter = new ShapefileDataAdapter();

        /// <summary>
        /// 맵 데이터 리스트
        /// </summary>
        private List<MapData> mapDataList = new List<MapData>
        {
            new MapData()
            {
                FilePath               = "DATA/Albers/switzerland.shp", 
                SourceCoordinateSystem = new CartesianSourceCoordinateSystem()
                {
                    CoordinateConverter = new AlbersEqualAreaConticCartesianToGeoConverter()
                    {
                        StandardParallelN = 60,
                        StandardParallelS = 20,
                        Ellipsoid         = Ellipsoid.GRS80,
                        ProjectionCenter  = new GeoPoint(40, -96)
                    }
                }
            },
            new MapData()
            {
                FilePath               = "DATA/Lambert/Belize.shp", 
                SourceCoordinateSystem = new CartesianSourceCoordinateSystem()
                {
                    CoordinateConverter = new LambertConformalConicCartesianToGeoConverter()
                    {
                        StandardParallelN = 60,
                        StandardParallelS = 20,
                        Ellipsoid         = Ellipsoid.GRS80,
                        ProjectionCenter  = new GeoPoint(40, -96)
                    }
                }
            },
            new MapData()
            {
                FilePath               = "DATA/TransverseMercator/israel.shp",
                SourceCoordinateSystem = new CartesianSourceCoordinateSystem()
                {
                    CoordinateConverter = new TransverseMercatorCartesianToGeoConverter()
                    {
                        Ellipsoid        = Ellipsoid.WGS84,
                        ProjectionCenter = new GeoPoint(0, 33),
                        ScaleFactor      = 0.9996,
                        FalseNorthing    = 0,
                        FalseEasting     = 500000
                    }
                }
            },
            new MapData()
            {
                FilePath               = "DATA/TransverseMercator/israel.shp",
                SourceCoordinateSystem = new CartesianSourceCoordinateSystem()
                {
                    CoordinateConverter = new UTMCartesianToGeoConverter()
                    {
                        UtmZone    = 36,
                        Hemisphere = Hemisphere.Northern
                    }
                }
            },
            new MapData()
            {
                FilePath               = "DATA/MercatorAux/montenegro.shp", 
                SourceCoordinateSystem = new CartesianSourceCoordinateSystem()
                {
                    CoordinateConverter = new MercatorAuxiliarySphereCartesianToGeoConverter()
                    {
                        SphereType       = 0,
                        ProjectionCenter = new GeoPoint(0,0)
                    }
                }
            }
        };

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            Load                                      += Form_Load;
            this.mapDataComboBox.SelectedIndexChanged += mapDataComboBox_SelectedIndexChanged;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 폼 로드시 처리하기 - Form_Load(sender, e)

        /// <summary>
        /// 폼 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_Load(object sender, EventArgs e)
        {
            this.mapDataComboBox.DataSource = this.mapDataList;

            this.bingMapDataProvider.BingKey = this.bingKey;

            VectorItemsLayer vectorItemsLayer = new VectorItemsLayer();
            
            vectorItemsLayer.ItemStyle.Fill = Color.FromArgb(40, 255, 128, 0);
            vectorItemsLayer.Data           = this.shapefileDataAdapter;

            vectorItemsLayer.DataLoaded += vectorItemsLayer_DataLoaded;

            this.mapControl.Layers.Add(vectorItemsLayer);
        }

        #endregion
        #region 맵 데이터 콤보 박스 선택 인덱스 변경시 처리하기 - mapDataComboBox_SelectedIndexChanged(sender, e)

        /// <summary>
        /// 맵 데이터 콤보 박스 선택 인덱스 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void mapDataComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            MapData mapData = this.mapDataComboBox.SelectedValue as MapData;

            if(mapData == null)
            {
                return;
            }

            Uri baseURI = new Uri(Assembly.GetEntryAssembly().Location);

            Uri fileURI = new Uri(baseURI, mapData.FilePath);

            this.shapefileDataAdapter.FileUri                = fileURI;
            this.shapefileDataAdapter.SourceCoordinateSystem = mapData.SourceCoordinateSystem;
        }

        #endregion
        #region 벡터 항목 레이어 데이터 로드시 처리하기 - vectorItemsLayer_DataLoaded(sender, e)

        /// <summary>
        /// 벡터 항목 레이어 데이터 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void vectorItemsLayer_DataLoaded(object sender, DataLoadedEventArgs e)
        {
            this.mapControl.ZoomToFitLayerItems(0.4);
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요