■ ISearchPanelRequestSender 클래스를 사용해 커스텀 검색 공급자를 구현하는 방법을 보여준다.
▶ 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 } } |
▶ CustomInformationData.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 |
using System; using System.Collections.Generic; using DevExpress.XtraMap; namespace TestProject { /// <summary> /// 커스텀 정보 데이터 /// </summary> public class CustomInformationData : IInformationData { //////////////////////////////////////////////////////////////////////////////////////////////////// Event ////////////////////////////////////////////////////////////////////////////////////////// Public #region 데이터 응답시 이벤트 - OnDataResponse /// <summary> /// 데이터 응답시 이벤트 /// </summary> public event EventHandler<RequestCompletedEventArgs> OnDataResponse; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 위치 정보 리스트 /// </summary> private readonly List<LocationInformation> locationInformationList = new List<LocationInformation>(); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 위치 정보 열거 가능 목록 - LocationInformationList /// <summary> /// 위치 정보 열거 가능 목록 /// </summary> public IEnumerable<LocationInformation> LocationInformationList { get { return this.locationInformationList; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method #region 검색하기 - Search(keyword) /// <summary> /// 검색하기 /// </summary> /// <param name="keyword">키워드</param> public void Search(string keyword) { Random random = new Random(DateTime.Now.Millisecond); this.locationInformationList.Clear(); int length = keyword.Length; for(int i = 0; i < length; i++) { LocationInformation locationInformation = new LocationInformation(); locationInformation.Address = new Address(keyword + " " + i.ToString()); locationInformation.Location = new GeoPoint(random.Next(180) - 90, random.Next(360) - 180); locationInformationList.Add(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[] mapItemArray = new MapItem[this.locationInformationList.Count]; for(int i = 0; i < mapItemArray.Length; i++) { mapItemArray[i] = new MapCallout() { Location = this.locationInformationList[i].Location, Text = this.locationInformationList[i].Address.FormattedAddress }; } return new RequestCompletedEventArgs(mapItemArray, null, false, null); } #endregion } } |
▶ CustomInformationDataProvider.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 |
using System.Collections.Generic; using DevExpress.XtraMap; namespace TestProject { /// <summary> /// 커스텀 정보 데이터 공급자 /// </summary> public class CustomInformationDataProvider : InformationDataProviderBase, ISearchPanelRequestSender { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 위치 정보 열거 가능 목록 - Addresses /// <summary> /// 위치 정보 열거 가능 목록 /// </summary> public IEnumerable<LocationInformation> Addresses { get { return Data.LocationInformationList; } } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 데이터 - Data /// <summary> /// 데이터 /// </summary> protected new CustomInformationData Data { get { return (CustomInformationData)base.Data; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 검색하기 - SearchByString(keyword) /// <summary> /// 문자열 검색하기 /// </summary> /// <param name="keyword">키워드</param> public void SearchByString(string keyword) { Data.Search(keyword); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 데이터 생성하기 - CreateData() /// <summary> /// 데이터 생성하기 /// </summary> /// <returns>정보 데이터 인터페이스</returns> protected override IInformationData CreateData() { return new CustomInformationData(); } #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 |
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.openStreetMapDataProvider.WebRequest += openStreetMapDataProvider_WebRequest; CustomInformationDataProvider customInformationDataProvider = new CustomInformationDataProvider(); this.informationLayer.DataProvider = customInformationDataProvider; } #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 } } |