■ InformationDataProviderBase 클래스를 사용해 커스텀 지오코드 공급자를 구현하는 방법을 보여준다.
▶ Address.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 |
using DevExpress.XtraMap; namespace TestProject { /// <summary> /// 주소 /// </summary> public class Address : AddressBase { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - Address(address) /// <summary> /// 생성자 /// </summary> /// <param name="address">주소</param> public Address(string address) { FormattedAddress = address; } #endregion } } |
▶ GeocodeData.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 |
using System; using DevExpress.XtraMap; namespace TestProject { /// <summary> /// 지오코드 데이터 /// </summary> public class GeocodeData : IInformationData { //////////////////////////////////////////////////////////////////////////////////////////////////// Event ////////////////////////////////////////////////////////////////////////////////////////// Public #region 데이터 응답시 이벤트 - OnDataResponse /// <summary> /// 데이터 응답시 이벤트 /// </summary> public event EventHandler<RequestCompletedEventArgs> OnDataResponse; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 위치 정보 /// </summary> private LocationInformation locationInformation = new LocationInformation(); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 위치 정보 - LocationInformation /// <summary> /// 위치 정보 /// </summary> public LocationInformation LocationInformation { get { return this.locationInformation; } set { this.locationInformation = value; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 주소 계산하기 - CalculateAddress(geoPoint) /// <summary> /// 주소 계산하기 /// </summary> /// <param name="geoPoint">지리 포인트</param> public void CalculateAddress(GeoPoint geoPoint) { string addressString = "Address from your service here " + Environment.NewLine + "Coordinates: " + geoPoint.ToString(); LocationInformation locationInformation = new LocationInformation(); locationInformation.Address = new Address(addressString); locationInformation.Location = new GeoPoint(geoPoint.Latitude, geoPoint.Longitude); LocationInformation = locationInformation; FireOnDataResponseEvent(); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 데이터 수신시 이벤트 발생시키기 - FireOnDataResponseEvent() /// <summary> /// 데이터 수신시 이벤트 발생시키기 /// </summary> protected void FireOnDataResponseEvent() { OnDataResponse?.Invoke(this, CreateEventArgs()); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region 이벤트 인자 생성하기 - CreateEventArgs() /// <summary> /// 이벤트 인자 생성하기 /// </summary> /// <returns>요청 완료시 이벤트 인자</returns> private RequestCompletedEventArgs CreateEventArgs() { MapItem item = new MapCallout() { Location = this.locationInformation.Location, Text = this.locationInformation.Address.FormattedAddress }; return new RequestCompletedEventArgs ( new MapItem[] { item }, null, false, null ); } #endregion } } |
▶ GeocodeDataProvider.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 |
using DevExpress.XtraMap; namespace TestProject { /// <summary> /// 지오코드 데이터 공급자 /// </summary> public class GeocodeDataProvider : InformationDataProviderBase, IMouseClickRequestSender { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 데이터 - Data /// <summary> /// 데이터 /// </summary> protected new GeocodeData Data { get { return (GeocodeData)base.Data; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - GeocodeDataProvider() /// <summary> /// 생성자 /// </summary> public GeocodeDataProvider() { ProcessMouseEvents = true; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 포인트 요청하기 - RequestByPoint(geoPoint, screenPoint) /// <summary> /// 포인트 요청하기 /// </summary> /// <param name="geoPoint">지리 포인트</param> /// <param name="screenPoint">화면 포인트</param> public void RequestByPoint(GeoPoint geoPoint, MapPoint screenPoint) { Data.CalculateAddress(geoPoint); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 데이터 생성하기 - CreateData() /// <summary> /// 데이터 생성하기 /// </summary> /// <returns>정보 데이터 인터페이스</returns> protected override IInformationData CreateData() { return new GeocodeData(); } #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 |
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.informationLayer.DataProvider = new GeocodeDataProvider(); this.openStreetMapDataProvider.WebRequest += openStreetMapDataProvider_WebRequest; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region OPEN STREET MAP 데이터 공급자 웹 요청시 처리하기 - openStreetMapDataProvider_WebRequest(sender, e) /// <summary> /// OPEN STREET MAP 데이터 공급자 웹 요청시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void openStreetMapDataProvider_WebRequest(object sender, MapWebRequestEventArgs e) { e.UserAgent = "XtraMap Getting Started - Connect to OpenStreetMap"; } #endregion } } |