MapControlEx.cs 137 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214
  1. using DataSimulation.Repostory;
  2. using DevExpress.Export.Xl;
  3. using DevExpress.Map;
  4. using DevExpress.Map.Native;
  5. using DevExpress.Utils;
  6. using DevExpress.Utils.Svg;
  7. using DevExpress.XtraBars;
  8. using DevExpress.XtraEditors;
  9. using DevExpress.XtraGrid;
  10. using DevExpress.XtraGrid.Columns;
  11. using DevExpress.XtraGrid.Views.Grid;
  12. using DevExpress.XtraMap;
  13. using DevExpress.XtraMap.ItemEditor;
  14. using DevExpress.XtraPrinting;
  15. using DxHelper;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.ComponentModel.DataAnnotations;
  19. using System.Data.Common;
  20. using System.Data.SQLite;
  21. using System.Drawing;
  22. using System.Drawing.Imaging;
  23. using System.IO;
  24. using System.Linq;
  25. using System.Reflection;
  26. using System.Text;
  27. using System.Threading;
  28. using System.Threading.Tasks;
  29. using System.Windows.Forms;
  30. public enum GoogleMapType
  31. {
  32. /// <summary>
  33. /// 卫星地图
  34. /// </summary>
  35. Sat = 47626774,
  36. /// <summary>
  37. /// 地形图
  38. /// </summary>
  39. Landform = 370833361,
  40. /// <summary>
  41. /// 混合地图
  42. /// </summary>
  43. Mix = 1024577166,
  44. /// <summary>
  45. /// 普通地图
  46. /// </summary>
  47. Normal = 1818940751
  48. }
  49. /// <summary>
  50. /// MapControl扩展类,封装了常用的非业务基础功能.
  51. /// 内置了4个图层,ImageTileLayer、DrawLayer、FixedDrawLayer、PosLayer.
  52. /// 必须首先调用UseDefalutOptions函数
  53. /// </summary>
  54. public static class MapControlEx
  55. {
  56. class InnerData
  57. {
  58. internal GeoPoint _mapMenuGeoPoint;
  59. internal Dictionary<int, MapItem> _clusterCache = new Dictionary<int, MapItem>();
  60. internal Dictionary<PosData, MapItem> _dataCache = new Dictionary<PosData, MapItem>();
  61. internal BarManager barM;
  62. internal PopupMenu mapMenu;
  63. internal PopupMenu posMenu;
  64. internal PopupMenu rectMenu;
  65. internal Action<(double starLon, double startLat, double centerLon, double centerLat,
  66. double endLon, double endLat, double lonRange, double latRange)> mOnRectChanged;
  67. internal Action<(double Lon, double Lat)> onClickChanged;
  68. internal MapItemStorage mMapStorage;
  69. internal MapItemStorage mMapStorageFixed;
  70. internal MapPolyline distinctPath;
  71. /// <summary>
  72. /// 航迹线
  73. /// </summary>
  74. internal MapSpline flightpath;
  75. internal Dictionary<string, FlightInfo> _flightCache = new Dictionary<string, FlightInfo>();
  76. internal MapDot hoverPoint;
  77. internal ToolTipControllerShowEventArgs hoverTip;
  78. internal ToolTipController mapToolTip;
  79. internal MapItemStorage posStorge;
  80. internal MapRectangle rangeItem;
  81. internal MapDot dotItem = new MapDot() { Tag = "DrawRect" };
  82. internal bool drawingRect = false;
  83. internal bool mouseLeftDown = false;
  84. internal (double starLon, double startLat, double centerLon, double centerLat,
  85. double endLon, double endLat, double lonRange, double latRange)
  86. CurrentRect;
  87. internal MapDot preSelectedItem;
  88. internal Type posDataType;
  89. }
  90. private static GoogleMapType mMapType = GoogleMapType.Normal;
  91. private static List<MapControl> listMapCtrl = new List<MapControl>();
  92. private const int _dotSize = 8;
  93. private const int _selectedDotSize = 12;
  94. public static MapControl SetMapLayerType(this MapControl ctrl, string wmsUrl)
  95. {
  96. if (!string.IsNullOrWhiteSpace(wmsUrl))
  97. {
  98. var provider = new WmsDataProvider();//地图瓦片提供者
  99. provider.ServerUri = wmsUrl;
  100. provider.ActiveLayerName = "OSM-WMS";
  101. ctrl.GetImageLayer().DataProvider = provider;
  102. }
  103. else
  104. {
  105. bool localGmdbDataEnable = false;//本地Data.Gmdb是否可用,可用时读取本地瓦片,否则执行Http请求资源
  106. var files = Directory.GetFiles(Application.StartupPath, "Data.gmdb", SearchOption.AllDirectories);
  107. if (files.Length > 0)
  108. {
  109. try
  110. {
  111. string conStr = string.Format("Data Source=\"{0}\";Page Size=32768", files[0]);
  112. var con = new SQLiteConnection(conStr);
  113. con.Open();
  114. con.Close();
  115. localGmdbDataEnable = true;
  116. }
  117. catch (Exception ex)
  118. {
  119. Console.Error.WriteLine(ex.Message);
  120. }
  121. }
  122. if (localGmdbDataEnable)
  123. {
  124. var provider = new ImageTileDataProvider();//地图瓦片提供者
  125. provider.TileSource = new ImageTileSource();//地图瓦片数据源接口实现
  126. ctrl.GetImageLayer().DataProvider = provider;
  127. }
  128. else
  129. {
  130. var provider = new HttpMapDataProvider();
  131. ctrl.GetImageLayer().DataProvider = provider;
  132. }
  133. }
  134. return ctrl;
  135. }
  136. /// <summary>
  137. /// <para>设置地图通用属性并创建4个Layer.</para>
  138. /// <para>ImageLayer:绘制地图瓦片</para>
  139. /// <para>DrawLayer:地图绘制图层,右键可以擦除</para>
  140. /// <para>FixedDrawLayer:地图绘制层,右键无法擦除</para>
  141. /// <para>PosLayer:定位点绘制专用图层</para>
  142. /// </summary>
  143. /// <param name="ctrl"></param>
  144. /// <returns></returns>
  145. public static MapControl UseDefalutOptions(this MapControl ctrl)
  146. {
  147. var barM = new BarManager();
  148. barM.BeginInit();
  149. barM.Form = ctrl;
  150. var mapMeun = new PopupMenu() { Manager = barM };
  151. var posMenu = new PopupMenu() { Manager = barM };
  152. var rectMenu = new PopupMenu() { Manager = barM };
  153. barM.EndInit();
  154. listMapCtrl.Add(ctrl);
  155. var innerData = new InnerData();
  156. innerData.barM = barM;
  157. innerData.mapMenu = mapMeun;
  158. innerData.posMenu = posMenu;
  159. innerData.rectMenu = rectMenu;
  160. innerData.mapToolTip = new ToolTipController();
  161. innerData.mapToolTip.InitialDelay = 10;
  162. innerData.mapToolTip.KeepWhileHovered = true;
  163. innerData.mapToolTip.ReshowDelay = 10;
  164. innerData.mapToolTip.ShowBeak = true;
  165. innerData.mapToolTip.ToolTipAnchor = DevExpress.Utils.ToolTipAnchor.Cursor;
  166. innerData.mapToolTip.ToolTipType = ToolTipType.SuperTip;
  167. ctrl.Tag = innerData;
  168. ctrl.ToolTipController = innerData.mapToolTip;
  169. ctrl.ToolTipController.BeforeShow += (sender, e) =>
  170. {
  171. if (e.SelectedObject == null) return;
  172. SuperToolTip superToolTip = new SuperToolTip();
  173. if (e.SelectedObject.ToString() == ItemsEditorPanelAction.AddRectangle.ToString())
  174. {
  175. e.ToolTip = "绘制矩形";
  176. return;
  177. }
  178. else if (e.SelectedObject is MapDot mapDot)
  179. {
  180. if (mapDot == null) return;
  181. var posItem = mapDot.Tag as PosData;
  182. if (mapDot == null || posItem == null) return;
  183. if (posItem.ClusterCount == 1)
  184. {
  185. var props = posItem.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).ToList();
  186. var list = new List<(int Index, string Name, string Format, object Value)>();
  187. foreach (var prop in props)
  188. {
  189. var attrToolTip = prop.GetCustomAttribute<ToolTipAttribute>();
  190. if (attrToolTip == null) continue;
  191. string toolTipFormat = attrToolTip.Format;
  192. var val = prop.GetValue(posItem);
  193. string displayName = prop.Name;
  194. var attrDisplay = prop.GetCustomAttribute<DisplayAttribute>();
  195. if (attrDisplay != null && !string.IsNullOrWhiteSpace(attrDisplay.Name))
  196. displayName = attrDisplay.Name;
  197. int index = attrToolTip.Index;
  198. list.Add((index, displayName, toolTipFormat, val));
  199. }
  200. list = list.OrderBy(p => p.Index).ToList();
  201. foreach ((int Index, string Name, string Format, object val) in list)
  202. {
  203. string f = null;
  204. if (val is DateTime)
  205. {
  206. f = "yyyy-MM-dd HH:mm:ss";
  207. }
  208. else if (val is float || val is double || val is decimal)
  209. {
  210. f = "f4";
  211. }
  212. if (!string.IsNullOrWhiteSpace(Format))
  213. f = Format;
  214. string valStr;
  215. if (!string.IsNullOrWhiteSpace(f))
  216. valStr = ((dynamic)val).ToString(f);
  217. else
  218. valStr = val.ToString();
  219. ToolTipItem tipItem = new ToolTipItem();
  220. tipItem.Text = $"{Name}:{valStr}";
  221. superToolTip.Items.Add(tipItem);
  222. }
  223. }
  224. else
  225. {
  226. ToolTipItem tipItem = new ToolTipItem();
  227. tipItem.Text = $"当前位置附近有{posItem.ClusterCount}个定位点,放大可查看";
  228. superToolTip.Items.Add(tipItem);
  229. }
  230. e.SuperTip = superToolTip;
  231. }
  232. else if (e.SelectedObject is MapCustomElement ele)
  233. {
  234. var find = innerData.mMapStorageFixed.Items.Where(p => (p is MapCustomElement pp) && p != ele && pp.Location.Equals(ele.Location));
  235. StringBuilder sb = new StringBuilder();
  236. sb.Append(((object[])ele.Tag)[1]);
  237. foreach (var item in find)
  238. {
  239. sb.Append("\r\n");
  240. sb.Append("-------------------");
  241. sb.Append("\r\n");
  242. sb.Append(((object[])item.Tag)[1]);
  243. }
  244. ele.ToolTipPattern = sb.ToString();
  245. }
  246. };
  247. ctrl.MouseDown += (sender, e) =>
  248. {
  249. if (e.Button == MouseButtons.Right)
  250. {
  251. var hitInfo = ctrl.CalcHitInfo(e.Location);
  252. if (hitInfo.InMapRectangle && innerData.rangeItem != null)
  253. {
  254. rectMenu?.ShowPopup(Cursor.Position);
  255. }
  256. else if (hitInfo.InMapDot && hitInfo.MapDot.Tag is PosData)
  257. {
  258. var selectPos = (PosData)hitInfo.MapDot.Tag;
  259. if (!selectPos.Selected)
  260. {
  261. selectPos.Selected = true;
  262. ctrl.UpdatePosItem(selectPos);
  263. }
  264. if (selectPos.ClusterCount == 1)
  265. {
  266. posMenu?.ShowPopup(Cursor.Position);//选中了原始MapItem
  267. }
  268. else
  269. {
  270. //选中了聚合后的MapItem
  271. }
  272. }
  273. else
  274. {
  275. var geoPoint = ctrl.ScreenPointToCoordPoint(e.Location) as GeoPoint;
  276. innerData._mapMenuGeoPoint = geoPoint;
  277. innerData.mapMenu?.ShowPopup(Cursor.Position);
  278. }
  279. }
  280. else
  281. {
  282. innerData.mouseLeftDown = true;
  283. innerData.barM.CloseMenus();
  284. var hitInfo = ctrl.CalcHitInfo(e.Location);
  285. if (hitInfo.InMapDot && hitInfo.MapDot.Tag is PosData)
  286. {
  287. var selectPos = hitInfo.MapDot.Tag as PosData;
  288. if (!selectPos.Selected)
  289. {
  290. selectPos.Selected = true;
  291. ctrl.UpdatePosItem(selectPos);
  292. }
  293. }
  294. }
  295. };
  296. ctrl.MouseUp += (sender, e) =>
  297. {
  298. innerData.mouseLeftDown = false;
  299. };
  300. //中心点、缩放级别
  301. ctrl.MinZoomLevel = 3;
  302. ctrl.ZoomLevel = 5;
  303. ctrl.MaxZoomLevel = 14;
  304. ctrl.CenterPoint = new GeoPoint(18, 110);
  305. //禁用多余特效
  306. ctrl.EnableDelayedScrolling = true;
  307. ctrl.RenderMode = RenderMode.DirectX;
  308. ctrl.EnableAnimation = false;
  309. ctrl.EnableRotation = false;
  310. //ctrl.ShowSearchPanel = false;
  311. ctrl.SearchPanelOptions.Visible = false;
  312. ctrl.SelectionMode = ElementSelectionMode.Single;//只能单选图层上的元素
  313. ((GeoMapCoordinateSystem)ctrl.CoordinateSystem).CircularScrollingMode = CircularScrollingMode.TilesAndVectorItems;
  314. //地图下方导航栏
  315. ctrl.NavigationPanelOptions.Height = 35;
  316. ctrl.NavigationPanelOptions.BackgroundStyle.Fill = Color.Transparent;
  317. ctrl.NavigationPanelOptions.ShowScrollButtons = false;
  318. ctrl.NavigationPanelOptions.ShowZoomTrackbar = false;
  319. ctrl.NavigationPanelOptions.ShowCoordinates = true;
  320. ctrl.NavigationPanelOptions.ShowKilometersScale = false;
  321. ctrl.NavigationPanelOptions.ShowMilesScale = false;
  322. ctrl.NavigationPanelOptions.CoordinatesStyle.Font = new Font("微软雅黑", 10F);
  323. ctrl.NavigationPanelOptions.ScaleStyle.Font = new Font("微软雅黑", 10F);
  324. // Create ImageTileLayer
  325. ImageLayer layer = new ImageLayer() { Name = "ImageTileLayer" };
  326. //bool localGmdbDataEnable = false;//本地Data.Gmdb是否可用,可用时读取本地瓦片,否则执行Http请求资源
  327. //var files = Directory.GetFiles(Application.StartupPath, "Data.gmdb", SearchOption.AllDirectories);
  328. //if (files.Length > 0)
  329. //{
  330. // try
  331. // {
  332. // string conStr = string.Format("Data Source=\"{0}\";Page Size=32768", files[0]);
  333. // var con = new SQLiteConnection(conStr);
  334. // con.Open();
  335. // con.Close();
  336. // localGmdbDataEnable = true;
  337. // }
  338. // catch (Exception ex)
  339. // {
  340. // Console.Error.WriteLine(ex.Message);
  341. // }
  342. //}
  343. //if (localGmdbDataEnable)
  344. //{
  345. // var provider = new ImageTileDataProvider();//地图瓦片提供者
  346. // provider.TileSource = new ImageTileSource();//地图瓦片数据源接口实现
  347. // layer.DataProvider = provider;
  348. //}
  349. //else
  350. //{
  351. // var provider = new HttpMapDataProvider();
  352. // layer.DataProvider = provider;
  353. //}
  354. ctrl.Layers.Add(layer);
  355. //地图绘制加载(标点、测距、框选等元素载体图层).用来绘制可擦除的元素
  356. var layerDraw = new VectorItemsLayer() { Name = "DrawLayer" };
  357. var drawDataStorage = new MapItemStorage();
  358. layerDraw.Data = drawDataStorage;
  359. ctrl.Layers.Add(layerDraw);
  360. innerData.mMapStorage = drawDataStorage;
  361. //绘制图层,不可手动擦除,一般用来绘制卫星、参考站等固定元素
  362. var layerDrawFixed = new VectorItemsLayer() { Name = "FixedDrawLayer" };
  363. var drawDataStorageFixed = new MapItemStorage();
  364. layerDrawFixed.Data = drawDataStorageFixed;
  365. ctrl.Layers.Add(layerDrawFixed);
  366. innerData.mMapStorageFixed = drawDataStorageFixed;
  367. //定位点专用PosLayer
  368. var layerPos = new VectorItemsLayer() { Name = "PosLayer" };
  369. layerPos.ToolTipPattern = "Test";//随便给一个,不然不会显示定位点的tooltip
  370. layerPos.AllowEditItems = true;
  371. layerPos.EnableHighlighting = false;
  372. layerPos.EnableSelection = false;
  373. ctrl.Layers.Add(layerPos);
  374. var posStorge = new MapItemStorage();
  375. layerPos.Data = posStorge;
  376. innerData.posStorge = posStorge;
  377. return ctrl;
  378. }
  379. /// <summary>
  380. /// 在框选矩形上增加右键菜单
  381. /// </summary>
  382. /// <param name="ctrl"></param>
  383. /// <param name="caption"></param>
  384. /// <param name="img"></param>
  385. /// <param name="action">一个回调,参数为选中的定位点</param>
  386. /// <returns></returns>
  387. public static MapControl AddPosMenu<T>(this MapControl ctrl, string caption, SvgImage img, Action<T> action, Func<T, bool> showCondition = null) where T : PosData, new()
  388. {
  389. var btnCustom = new BarButtonItem() { Caption = caption };
  390. btnCustom.ImageOptions.SvgImage = img;
  391. btnCustom.Tag = ctrl;
  392. var innerData = ctrl.Tag as InnerData;
  393. btnCustom.ItemClick += (sender, e) =>
  394. {
  395. action((T)innerData.preSelectedItem.Tag);
  396. };
  397. innerData.barM.BeginInit();
  398. innerData.barM.Items.Add(btnCustom);
  399. innerData.posMenu.LinksPersistInfo.Add(new LinkPersistInfo(btnCustom));
  400. innerData.barM.EndInit();
  401. innerData.posMenu.BeforePopup += (sender, e) =>
  402. {
  403. if (showCondition == null)
  404. btnCustom.Visibility = BarItemVisibility.Always;
  405. else
  406. {
  407. bool showBtn = showCondition((T)innerData.preSelectedItem.Tag);
  408. if (showBtn)
  409. btnCustom.Visibility = BarItemVisibility.Always;
  410. else
  411. btnCustom.Visibility = BarItemVisibility.Never;
  412. }
  413. };
  414. return ctrl;
  415. }
  416. /// <summary>
  417. /// 在地图上增加右键菜单
  418. /// </summary>
  419. /// <param name="ctrl"></param>
  420. /// <param name="caption"></param>
  421. /// <param name="img"></param>
  422. /// <param name="action">一个回调,参数为点击位置的经纬度</param>
  423. /// <returns></returns>
  424. public static MapControl AddMapMenu(this MapControl ctrl, string caption, SvgImage img, Action<double, double> action)
  425. {
  426. var btnCustom = new BarButtonItem() { Caption = caption, Name = caption };
  427. btnCustom.ImageOptions.SvgImage = img;
  428. btnCustom.Tag = ctrl;
  429. var innerData = ctrl.Tag as InnerData;
  430. btnCustom.ItemClick += (sender, e) =>
  431. {
  432. action(innerData._mapMenuGeoPoint.Longitude, innerData._mapMenuGeoPoint.Latitude);
  433. };
  434. innerData.barM.BeginInit();
  435. innerData.barM.Items.Add(btnCustom);
  436. innerData.mapMenu.LinksPersistInfo.Add(new LinkPersistInfo(btnCustom));
  437. innerData.barM.EndInit();
  438. return ctrl;
  439. }
  440. /// <summary>
  441. /// 在框选矩形上增加右键菜单
  442. /// </summary>
  443. /// <param name="ctrl"></param>
  444. /// <param name="caption"></param>
  445. /// <param name="img"></param>
  446. /// <param name="action">一个回调,参数为框选的定位点</param>
  447. /// <returns></returns>
  448. public static MapControl AddRectMenu<T>(this MapControl ctrl, string caption, SvgImage img, Action<IEnumerable<T>> action) where T : PosData, new()
  449. {
  450. var btnCustom = new BarButtonItem() { Caption = caption };
  451. btnCustom.ImageOptions.SvgImage = img;
  452. btnCustom.Tag = ctrl;
  453. btnCustom.ItemClick += (sender, e) =>
  454. {
  455. var data = ctrl.GetRectPosItem<T>();
  456. action(data);
  457. };
  458. var innerData = ctrl.Tag as InnerData;
  459. innerData.barM.BeginInit();
  460. innerData.barM.Items.Add(btnCustom);
  461. innerData.rectMenu.LinksPersistInfo.Add(new LinkPersistInfo(btnCustom));
  462. innerData.barM.EndInit();
  463. return ctrl;
  464. }
  465. /// <summary>
  466. /// 重新设置定位数据
  467. /// </summary>
  468. /// <typeparam name="T"></typeparam>
  469. /// <param name="items">数据源(指定null或空集合可以清空已有数据)</param>
  470. /// <param name="clearDrawLayer">是否清除DrawLayer上临时绘制的内容</param>
  471. public static void SetPosDataSource<T>(this MapControl ctrl, IEnumerable<T> items, bool clearDrawLayer = true) where T : PosData, new()
  472. {
  473. var innerData = ctrl.Tag as InnerData;
  474. innerData._dataCache.Clear();
  475. if (clearDrawLayer)
  476. ctrl.ClearDrawObj();
  477. innerData.posStorge.Items.Clear();
  478. if (items == null || !items.Any())
  479. {
  480. ctrl.Refresh();
  481. return;
  482. }
  483. List<MapDot> list = new List<MapDot>();
  484. for (int i = 0; i < items.Count(); i++)
  485. {
  486. var p = items.ElementAt(i);
  487. if (p.PosLon > 180) continue;
  488. var mapItem = new MapDot()
  489. {
  490. EnableHighlighting = DefaultBoolean.True,
  491. EnableSelection = DefaultBoolean.False,
  492. CanMove = false,
  493. Visible = p.Visible,
  494. IsHitTestVisible = true,
  495. Fill = ColorHelper.IsHtmlColor(p.ColorKey) ? ColorTranslator.FromHtml(p.ColorKey) : ColorHelper.GetColor(p.ColorKey),
  496. Size = _dotSize,
  497. Tag = items.ElementAt(i),
  498. Location = new GeoPoint(p.PosLat, p.PosLon)
  499. };
  500. list.Add(mapItem);
  501. innerData._dataCache.Add(p, mapItem);
  502. }
  503. innerData.posStorge.Items.AddRange(list);
  504. }
  505. /// <summary>
  506. /// 定位图层数据源添加一个定位点
  507. /// </summary>
  508. /// <typeparam name="T"></typeparam>
  509. /// <param name="item"></param>
  510. public static void AddPosItem<T>(this MapControl ctrl, T item) where T : PosData, new()
  511. {
  512. if (item.PosLon > 180) return;
  513. var innerData = ctrl.Tag as InnerData;
  514. var mapItem = new MapDot()
  515. {
  516. EnableHighlighting = DefaultBoolean.True,
  517. EnableSelection = DefaultBoolean.False,
  518. CanMove = false,
  519. Visible = item.Visible,
  520. IsHitTestVisible = true,
  521. Fill = ColorHelper.IsHtmlColor(item.ColorKey) ? ColorTranslator.FromHtml(item.ColorKey) : ColorHelper.GetColor(item.ColorKey),
  522. Size = _dotSize,
  523. Tag = item,
  524. Location = new GeoPoint(item.PosLat, item.PosLon)
  525. };
  526. innerData._dataCache.Add(item, mapItem);
  527. innerData.posStorge.Items.Add(mapItem);
  528. }
  529. /// <summary>
  530. /// 定位图层数据源删除定位点
  531. /// </summary>
  532. /// <typeparam name="T"></typeparam>
  533. /// <param name="ctrl"></param>
  534. /// <param name="data"></param>
  535. public static void DelPosItem<T>(this MapControl ctrl, IEnumerable<T> data) where T : PosData, new()
  536. {
  537. if (data == null || !data.Any()) return;
  538. foreach (var item in data)
  539. {
  540. ctrl.DelPosItem(item);
  541. }
  542. ctrl.Refresh();
  543. }
  544. /// <summary>
  545. /// 定位图层数据源删除定位点
  546. /// </summary>
  547. /// <typeparam name="T"></typeparam>
  548. /// <param name="ctrl"></param>
  549. /// <param name="data"></param>
  550. public static void DelPosItem<T>(this MapControl ctrl, T item) where T : PosData, new()
  551. {
  552. if (item == null) return;
  553. var innerData = ctrl.Tag as InnerData;
  554. if (innerData._dataCache.ContainsKey(item))
  555. {
  556. innerData.posStorge.Items.Remove(innerData._dataCache[item]);
  557. innerData._dataCache.Remove(item);
  558. }
  559. ctrl.Refresh();
  560. }
  561. /// <summary>
  562. /// 定位图层数据源删除定位点
  563. /// </summary>
  564. /// <typeparam name="T"></typeparam>
  565. /// <param name="ctrl"></param>
  566. /// <param name="data"></param>
  567. public static void DelPosItem<T>(this MapControl ctrl, Func<T, bool> predicate) where T : PosData, new()
  568. {
  569. var innerData = ctrl.Tag as InnerData;
  570. List<PosData> keys = new List<PosData>();
  571. foreach (var item in innerData._dataCache.Keys)
  572. {
  573. if (predicate((T)item))
  574. keys.Add(item);
  575. }
  576. foreach (var item in keys)
  577. {
  578. ctrl.DelPosItem(item);
  579. }
  580. ctrl.Refresh();
  581. }
  582. /// <summary>
  583. /// 更新定位数据(可以更新可见性、颜色、经纬度、选中状态)
  584. /// </summary>
  585. /// <typeparam name="T"></typeparam>
  586. /// <param name="ctrl"></param>
  587. /// <param name="item"></param>
  588. /// <param name="setCenter">是否将这个点设置到地图中心显示</param>
  589. public static void UpdatePosItem<T>(this MapControl ctrl, T item, bool setCenter = false) where T : PosData, new()
  590. {
  591. if (item == null) return;
  592. var innerData = ctrl.Tag as InnerData;
  593. if (innerData._dataCache.ContainsKey(item))
  594. {
  595. var mapDot = innerData._dataCache[item] as MapDot;
  596. mapDot.Visible = item.Visible;//外部修改了可见性
  597. mapDot.Fill = ColorHelper.IsHtmlColor(item.ColorKey) ? ColorTranslator.FromHtml(item.ColorKey) : ColorHelper.GetColor(item.ColorKey);//外部修改了颜色
  598. mapDot.Location = new GeoPoint(item.PosLat, item.PosLon);//外部修改了位置
  599. if (mapDot.Size != (item.Selected ? _selectedDotSize : _dotSize))//外部修改了选中状态
  600. {
  601. mapDot.Size = item.Selected ? _selectedDotSize : _dotSize;
  602. mapDot.StrokeWidth = item.Selected ? 0 : 1;
  603. if (item.ClusterCount > 1)
  604. {
  605. if (innerData._clusterCache.TryGetValue(item.ClusterKey, out MapItem clusterItem))
  606. {
  607. (clusterItem as MapDot).Size = item.Selected ? _selectedDotSize : _dotSize;
  608. }
  609. }
  610. if (mapDot.ClusteredItems.Any())
  611. (mapDot.ClusteredItems[0] as MapDot).Size = _selectedDotSize;
  612. if (item.Selected)
  613. {
  614. //让选中的Item在上层
  615. var idx = innerData.posStorge.Items.IndexOf(mapDot);
  616. innerData.posStorge.Items.Swap(idx, innerData.posStorge.Items.Count - 1);
  617. //innerData.posStorge.Items.Add(mapDot);
  618. //需要将上次选中的点设置为未选中
  619. if (innerData.preSelectedItem != null)
  620. {
  621. innerData.preSelectedItem.Size = _dotSize;
  622. (innerData.preSelectedItem.Tag as PosData).Selected = false;
  623. if ((innerData.preSelectedItem.Tag as PosData).ClusterCount > 1)
  624. {
  625. if (innerData._clusterCache.TryGetValue((innerData.preSelectedItem.Tag as PosData).ClusterKey, out MapItem clusterItem))
  626. {
  627. (clusterItem as MapDot).Size = _dotSize + 2;
  628. }
  629. }
  630. }
  631. innerData.preSelectedItem = mapDot;
  632. }
  633. }
  634. if (setCenter && item.Visible)
  635. ctrl.SetCenterPoint(item.PosLon, item.PosLat, false);
  636. }
  637. }
  638. /// <summary>
  639. /// 更新定位数据(可以更新可见性、颜色、经纬度)
  640. /// </summary>
  641. /// <typeparam name="T"></typeparam>
  642. /// <param name="ctrl"></param>
  643. /// <param name="item"></param>
  644. public static void UpdatePosItem<T>(this MapControl ctrl, IEnumerable<T> items) where T : PosData, new()
  645. {
  646. if (items == null || !items.Any()) return;
  647. var innerData = ctrl.Tag as InnerData;
  648. foreach (var item in items)
  649. {
  650. if (innerData._dataCache.ContainsKey(item))
  651. {
  652. var mapDot = innerData._dataCache[item] as MapDot;
  653. mapDot.Visible = item.Visible;//外部修改了可见性
  654. mapDot.Fill = ColorHelper.IsHtmlColor(item.ColorKey) ? ColorTranslator.FromHtml(item.ColorKey) : ColorHelper.GetColor(item.ColorKey);//外部修改了颜色
  655. mapDot.Location = new GeoPoint(item.PosLat, item.PosLon);//外部修改了位置
  656. }
  657. }
  658. }
  659. /// <summary>
  660. /// 设置地图中心点
  661. /// </summary>
  662. /// <param name="ctrl"></param>
  663. /// <param name="lon"></param>
  664. /// <param name="lat"></param>
  665. /// <param name="animated">是否显示动画</param>
  666. /// <returns></returns>
  667. public static MapControl SetCenterPoint(this MapControl ctrl, double lon, double lat, bool animated = false)
  668. {
  669. ctrl.SetCenterPoint(new GeoPoint(lat, lon), animated);
  670. return ctrl;
  671. }
  672. /// <summary>
  673. /// 地图上添加图片
  674. /// </summary>
  675. /// <param name="ctrl"></param>
  676. /// <param name="tag"></param>
  677. /// <param name="imgLat"></param>
  678. /// <param name="imgLon"></param>
  679. /// <param name="img"></param>
  680. /// <param name="toolTip"></param>
  681. public static void DrawFixedImg(this MapControl ctrl, string tag, double imgLat, double imgLon, Image img, string toolTip = "")
  682. {
  683. var innerData = ctrl.Tag as InnerData;
  684. var item = new MapCustomElement() { Tag = new object[] { tag, toolTip } };
  685. item.UseAnimation = false;
  686. item.BackgroundDrawingMode = ElementState.None;
  687. item.Location = new GeoPoint(imgLat, imgLon);
  688. item.Image = img;
  689. item.ToolTipPattern = toolTip;
  690. innerData.mMapStorageFixed.Items.Add(item);
  691. }
  692. /// <summary>
  693. /// 地图上添加指定大小图片
  694. /// </summary>
  695. /// <param name="ctrl"></param>
  696. /// <param name="tag"></param>
  697. /// <param name="imgLat"></param>
  698. /// <param name="imgLon"></param>
  699. /// <param name="img"></param>
  700. /// <param name="size"></param>
  701. /// <param name="toolTip"></param>
  702. public static void DrawFixedImg(this MapControl ctrl, string tag, double imgLat, double imgLon, SvgImage img, string toolTip = "")
  703. {
  704. var innerData = ctrl.Tag as InnerData;
  705. var item = new MapCustomElement() { Tag = new object[] { tag, toolTip } };
  706. item.UseAnimation = false;
  707. item.BackgroundDrawingMode = ElementState.None;
  708. item.Location = new GeoPoint(imgLat, imgLon);
  709. item.SvgImage = img;
  710. item.ToolTipPattern = toolTip;
  711. innerData.mMapStorageFixed.Items.Add(item);
  712. }
  713. public static void DelFixedImg(this MapControl ctrl, string tag)
  714. {
  715. var innerData = ctrl.Tag as InnerData;
  716. var delItems = innerData.mMapStorageFixed.Items.ToList().FindAll(p => ((object[])p.Tag)[0].ToString() == tag);
  717. foreach (var item in delItems)
  718. {
  719. innerData.mMapStorageFixed.Items.Remove(item);
  720. }
  721. }
  722. /// <summary>
  723. /// 获取当前矩形框选的定位点
  724. /// </summary>
  725. /// <param name="ctrl"></param>
  726. /// <returns></returns>
  727. public static IEnumerable<T> GetRectPosItem<T>(this MapControl ctrl) where T : PosData, new()
  728. {
  729. var innerData = ctrl.Tag as InnerData;
  730. if (innerData.CurrentRect == default) return new List<T>();
  731. var rect = ctrl.GetCurrentRect();
  732. double startLon = rect.starLon;
  733. double startLat = rect.startLat;
  734. double endLon = rect.endLon;
  735. double endLat = rect.endLat;
  736. var temp = innerData._dataCache.Keys.Where(p => p.InRectangle(startLon, startLat, endLon, endLat));
  737. var res = temp.Select(p => (T)p);
  738. return res;
  739. }
  740. /// <summary>
  741. /// <para>设置地图瓦片Http地址.格式如http://192.168.100.63:58089</para>
  742. /// <para>当客户端本地运行目录或子目录存在Data.gmdb时Http接口不会被调用</para>
  743. /// </summary>
  744. /// <param name="ctrl"></param>
  745. /// <param name="httpAddr">such as http://192.168.100.63:58089</param>
  746. /// <returns></returns>
  747. public static MapControl SetMapDataHttpAddr(this MapControl ctrl, string httpAddr)
  748. {
  749. var provider = ctrl.GetImageLayer().DataProvider;
  750. if (provider is HttpMapDataProvider)
  751. {
  752. var tileSource = ((provider as HttpMapDataProvider).TileSource as HttpTileSource);
  753. tileSource.HttpServerAddr = httpAddr;
  754. }
  755. return ctrl;
  756. }
  757. /// <summary>
  758. /// 定位点使用内置聚合器
  759. /// </summary>
  760. /// <param name="ctrl"></param>
  761. /// <returns></returns>
  762. public static MapControl UseCluster(this MapControl ctrl)
  763. {
  764. var innerData = ctrl.Tag as InnerData;
  765. innerData.posStorge.Clusterer = new PosClusterer(ctrl);//定位点聚合器
  766. return ctrl;
  767. }
  768. /// <summary>
  769. /// 为地图添加右键测距功能
  770. /// </summary>
  771. /// <returns></returns>
  772. public static MapControl UseDistanceLine(this MapControl ctrl)
  773. {
  774. var btnDistance = new BarButtonItem() { Caption = "测距" };
  775. btnDistance.ImageOptions.SvgImage = SvgHelper.CreateDistanceLine();
  776. btnDistance.Tag = ctrl;
  777. btnDistance.ItemClick += DistanceLine_ItemClick;
  778. var innerData = ctrl.Tag as InnerData;
  779. innerData.barM.BeginInit();
  780. innerData.barM.Items.Add(btnDistance);
  781. innerData.mapMenu.LinksPersistInfo.Add(new LinkPersistInfo(btnDistance));
  782. innerData.barM.EndInit();
  783. return ctrl;
  784. }
  785. #region 航迹点
  786. /// <summary>
  787. /// 使用航迹
  788. /// </summary>
  789. /// <param name="ctrl"></param>
  790. /// <returns></returns>
  791. public static MapControl UseFlightLine(this MapControl ctrl, Action<(bool, XtraUserControl)> ShowPopup)
  792. {
  793. var btnFlight = new BarButtonItem() { Caption = "航迹线" };
  794. btnFlight.ImageOptions.SvgImage = SvgHelper.CreateDistanceLine();
  795. btnFlight.Tag = ctrl;
  796. var innerData = ctrl.Tag as InnerData;
  797. btnFlight.ItemClick += (sender, e) =>
  798. {
  799. var flights = innerData._flightCache.Keys.ToList();
  800. var frm = new MapFlightLineView(flights);
  801. frm.onClick = (reslut) =>
  802. {
  803. (bool isOk, string caption, double speed) = reslut;
  804. ShowPopup?.Invoke((false, frm));
  805. if (!isOk)
  806. {
  807. return;
  808. }
  809. var filghtInfo = new FlightInfo(caption, speed);
  810. innerData._flightCache.Add(filghtInfo.FlightName, filghtInfo);
  811. string filghtName = $"DrawFlightLine{caption}";
  812. ctrl.MapEditor.SetEditMode();
  813. var items = innerData.mMapStorage.Items.ToArray();
  814. innerData.flightpath = new MapSpline()
  815. {
  816. Stroke = Color.FromArgb(127, 255, 0, 199),
  817. StrokeWidth = 2,
  818. CanResize = true,
  819. CanEdit = true,
  820. CanRotate = true,
  821. IsHitTestVisible = false,
  822. CanMove = true,
  823. Tag = filghtName
  824. };
  825. innerData.mMapStorage.Items.Add(innerData.flightpath);
  826. innerData.hoverPoint = new MapDot() { CanResize = false, CanMove = false, Tag = filghtName, Size = 8 };
  827. innerData.hoverPoint.Fill = ColorHelper.GetColor(innerData.hoverPoint.Tag.ToString());
  828. innerData.mMapStorage.Items.Add(innerData.hoverPoint);
  829. //提示框
  830. SuperToolTip superToolTip = new SuperToolTip();
  831. ToolTipItem textItem = new ToolTipItem() { Text = "单击添加航迹点,双击结束绘制航迹" };
  832. superToolTip.Items.Add(textItem);
  833. ToolTipControllerShowEventArgs arg = new ToolTipControllerShowEventArgs();
  834. arg.ShowBeak = true;
  835. arg.SuperTip = superToolTip;
  836. innerData.hoverTip = arg;
  837. ctrl.MouseClick += AddFlightPoint;
  838. ctrl.MouseLeave += MapControl_MouseLeave;
  839. ctrl.MouseEnter += MapControl_MouseEnter;
  840. ctrl.MouseMove += MovingDistinct;
  841. ctrl.DoubleClick += (sender1, e1) =>
  842. {
  843. ctrl.MouseClick -= AddFlightPoint;
  844. ctrl.MouseLeave -= MapControl_MouseLeave;
  845. ctrl.MouseEnter -= MapControl_MouseEnter;
  846. ctrl.MouseMove -= MovingDistinct;
  847. };
  848. };
  849. ShowPopup?.Invoke((true, frm));
  850. };
  851. innerData.barM.BeginInit();
  852. innerData.barM.Items.Add(btnFlight);
  853. innerData.mapMenu.LinksPersistInfo.Add(new LinkPersistInfo(btnFlight));
  854. innerData.barM.EndInit();
  855. return ctrl;
  856. }
  857. /// <summary>
  858. ///
  859. /// </summary>
  860. /// <param name="ctrl"></param>
  861. /// <param name="fligthName"></param>
  862. /// <param name="speed">速度 m/s</param>
  863. /// <returns></returns>
  864. public static MapControl DrawFlightLine(this MapControl ctrl, string fligthName, double speed)
  865. {
  866. var innerData = ctrl.Tag as InnerData;
  867. var items = innerData.mMapStorage.Items.ToArray();
  868. foreach (var item in items)
  869. {
  870. if (item.Tag != null && item.Tag.ToString().Contains("DrawDistanceLine"))
  871. innerData.mMapStorage.Items.Remove(item);
  872. }
  873. if (innerData.distinctPath != null)
  874. {
  875. innerData.distinctPath.Points.Clear();
  876. }
  877. var filghtInfo = new FlightInfo(fligthName, speed);
  878. innerData._flightCache.Add(filghtInfo.FlightName, filghtInfo);
  879. string filghtName = $"DrawFlightLine{fligthName}";
  880. ctrl.MapEditor.SetEditMode();
  881. innerData.flightpath = new MapSpline()
  882. {
  883. Stroke = Color.FromArgb(127, 255, 0, 199),
  884. StrokeWidth = 2,
  885. CanResize = true,
  886. CanEdit = true,
  887. CanRotate = true,
  888. IsHitTestVisible = false,
  889. CanMove = true,
  890. Tag = filghtName
  891. };
  892. innerData.mMapStorage.Items.Add(innerData.flightpath);
  893. innerData.hoverPoint = new MapDot() { CanResize = false, CanMove = false, Tag = filghtName, Size = 8 };
  894. innerData.hoverPoint.Fill = ColorHelper.GetColor(innerData.hoverPoint.Tag.ToString());
  895. innerData.mMapStorage.Items.Add(innerData.hoverPoint);
  896. //提示框
  897. SuperToolTip superToolTip = new SuperToolTip();
  898. ToolTipItem textItem = new ToolTipItem() { Text = "单击添加航迹点,双击结束绘制航迹" };
  899. superToolTip.Items.Add(textItem);
  900. ToolTipControllerShowEventArgs arg = new ToolTipControllerShowEventArgs();
  901. arg.ShowBeak = true;
  902. arg.SuperTip = superToolTip;
  903. innerData.hoverTip = arg;
  904. ctrl.MouseClick += AddFlightPoint;
  905. ctrl.MouseLeave += MapControl_MouseLeave;
  906. ctrl.MouseEnter += MapControl_MouseEnter;
  907. ctrl.MouseMove += MovingDistinct;
  908. ctrl.DoubleClick += (sender1, e1) =>
  909. {
  910. ctrl.MouseClick -= AddFlightPoint;
  911. ctrl.MouseLeave -= MapControl_MouseLeave;
  912. ctrl.MouseEnter -= MapControl_MouseEnter;
  913. ctrl.MouseMove -= MovingDistinct;
  914. };
  915. return ctrl;
  916. }
  917. /// <summary>
  918. /// 获取航迹
  919. /// </summary>
  920. /// <param name="ctrl"></param>
  921. /// <returns></returns>
  922. public static IEnumerable<T> GetFlightLine<T>(this MapControl ctrl) where T : FlightInfo
  923. {
  924. var innerData = ctrl.Tag as InnerData;
  925. return innerData._flightCache.Select(m => (T)m.Value);
  926. }
  927. private static void AddFlightPoint(object sender, MouseEventArgs e)
  928. {
  929. var innerData = (sender as MapControl).Tag as InnerData;
  930. var ctrl = sender as MapControl;
  931. var location = ctrl.ScreenPointToCoordPoint(e.Location);
  932. string Name = innerData.flightpath.Tag.ToString().Replace("DrawFlightLine", "");
  933. double lon = Math.Round(location.GetX(), 3);
  934. double lat = Math.Round(location.GetY(), 3);
  935. innerData.hoverPoint = new MapDot()
  936. {
  937. CanResize = false,
  938. CanMove = false,
  939. ToolTipPattern = $"航迹:{Name}\r\n{lon},{lat}°",
  940. Tag = innerData.flightpath.Tag,
  941. Size = 8
  942. };
  943. innerData.hoverPoint.Location = location;
  944. innerData.hoverPoint.Fill = ColorHelper.GetColor(innerData.hoverPoint.Tag.ToString());
  945. innerData.mMapStorage.Items.Add(innerData.hoverPoint);
  946. innerData.flightpath.Points.Add(innerData.hoverPoint.Location);
  947. if (!innerData._flightCache[Name].flights.Any(m => m.FlightLon == lon && m.FlightLat == lat))
  948. {
  949. innerData._flightCache[Name].flights.Add(new FlightData(lon, lat));
  950. }
  951. }
  952. public static void SetFlightLine<T>(this MapControl ctrl, IEnumerable<T> items, bool clearDrawLayer = true) where T : FlightInfo, new()
  953. {
  954. var innerData = ctrl.Tag as InnerData;
  955. innerData._flightCache.Clear();
  956. if (clearDrawLayer)
  957. ctrl.ClearDrawObj();
  958. if (items == null || !items.Any())
  959. {
  960. ctrl.Refresh();
  961. return;
  962. }
  963. for (int i = 0; i < items.Count(); i++)
  964. {
  965. var f = items.ElementAt(i);
  966. ctrl.ShowFlightLine(innerData, f);
  967. }
  968. }
  969. private static void ShowFlightLine(this MapControl ctrl, InnerData innerData, FlightInfo flight)
  970. {
  971. string filghtName = $"DrawFlightLine{flight.FlightName}";
  972. var flightpath = new MapSpline()
  973. {
  974. Stroke = Color.FromArgb(127, 255, 0, 199),
  975. StrokeWidth = 2,
  976. CanResize = true,
  977. CanEdit = true,
  978. CanRotate = true,
  979. IsHitTestVisible = false,
  980. CanMove = true,
  981. Tag = filghtName
  982. };
  983. innerData.mMapStorage.Items.Add(flightpath);
  984. var hoverPoint = new MapDot() { CanResize = false, CanMove = false, Tag = filghtName, Size = 8 };
  985. hoverPoint.Fill = ColorHelper.GetColor(hoverPoint.Tag.ToString());
  986. innerData.mMapStorage.Items.Add(hoverPoint);
  987. if (flight.flights.Count > 0)
  988. {
  989. var center = new GeoPoint(flight.flights.First().FlightLat, flight.flights.First().FlightLon);
  990. ctrl.SetCenterPoint(center, true);
  991. }
  992. Task.Run(() =>
  993. {
  994. flight.flights.ForEach((finfo) =>
  995. {
  996. var location = new GeoPoint(finfo.FlightLat, finfo.FlightLon);
  997. var hoverPointj = new MapDot()
  998. {
  999. CanResize = false,
  1000. CanMove = false,
  1001. ToolTipPattern = $"航迹:{flight.FlightName}\r\n{finfo.FlightLon},{finfo.FlightLat}°",
  1002. Tag = flightpath.Tag,
  1003. Size = 8
  1004. };
  1005. hoverPointj.Location = location;
  1006. hoverPointj.Fill = ColorHelper.GetColor(hoverPointj.Tag.ToString());
  1007. innerData.mMapStorage.Items.Add(hoverPointj);
  1008. flightpath.Points.Add(hoverPointj.Location);
  1009. Thread.Sleep(1000);
  1010. });
  1011. });
  1012. innerData._flightCache.Add(flight.FlightName, flight);
  1013. }
  1014. public static MapControl UseExportFlightLine(this MapControl ctrl)
  1015. {
  1016. var innerData = ctrl.Tag as InnerData;
  1017. var btnExportFlightLine = new BarButtonItem() { Caption = "导出航迹" };
  1018. btnExportFlightLine.ImageOptions.SvgImage = SvgHelper.CreateExportCsv();
  1019. btnExportFlightLine.Tag = ctrl;
  1020. btnExportFlightLine.ItemClick += (sender, e) =>
  1021. {
  1022. if (!innerData._flightCache.Any()) return;
  1023. List<FightDataCsv> list = new List<FightDataCsv>();
  1024. foreach (var item in innerData._flightCache.Values)
  1025. {
  1026. foreach (var fitem in item.flights)
  1027. {
  1028. list.Add(new FightDataCsv(item.FlightName, item.Speed, fitem.FlightLon, fitem.FlightLat));
  1029. }
  1030. }
  1031. Dictionary<string, string> cellFormats = new Dictionary<string, string>();//单元格的format
  1032. var props = list.First().GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
  1033. List<(int ColumnIndex, PropertyInfo Prop, string Header)> listPorps = new List<(int, PropertyInfo, string)>();
  1034. foreach (var prop in props)
  1035. {
  1036. ExportCellAttribute attrExport = prop.GetCustomAttribute<ExportCellAttribute>();
  1037. if (attrExport == null) continue;
  1038. if (!string.IsNullOrWhiteSpace(attrExport.Format))
  1039. {
  1040. cellFormats.Add(prop.Name, attrExport.Format);
  1041. }
  1042. if (attrExport.ColumnIndex == -1)
  1043. attrExport.ColumnIndex = 10000;
  1044. var attrDisplay = prop.GetCustomAttribute<DisplayAttribute>();
  1045. if (attrDisplay != null && !string.IsNullOrWhiteSpace(attrDisplay.Name))
  1046. listPorps.Add((attrExport.ColumnIndex, prop, attrDisplay.Name));
  1047. else
  1048. listPorps.Add((attrExport.ColumnIndex, prop, prop.Name));
  1049. }
  1050. listPorps = listPorps.OrderBy(p => p.ColumnIndex).ToList();
  1051. using (var dialog = new SaveFileDialog())
  1052. {
  1053. dialog.Filter = "CSV文件|*.csv";
  1054. dialog.AddExtension = true;
  1055. dialog.FileName = $"FlightLine{DateTime.Now:yyyyMMddHHmmss}.csv";
  1056. if (dialog.ShowDialog() == DialogResult.OK)
  1057. {
  1058. StreamWriter sw = new StreamWriter(dialog.FileName, false, new UTF8Encoding(true));//utf8-bom
  1059. foreach (var prop in listPorps)
  1060. {
  1061. sw.Write($"{prop.Header},");
  1062. }
  1063. sw.WriteLine();
  1064. WaitHelper.ShowOverlayForm(ctrl);
  1065. long count = list.Count() * listPorps.Count;
  1066. int idx = 1;
  1067. foreach (var item in list)
  1068. {
  1069. foreach (var prop in listPorps)
  1070. {
  1071. WaitHelper.UpdateOverlyText($"{idx * 100 / count}%");
  1072. var value = prop.Prop.GetValue(item);
  1073. string str = null;
  1074. if (cellFormats.ContainsKey(prop.Prop.Name))
  1075. {
  1076. str = ((dynamic)value).ToString(cellFormats[prop.Prop.Name]);
  1077. }
  1078. else
  1079. {
  1080. if (value is DateTime)
  1081. str = $"{(DateTime)value:yyyy-MM-dd HH:mm:ss}";
  1082. else if (value is float || value is double || value is decimal)
  1083. {
  1084. dynamic valD = value;
  1085. str = ((dynamic)value).ToString("f4");
  1086. }
  1087. else if (value is string)
  1088. {
  1089. str = value.ToString();
  1090. }
  1091. }
  1092. sw.Write($"{str},");
  1093. idx++;
  1094. }
  1095. sw.WriteLine();
  1096. }
  1097. sw.Close();
  1098. WaitHelper.CloseOverlayForm();
  1099. }
  1100. }
  1101. GC.Collect();
  1102. };
  1103. innerData.barM.BeginInit();
  1104. innerData.barM.Items.Add(btnExportFlightLine);
  1105. innerData.mapMenu.LinksPersistInfo.Add(new LinkPersistInfo(btnExportFlightLine));
  1106. innerData.barM.EndInit();
  1107. return ctrl;
  1108. }
  1109. #endregion
  1110. /// <summary>
  1111. /// 为地图添加右键标点功能
  1112. /// </summary>
  1113. /// <param name="ctrl"></param>
  1114. /// <param name="menu"></param>
  1115. /// <param name="item"></param>
  1116. /// <returns></returns>
  1117. public static MapControl UseMarkDot(this MapControl ctrl)
  1118. {
  1119. var btnMarkDot = new BarButtonItem() { Caption = "标点" };
  1120. btnMarkDot.ImageOptions.SvgImage = SvgHelper.CreateMarkDot();
  1121. btnMarkDot.Tag = ctrl;
  1122. btnMarkDot.ItemClick += MarkDot_ItemClick;
  1123. var innerData = ctrl.Tag as InnerData;
  1124. innerData.barM.BeginInit();
  1125. innerData.barM.Items.Add(btnMarkDot);
  1126. innerData.mapMenu.LinksPersistInfo.Add(new LinkPersistInfo(btnMarkDot));
  1127. innerData.barM.EndInit();
  1128. return ctrl;
  1129. }
  1130. /// <summary>
  1131. /// 为地图添加清除功能
  1132. /// </summary>
  1133. /// <param name="ctrl"></param>
  1134. /// <param name="item"></param>
  1135. /// <returns></returns>
  1136. public static MapControl UseClearAll(this MapControl ctrl)
  1137. {
  1138. var btnClearAll = new BarButtonItem() { Caption = "清除" };
  1139. btnClearAll.ImageOptions.SvgImage = SvgHelper.CreateClear();
  1140. btnClearAll.Tag = ctrl;
  1141. btnClearAll.ItemClick += (sender, e) => ctrl.ClearDrawObj();
  1142. var innerData = ctrl.Tag as InnerData;
  1143. innerData.barM.BeginInit();
  1144. innerData.barM.Items.Add(btnClearAll);
  1145. innerData.mapMenu.LinksPersistInfo.Add(new LinkPersistInfo(btnClearAll));
  1146. innerData.barM.EndInit();
  1147. return ctrl;
  1148. }
  1149. /// <summary>
  1150. /// 为地图添加导出图片功能
  1151. /// </summary>
  1152. /// <param name="ctrl"></param>
  1153. /// <param name="item"></param>
  1154. /// <returns></returns>
  1155. public static MapControl UseExportImg(this MapControl ctrl)
  1156. {
  1157. var btnExportImg = new BarButtonItem() { Caption = "导出图片" };
  1158. btnExportImg.ImageOptions.SvgImage = SvgHelper.CreateExportImg();
  1159. btnExportImg.Tag = ctrl;
  1160. btnExportImg.ItemClick += ExportImg_ItemClick;
  1161. var innerData = ctrl.Tag as InnerData;
  1162. innerData.barM.BeginInit();
  1163. innerData.barM.Items.Add(btnExportImg);
  1164. innerData.mapMenu.LinksPersistInfo.Add(new LinkPersistInfo(btnExportImg));
  1165. innerData.barM.EndInit();
  1166. return ctrl;
  1167. }
  1168. /// <summary>
  1169. /// 为地图添加导出图片功能
  1170. /// </summary>
  1171. /// <param name="ctrl"></param>
  1172. /// <param name="item"></param>
  1173. /// <returns></returns>
  1174. public static MapControl UseExportCsv(this MapControl ctrl, bool exportHeader = true)
  1175. {
  1176. var innerData = ctrl.Tag as InnerData;
  1177. var btnExportCsv = new BarButtonItem() { Caption = "导出Csv" };
  1178. btnExportCsv.ImageOptions.SvgImage = SvgHelper.CreateExportCsv();
  1179. btnExportCsv.Tag = ctrl;
  1180. btnExportCsv.ItemClick += (sender, e) =>
  1181. {
  1182. if (!innerData._dataCache.Any()) return;
  1183. bool exportSigTime = false;
  1184. Dictionary<string, string> cellFormats = new Dictionary<string, string>();//单元格的format
  1185. var props = innerData._dataCache.Keys.GetType().GetGenericArguments().First().GetProperties(BindingFlags.Public | BindingFlags.Instance);
  1186. List<(int ColumnIndex, PropertyInfo Prop, string Header)> listPorps = new List<(int, PropertyInfo, string)>();
  1187. foreach (var prop in props)
  1188. {
  1189. ExportCellAttribute attrExport = prop.GetCustomAttribute<ExportCellAttribute>();
  1190. if (attrExport == null) continue;
  1191. if (prop.Name == nameof(PosData.SigTime))
  1192. exportSigTime = true;
  1193. if (!string.IsNullOrWhiteSpace(attrExport.Format))
  1194. {
  1195. cellFormats.Add(prop.Name, attrExport.Format);
  1196. }
  1197. if (attrExport.ColumnIndex == -1)
  1198. attrExport.ColumnIndex = 10000;
  1199. var attrDisplay = prop.GetCustomAttribute<DisplayAttribute>();
  1200. if (attrDisplay != null && !string.IsNullOrWhiteSpace(attrDisplay.Name))
  1201. listPorps.Add((attrExport.ColumnIndex, prop, attrDisplay.Name));
  1202. else
  1203. listPorps.Add((attrExport.ColumnIndex, prop, prop.Name));
  1204. }
  1205. listPorps = listPorps.OrderBy(p => p.ColumnIndex).ToList();
  1206. using (var dialog = new SaveFileDialog())
  1207. {
  1208. dialog.Filter = "CSV文件|*.csv";
  1209. dialog.AddExtension = true;
  1210. dialog.FileName = $"Pos{DateTime.Now:yyyyMMddHHmmss}.csv";
  1211. if (dialog.ShowDialog() == DialogResult.OK)
  1212. {
  1213. var list = innerData._dataCache.Keys as IEnumerable<PosData>;
  1214. if (exportSigTime)
  1215. list = list.OrderByDescending(p => p.SigTime);//如果导出了SigTime,则自动按照SigTime降序排列后导出
  1216. StreamWriter sw = new StreamWriter(dialog.FileName, false, new UTF8Encoding(true));//utf8-bom
  1217. if (exportHeader)
  1218. {
  1219. foreach (var prop in listPorps)
  1220. {
  1221. sw.Write($"{prop.Header},");
  1222. }
  1223. sw.WriteLine();
  1224. }
  1225. WaitHelper.ShowOverlayForm(ctrl);
  1226. long count = list.Count() * listPorps.Count;
  1227. int idx = 1;
  1228. foreach (var item in list)
  1229. {
  1230. foreach (var prop in listPorps)
  1231. {
  1232. WaitHelper.UpdateOverlyText($"{idx * 100 / count}%");
  1233. var value = prop.Prop.GetValue(item);
  1234. string str = null;
  1235. if (cellFormats.ContainsKey(prop.Prop.Name))
  1236. {
  1237. str = ((dynamic)value).ToString(cellFormats[prop.Prop.Name]);
  1238. }
  1239. else
  1240. {
  1241. if (value is DateTime)
  1242. str = $"{(DateTime)value:yyyy-MM-dd HH:mm:ss}";
  1243. else if (value is float || value is double || value is decimal)
  1244. {
  1245. dynamic valD = value;
  1246. str = ((dynamic)value).ToString("f4");
  1247. }
  1248. }
  1249. sw.Write($"{str},");
  1250. idx++;
  1251. }
  1252. sw.WriteLine();
  1253. }
  1254. sw.Close();
  1255. WaitHelper.CloseOverlayForm();
  1256. }
  1257. }
  1258. GC.Collect();
  1259. };
  1260. innerData.barM.BeginInit();
  1261. innerData.barM.Items.Add(btnExportCsv);
  1262. innerData.mapMenu.LinksPersistInfo.Add(new LinkPersistInfo(btnExportCsv));
  1263. innerData.barM.EndInit();
  1264. return ctrl;
  1265. }
  1266. /// <summary>
  1267. /// 为地图添加导出Excel数据功能
  1268. /// </summary>
  1269. /// <typeparam name="T"></typeparam>
  1270. /// <param name="ctrl"></param>
  1271. /// <param name="exportHeader">是否导出列头</param>
  1272. /// <returns></returns>
  1273. public static MapControl UseExportXlsx(this MapControl ctrl, bool exportHeader = true)
  1274. {
  1275. Action action = () =>
  1276. {
  1277. var btnExportXlsx = new BarButtonItem() { Caption = "导出Excel" };
  1278. btnExportXlsx.ImageOptions.SvgImage = SvgHelper.CreateExportXlsx();
  1279. var innerData = ctrl.Tag as InnerData;
  1280. innerData.barM.BeginInit();
  1281. innerData.barM.Items.Add(btnExportXlsx);
  1282. innerData.mapMenu.LinksPersistInfo.Add(new LinkPersistInfo(btnExportXlsx));
  1283. innerData.barM.EndInit();
  1284. btnExportXlsx.ItemClick += (sender, e) =>
  1285. {
  1286. if (!innerData._dataCache.Any()) return;
  1287. GridControl gc = new GridControl();
  1288. GridView view = new GridView();
  1289. view.GridControl = gc;
  1290. gc.MainView = view;
  1291. gc.ViewCollection.Add(view);
  1292. view.OptionsPrint.ShowPrintExportProgress = false;
  1293. bool exportSigTime = false;
  1294. Dictionary<string, string> cellFormats = new Dictionary<string, string>();//单元格的format
  1295. var props = innerData._dataCache.Keys.GetType().GetGenericArguments().First().GetProperties(BindingFlags.Public | BindingFlags.Instance);
  1296. foreach (var prop in props)
  1297. {
  1298. ExportCellAttribute attrExport = prop.GetCustomAttribute<ExportCellAttribute>();
  1299. if (attrExport == null) continue;
  1300. if (prop.Name == nameof(PosData.SigTime))
  1301. exportSigTime = true;
  1302. if (!string.IsNullOrWhiteSpace(attrExport.Format))
  1303. {
  1304. cellFormats.Add(prop.Name, attrExport.Format);
  1305. }
  1306. var col = new GridColumn();
  1307. col.FieldName = prop.Name;
  1308. col.Visible = true;
  1309. var attr = prop.GetCustomAttribute<DisplayAttribute>();
  1310. if (attr != null && !string.IsNullOrWhiteSpace(attr.Name))
  1311. col.Caption = attr.Name;
  1312. else
  1313. col.Caption = prop.Name;
  1314. if (attrExport.ColumnIndex >= 0)
  1315. col.VisibleIndex = attrExport.ColumnIndex;
  1316. view.Columns.Add(col);
  1317. }
  1318. gc.Visible = false;
  1319. gc.Parent = ctrl.Parent;
  1320. using (var dialog = new SaveFileDialog())
  1321. {
  1322. dialog.Filter = "Excel文件|*.xlsx";
  1323. dialog.AddExtension = true;
  1324. dialog.FileName = $"Pos{DateTime.Now:yyyyMMddHHmmss}.xlsx";
  1325. if (dialog.ShowDialog() == DialogResult.OK)
  1326. {
  1327. var list = innerData._dataCache.Keys.ToList();
  1328. if (exportSigTime)
  1329. list = list.OrderByDescending(p => p.SigTime).ToList();//如果导出了SigTime,则自动按照SigTime降序排列后导出
  1330. gc.DataSource = list;
  1331. gc.Visible = true;
  1332. var exportType = DevExpress.Export.ExportSettings.DefaultExportType;
  1333. var options = new XlsxExportOptionsEx();
  1334. WaitHelper.ShowOverlayForm(ctrl);
  1335. options.ExportProgress += arg =>
  1336. {
  1337. WaitHelper.UpdateOverlyText($"{arg.ProgressPercentage}%");
  1338. if (arg.ProgressPercentage >= 100)
  1339. {
  1340. WaitHelper.CloseOverlayForm();
  1341. }
  1342. };
  1343. view.OptionsPrint.PrintHeader = exportHeader;
  1344. options.CustomizeCell += arg =>
  1345. {
  1346. arg.Handled = true;
  1347. var aligmentCenter = new XlCellAlignment()
  1348. {
  1349. HorizontalAlignment = XlHorizontalAlignment.Center,
  1350. VerticalAlignment = XlVerticalAlignment.Center
  1351. };
  1352. var aligmentLeft = new XlCellAlignment()
  1353. {
  1354. HorizontalAlignment = XlHorizontalAlignment.Left,
  1355. VerticalAlignment = XlVerticalAlignment.Center
  1356. };
  1357. if (arg.Value is bool)
  1358. {
  1359. arg.Formatting.Alignment = aligmentCenter;
  1360. arg.Value = ((bool)arg.Value) ? "☑" : "☐";
  1361. }
  1362. if (arg.Value is DateTime)
  1363. {
  1364. arg.Formatting.Alignment = aligmentLeft;
  1365. arg.Formatting.FormatType = FormatType.DateTime;
  1366. arg.Formatting.FormatString = "yyyy-MM-dd HH:mm:ss";
  1367. }
  1368. else if (arg.Value is float || arg.Value is double || arg.Value is decimal)
  1369. {
  1370. arg.Formatting.Alignment = aligmentLeft;
  1371. arg.Formatting.FormatType = FormatType.Numeric;
  1372. arg.Formatting.FormatString = "f4";
  1373. }
  1374. if (cellFormats.ContainsKey(arg.ColumnFieldName))
  1375. {
  1376. arg.Formatting.FormatString = cellFormats[arg.ColumnFieldName];
  1377. }
  1378. };
  1379. view.OptionsPrint.ShowPrintExportProgress = false;
  1380. DevExpress.Export.ExportSettings.DefaultExportType = DevExpress.Export.ExportType.DataAware;
  1381. gc.ExportToXlsx(dialog.FileName, options);
  1382. DevExpress.Export.ExportSettings.DefaultExportType = exportType;
  1383. gc.Visible = false;
  1384. }
  1385. }
  1386. gc.Parent = null;
  1387. gc.Dispose();
  1388. GC.Collect();
  1389. };
  1390. };
  1391. if (ctrl.Parent == null)
  1392. {
  1393. ctrl.ParentChanged += (sender, e) => action();
  1394. }
  1395. else
  1396. {
  1397. action();
  1398. }
  1399. return ctrl;
  1400. }
  1401. /// <summary>
  1402. /// 为地图添加矩形框选区域功能
  1403. /// </summary>
  1404. /// <returns></returns>
  1405. public static MapControl UseDrawRect(this MapControl ctrl, Action<(double starLon, double startLat, double centerLon, double centerLat,
  1406. double endLon, double endLat, double lonRange, double latRange)> onRectChanged = null)
  1407. {
  1408. var innerData = ctrl.Tag as InnerData;
  1409. innerData.mOnRectChanged = onRectChanged;
  1410. ctrl.MapEditor.ShowEditorPanel = true;
  1411. ctrl.MapEditor.PanelOptions.ShowAddCalloutButton = false;
  1412. ctrl.MapEditor.PanelOptions.ShowAddCustomElementButton = false;
  1413. ctrl.MapEditor.PanelOptions.ShowAddDotButton = false;
  1414. ctrl.MapEditor.PanelOptions.ShowAddEllipseButton = false;
  1415. ctrl.MapEditor.PanelOptions.ShowAddLineButton = false;
  1416. ctrl.MapEditor.PanelOptions.ShowAddPathButton = false;
  1417. ctrl.MapEditor.PanelOptions.ShowAddPolylineButton = false;
  1418. ctrl.MapEditor.PanelOptions.ShowAddPushpinButton = false;
  1419. ctrl.MapEditor.PanelOptions.ShowAddSplineButton = false;
  1420. ctrl.MapEditor.PanelOptions.ShowEditModeButton = false;
  1421. ctrl.MapEditor.PanelOptions.ShowTransformModeButton = false;
  1422. ctrl.MapEditor.PanelOptions.ShowUndoRedoButtons = false;
  1423. ctrl.MouseMove += DrawRect_MouseMove;
  1424. ctrl.MapEditor.MapItemCreating += (sender, e) =>
  1425. {
  1426. if (!innerData.mouseLeftDown)
  1427. {
  1428. e.Cancel = true;
  1429. return;
  1430. }
  1431. if (!(e.Item is MapRectangle)) return;
  1432. var items = innerData.mMapStorage.Items.ToList().FindAll(p => p.Tag != null && p.Tag.ToString() == "DrawRect");
  1433. ctrl.MapEditor.RemoveItems(items);
  1434. var item = e.Item as MapRectangle;
  1435. item.Tag = "DrawRect";
  1436. item.CanMove = false;
  1437. item.CanResize = false;
  1438. item.EnableSelection = DefaultBoolean.False;
  1439. item.EnableHighlighting = DefaultBoolean.True;
  1440. innerData.rangeItem = item;
  1441. if (innerData.rangeItem.Height == 0 && innerData.rangeItem.Width == 0)
  1442. {
  1443. innerData.rangeItem.Height = 5;
  1444. innerData.rangeItem.Width = 5;
  1445. }
  1446. item.Fill = Color.FromArgb(50, Color.FromArgb(23, 107, 209));
  1447. item.Stroke = Color.FromArgb(23, 107, 209);
  1448. item.StrokeWidth = 1;
  1449. innerData.dotItem.Fill = Color.Red;
  1450. innerData.dotItem.Size = 6;
  1451. innerData.dotItem.Location = innerData.rangeItem.GetCenter();
  1452. innerData.mMapStorage.Items.Add(innerData.rangeItem);
  1453. innerData.mMapStorage.Items.Add(innerData.dotItem);
  1454. DrawRect_MouseMove(ctrl, null);
  1455. var layer = ctrl.Layers.Find(p => p.Name == "");
  1456. if (layer != null) ctrl.Layers.Remove(layer);
  1457. };
  1458. ctrl.MapEditor.MapItemEdited += (sender, e) =>
  1459. {
  1460. innerData.drawingRect = e.Action == MapEditorAction.Create;
  1461. };
  1462. return ctrl;
  1463. }
  1464. /// <summary>
  1465. /// 绘制矩形
  1466. /// </summary>
  1467. /// <param name="ctrl"></param>
  1468. /// <param name="startLon"></param>
  1469. /// <param name="startLat"></param>
  1470. /// <param name="endLon"></param>
  1471. /// <param name="endLat"></param>
  1472. public static void DrawRect(this MapControl ctrl, double startLon, double startLat, double endLon, double endLat, bool recCallback = false)
  1473. {
  1474. var innerData = ctrl.Tag as InnerData;
  1475. if (innerData.rangeItem != null)
  1476. innerData.mMapStorage.Items.Remove(innerData.rangeItem);
  1477. if (innerData.dotItem != null)
  1478. innerData.mMapStorage.Items.Remove(innerData.dotItem);
  1479. double centerLon = (startLon + endLon) / 2;
  1480. double centerLat = (startLat + endLat) / 2;
  1481. var size = BoundingRectItemHelper.CalculateRectangleSize(ctrl.CoordinateSystem,
  1482. new GeoPoint(startLat, startLon),
  1483. new GeoPoint(endLat, endLon));
  1484. innerData.dotItem.Location = new GeoPoint(centerLat, centerLon);
  1485. innerData.dotItem.Fill = Color.Red;
  1486. innerData.dotItem.Size = 8;
  1487. var rect = new MapRectangle()
  1488. {
  1489. CanMove = false,
  1490. CanResize = false,
  1491. EnableSelection = DefaultBoolean.False,
  1492. EnableHighlighting = DefaultBoolean.True,
  1493. Tag = "DrawRect",
  1494. Width = size.Width,
  1495. Height = size.Height,
  1496. Location = new GeoPoint(startLat, startLon),
  1497. Fill = Color.FromArgb(50, Color.FromArgb(23, 107, 209)),
  1498. Stroke = Color.FromArgb(23, 107, 209),
  1499. StrokeWidth = 1
  1500. };
  1501. innerData.rangeItem = rect;
  1502. innerData.CurrentRect = (startLon, startLat, centerLon, centerLat, endLon, endLat, (endLon - startLon) / 2, (endLat - startLat) / 2);
  1503. innerData.mMapStorage.Items.Add(innerData.rangeItem);
  1504. innerData.mMapStorage.Items.Add(innerData.dotItem);
  1505. if (recCallback)
  1506. innerData.mOnRectChanged?.Invoke(ctrl.GetCurrentRect());
  1507. }
  1508. public static void DrawDtoPonit(this MapControl ctrl, string title, IEnumerable<(double lon, double lat)> lines)
  1509. {
  1510. string identify = "DrawPoint_";
  1511. if (lines == null || !lines.Any()) return;
  1512. var innerData = ctrl.Tag as InnerData;
  1513. List<MapDot> list = new List<MapDot>();
  1514. var color = ColorHelper.GetColor(title);
  1515. for (int i = 0; i < lines.Count(); i++)
  1516. {
  1517. var p = lines.ElementAt(i);
  1518. if (p.lon < -180 || p.lon > 180) continue;
  1519. if (p.lon == 0 && p.lon == 0) continue;
  1520. var mapItem = new MapDot()
  1521. {
  1522. EnableHighlighting = DefaultBoolean.True,
  1523. EnableSelection = DefaultBoolean.False,
  1524. CanMove = false,
  1525. Visible = true,
  1526. IsHitTestVisible = true,
  1527. Fill = color,
  1528. Size = 4,
  1529. Tag = $"{identify}{title}{lines.ElementAt(i).lon}",
  1530. Location = new GeoPoint(p.lat, p.lon),
  1531. ToolTipPattern = $"{title}",
  1532. };
  1533. list.Add(mapItem);
  1534. }
  1535. if (!list.Any()) return;
  1536. innerData.mMapStorage.Items.AddRange(list);
  1537. }
  1538. public static void DrawGdopLine(this MapControl ctrl, IEnumerable<(string wcKm, double lon, double lat)> lines)
  1539. {
  1540. if (lines == null || !lines.Any()) return;
  1541. var innerData = ctrl.Tag as InnerData;
  1542. var wcKm = lines.First().wcKm;
  1543. var polyLine = new MapPolyline()
  1544. {
  1545. Stroke = ColorHelper.GetColor(wcKm),
  1546. StrokeWidth = 2,
  1547. IsGeodesic = true,
  1548. CanResize = false,
  1549. CanEdit = false,
  1550. CanRotate = false,
  1551. IsHitTestVisible = true,
  1552. CanMove = false,
  1553. Tag = $"DrawGdopLine_{wcKm}",
  1554. };
  1555. polyLine.TitleOptions.Pattern = wcKm;
  1556. foreach (var item in lines)
  1557. {
  1558. if (double.IsNaN(item.lat) || double.IsNaN(item.lon)) continue;
  1559. polyLine.Points.Add(new GeoPoint(item.lat, item.lon));
  1560. }
  1561. if (!polyLine.Points.Any()) return;
  1562. innerData.mMapStorage.Items.Add(polyLine);
  1563. }
  1564. /// <summary>
  1565. /// 绘制线
  1566. /// </summary>
  1567. /// <param name="ctrl"></param>
  1568. /// <param name="title"></param>
  1569. /// <param name="lines"></param>
  1570. /// <param name="isClear">是否清除上次绘制</param>
  1571. public static void DrawCXLine(this MapControl ctrl, string title, IEnumerable<(double lon, double lat)> lines, bool isClear = true)
  1572. {
  1573. string identify = "DrawCXLine_";
  1574. if (lines == null || !lines.Any()) return;
  1575. var innerData = ctrl.Tag as InnerData;
  1576. if (isClear)
  1577. {
  1578. var mapItem = innerData.mMapStorage.Items.Find(m => m.Tag.ToString().StartsWith(identify));
  1579. if (mapItem != null)
  1580. {
  1581. innerData.mMapStorage.Items.Remove(mapItem);
  1582. }
  1583. }
  1584. var polyLine = new MapPolyline()
  1585. {
  1586. Stroke = Color.Red,
  1587. StrokeWidth = 3,
  1588. CanMove = false,
  1589. Visible = true,
  1590. IsHitTestVisible = true,
  1591. Tag = $"{identify}{title}",
  1592. ToolTipPattern = title,
  1593. };
  1594. foreach (var item in lines)
  1595. {
  1596. if (double.IsNaN(item.lat) || double.IsNaN(item.lon)) continue;
  1597. polyLine.Points.Add(new GeoPoint(item.lat, item.lon));
  1598. }
  1599. if (!polyLine.Points.Any()) return;
  1600. innerData.mMapStorage.Items.Add(polyLine);
  1601. }
  1602. public static void DrawErrEllipse(this MapControl ctrl, double r1, double r2, IEnumerable<(double lon, double lat)> lines)
  1603. {
  1604. if (lines == null || !lines.Any()) return;
  1605. var innerData = ctrl.Tag as InnerData;
  1606. //innerData.mMapStorage.Items.Clear();
  1607. var polyLine = new MapPolyline()
  1608. {
  1609. Stroke = Color.Red,
  1610. StrokeWidth = 4,
  1611. IsGeodesic = true,
  1612. CanResize = false,
  1613. CanEdit = false,
  1614. CanRotate = false,
  1615. IsHitTestVisible = true,
  1616. CanMove = false,
  1617. Tag = $"DrawErrEllipse",
  1618. };
  1619. //polyLine.ToolTipPattern = $"长轴:{r1:f1}km\r\n短轴:{r2:f1}km";
  1620. foreach (var item in lines)
  1621. {
  1622. if (double.IsNaN(item.lat) || double.IsNaN(item.lon)) continue;
  1623. polyLine.Points.Add(new GeoPoint(item.lat, item.lon));
  1624. }
  1625. if (!polyLine.Points.Any()) return;
  1626. innerData.mMapStorage.Items.Add(polyLine);
  1627. var callout = new DevExpress.XtraMap.MapCallout()
  1628. {
  1629. Text = $"R1={r1:f1}km\r\nR2={r2:f1}km",
  1630. Location = polyLine.Points.First(),
  1631. CanMove = false,
  1632. IsHitTestVisible = false,
  1633. };
  1634. innerData.mMapStorage.Items.Add(callout);
  1635. }
  1636. /// <summary>
  1637. /// 绘制GDOP多条线 两个点绘制一个线段 1和2一个线段 3和4一个线段
  1638. /// </summary>
  1639. /// <param name="ctrl"></param>
  1640. /// <param name="wcKm"></param>
  1641. /// <param name="dots"></param>
  1642. /// <param name="patterncount"></param>
  1643. public static void DrawGdopLineTwo(this MapControl ctrl, string wcKm, IEnumerable<(double lon, double lat)> dots, int patterncount)
  1644. {
  1645. if (dots == null || !dots.Any()) return;
  1646. string identify = "DrawGdopLine_";
  1647. var innerData = ctrl.Tag as InnerData;
  1648. //多条线 两个点绘制一个线段 1和2一个线段 3和4一个线段
  1649. List<MapPolyline> polylines = new List<MapPolyline>();
  1650. int index = 0;
  1651. int count = dots.Count();
  1652. MapPolyline polyLine = null;
  1653. foreach (var item in dots)
  1654. {
  1655. if (index % 2 == 0)
  1656. {
  1657. if (polyLine != null)//添加线段
  1658. {
  1659. polylines.Add(polyLine);
  1660. }
  1661. polyLine = new MapPolyline()
  1662. {
  1663. Stroke = ColorHelper.GetColor(wcKm),
  1664. StrokeWidth = 2,
  1665. IsGeodesic = true,
  1666. CanResize = false,
  1667. CanEdit = false,
  1668. CanRotate = false,
  1669. IsHitTestVisible = true,
  1670. CanMove = false,
  1671. Tag = $"{identify}{wcKm}",
  1672. };
  1673. }
  1674. polyLine.Points.Add(new GeoPoint(item.lat, item.lon));
  1675. if (patterncount == index)//提示公里信息
  1676. {
  1677. polyLine.TitleOptions.Pattern = wcKm;
  1678. }
  1679. index++;
  1680. if (index == count)//添加最后一个线段
  1681. {
  1682. polylines.Add(polyLine);
  1683. }
  1684. }
  1685. if (!polyLine.Points.Any()) return;
  1686. innerData.mMapStorage.Items.AddRange(polylines);
  1687. }
  1688. /// <summary>
  1689. /// 绘制半径圆
  1690. /// </summary>
  1691. /// <param name="ctrl"></param>
  1692. /// <param name="lat"></param>
  1693. /// <param name="lon"></param>
  1694. /// <param name="radius"></param>
  1695. public static void DrawRadiusRound(this MapControl ctrl, double lat, double lon, int radius)
  1696. {
  1697. var innerData = ctrl.Tag as InnerData;
  1698. try
  1699. {
  1700. if (radius <= 0)
  1701. return;
  1702. CoordPointCollection latLngs = new CoordPointCollection();
  1703. MyLatLng centerLatLng = new MyLatLng(lon, lat);
  1704. // 0 - 360度 寻找半径为radius,圆心为centerP的圆上点的经纬度
  1705. for (int i = 0; i < 360; i++)
  1706. {
  1707. //获取目标经纬度
  1708. MyLatLng tempLatLng = getMyLatLng(centerLatLng, radius, i);
  1709. //将自定义的经纬度类 转换成 标准经纬度类
  1710. CoordPoint p = new GeoPoint(tempLatLng.m_Latitude, tempLatLng.m_Longitude);
  1711. latLngs.Add(p);
  1712. }
  1713. //安全性检查
  1714. if (latLngs.Count < 20)
  1715. {
  1716. return;
  1717. }
  1718. //通过绘制多边形的方式绘制圆
  1719. MapPolygon gpol = new MapPolygon();
  1720. gpol.Points = latLngs;
  1721. gpol.Stroke = Color.Red;
  1722. gpol.Fill = Color.FromArgb(50, Color.Red);
  1723. gpol.IsHitTestVisible = true;
  1724. innerData.mMapStorageFixed.Items.Add(gpol);
  1725. }
  1726. catch (Exception ex)
  1727. {
  1728. //Dialog.Error(ex);
  1729. }
  1730. }
  1731. /// <summary>
  1732. /// 度 转换成 弧度
  1733. /// </summary>
  1734. /// <param name="degrees"></param>
  1735. /// <returns></returns>
  1736. public static double DegreesToRadians(double degrees)
  1737. {
  1738. const double degToRadFactor = Math.PI / 180;
  1739. return degrees * degToRadFactor;
  1740. }
  1741. /// <summary>
  1742. /// 计算两个点之间的距离
  1743. /// </summary>
  1744. /// <param name="startlon">开始经度</param>
  1745. /// <param name="startlat">开始纬度</param>
  1746. /// <param name="endlon">结束经度</param>
  1747. /// <param name="endlat">结束纬度</param>
  1748. /// <returns></returns>
  1749. public static double CalcLineKm(double startlon, double startlat, double endlon, double endlat)
  1750. {
  1751. GeoPoint startPoint = new GeoPoint() { Longitude = startlon, Latitude = startlat };
  1752. GeoPoint endPoint = new GeoPoint() { Longitude = endlon, Latitude = endlat };
  1753. double result = 0;
  1754. MapSize sizeInKm = new SphericalMercatorProjection().GeoToKilometersSize(startPoint, new MapSize(Math.Abs(startPoint.Longitude - endPoint.Longitude), Math.Abs(startPoint.Latitude - endPoint.Latitude)));
  1755. result = Math.Sqrt(sizeInKm.Width * sizeInKm.Width + sizeInKm.Height * sizeInKm.Height);
  1756. return result;
  1757. }
  1758. /// <summary>
  1759. /// 计算方向线坐标
  1760. /// </summary>
  1761. /// <param name="lon">经度</param>
  1762. /// <param name="lat">纬度</param>
  1763. /// <param name="deg"> 艏向角 角度制</param>
  1764. /// <param name="dis">长度 m</param>
  1765. /// <returns></returns>
  1766. public static (double, double) CalcSituation(double lon, double lat, double deg, double dis)
  1767. {
  1768. double arc = 6371.393 * 1000; //地球平均半径
  1769. double rad = deg * (Math.PI / 180); //角度转弧度
  1770. double c_lng = lon + dis * Math.Sin(rad) / (arc * Math.Cos(lat) * 2 * Math.PI / 360);
  1771. double c_lat = lat + dis * Math.Cos(rad) / (arc * 2 * Math.PI / 360);
  1772. return (c_lng, c_lat); //方向上的另一点坐标
  1773. }
  1774. /**
  1775. * 求B点经纬度
  1776. * @param A 已知点的经纬度,
  1777. * @param distance AB两地的距离 单位km
  1778. * @param angle AB连线与正北方向的夹角(0~360)
  1779. * @return B点的经纬度
  1780. */
  1781. private static MyLatLng getMyLatLng(MyLatLng A, double distance, double angle)
  1782. {
  1783. double dx = distance * 1000 * Math.Sin(DegreesToRadians(angle));
  1784. double dy = distance * 1000 * Math.Cos(DegreesToRadians(angle));
  1785. double bjd = (dx / A.Ed + A.m_RadLo) * 180 / Math.PI;
  1786. double bwd = (dy / A.Ec + A.m_RadLa) * 180 / Math.PI;
  1787. return new MyLatLng(bjd, bwd);
  1788. }
  1789. public static void ClearRect(this MapControl ctrl)
  1790. {
  1791. var innerDate = ctrl.Tag as InnerData;
  1792. if (innerDate.rangeItem != null)
  1793. innerDate.mMapStorage.Items.Remove(innerDate.rangeItem);
  1794. if (innerDate.dotItem != null)
  1795. innerDate.mMapStorage.Items.Remove(innerDate.dotItem);
  1796. }
  1797. /// <summary>
  1798. /// 获取地图框选的范围信息(可能为null)
  1799. /// </summary>
  1800. /// <param name="ctrl"></param>
  1801. /// <returns></returns>
  1802. public static (double starLon, double startLat, double centerLon, double centerLat,
  1803. double endLon, double endLat, double lonRange, double latRange) GetCurrentRect(this MapControl ctrl)
  1804. {
  1805. var innerData = ctrl.Tag as InnerData;
  1806. return innerData.CurrentRect;
  1807. }
  1808. /// <summary>
  1809. /// 获取地图瓦片图层
  1810. /// </summary>
  1811. /// <param name="ctrl"></param>
  1812. /// <returns></returns>
  1813. public static ImageLayer GetImageLayer(this MapControl ctrl)
  1814. {
  1815. if (ctrl.Layers == null) return null;
  1816. return (ImageLayer)ctrl.Layers["ImageTileLayer"];
  1817. }
  1818. /// <summary>
  1819. /// 获取地图绘制图层
  1820. /// </summary>
  1821. /// <param name="ctrl"></param>
  1822. /// <returns></returns>
  1823. public static VectorItemsLayer GetDrawLayer(this MapControl ctrl)
  1824. {
  1825. return (VectorItemsLayer)ctrl.Layers["DrawLayer"];
  1826. }
  1827. /// <summary>
  1828. /// 获取地图绘制图层
  1829. /// </summary>
  1830. /// <param name="ctrl"></param>
  1831. /// <returns></returns>
  1832. public static VectorItemsLayer GetPosLayer(this MapControl ctrl)
  1833. {
  1834. return (VectorItemsLayer)ctrl.Layers["PosLayer"];
  1835. }
  1836. /// <summary>
  1837. /// 获取地图绘制图层的数据仓库
  1838. /// </summary>
  1839. /// <param name="ctrl"></param>
  1840. /// <returns></returns>
  1841. public static MapItemStorage GetDrawStorage(this MapControl ctrl)
  1842. {
  1843. var innerData = ctrl.Tag as InnerData;
  1844. return innerData.mMapStorage;
  1845. }
  1846. /// <summary>
  1847. /// 设置地图类型.默认为Normal
  1848. /// 该方法为所有MapControl实例设置地图类型
  1849. /// </summary>
  1850. /// <param name="ctrl"></param>
  1851. /// <param name="mapType"></param>
  1852. public static void SetMapType(GoogleMapType mapType)
  1853. {
  1854. mMapType = mapType;
  1855. listMapCtrl.ForEach(t =>
  1856. {
  1857. if (t.GetImageLayer() == null) return;
  1858. var provider = t.GetImageLayer().DataProvider as MapTileDataProviderBase;
  1859. provider?.ClearCache();
  1860. t.Refresh();
  1861. });
  1862. }
  1863. #region private
  1864. private static void DrawRect_MouseMove(object sender, MouseEventArgs e)
  1865. {
  1866. var innerData = (sender as MapControl).Tag as InnerData;
  1867. if (!innerData.drawingRect) return;
  1868. innerData.dotItem.Location = innerData.rangeItem.GetCenter();
  1869. var startLon = Math.Round(innerData.rangeItem.Location.GetX(), 3);
  1870. var startLat = Math.Round(innerData.rangeItem.Location.GetY(), 3);
  1871. if (startLon >= 180)
  1872. {
  1873. startLon -= 360;
  1874. }
  1875. if (startLon <= -180)
  1876. {
  1877. startLon += 360;
  1878. }
  1879. var center = innerData.rangeItem.GetCenter();
  1880. var centerLon = Math.Round(center.GetX(), 3);
  1881. if (centerLon >= 180)
  1882. {
  1883. centerLon -= 360;
  1884. }
  1885. if (centerLon <= -180)
  1886. {
  1887. centerLon += 360;
  1888. }
  1889. var centerLat = Math.Round(center.GetY(), 3);
  1890. double endLon;
  1891. if (centerLon < 0 && startLon > 0)
  1892. endLon = startLon + 2 * (centerLon + 360 - startLon);
  1893. else
  1894. endLon = startLon + 2 * (centerLon - startLon);
  1895. var endLat = startLat + 2 * (centerLat - startLat);
  1896. var StartLon = Math.Min(startLon, endLon);
  1897. var StartLat = Math.Min(startLat, endLat);
  1898. var CenterLon = centerLon;
  1899. var CenterLat = centerLat;
  1900. var EndLon = Math.Max(startLon, endLon);
  1901. var EndLat = Math.Max(startLat, endLat);
  1902. double centerLonNew = CenterLon % 360;
  1903. CenterLon = centerLonNew;
  1904. //double LonRange = Math.Round((EndLon - StartLon) / 2, 3);
  1905. //double LatRange = Math.Round((EndLat - StartLat) / 2, 3);
  1906. double LonRange = Math.Round((EndLon - StartLon), 3);
  1907. double LatRange = Math.Round((EndLat - StartLat), 3);
  1908. if (LonRange >= 360)
  1909. {
  1910. }
  1911. innerData.CurrentRect = (StartLon, StartLat, CenterLon, CenterLat, EndLon, EndLat, LonRange, LatRange);
  1912. innerData.mOnRectChanged?.Invoke(innerData.CurrentRect);
  1913. }
  1914. private static void ExportImg_ItemClick(object sender, ItemClickEventArgs e)
  1915. {
  1916. var ctrl = e.Item.Tag as MapControl;
  1917. using (var dialog = new SaveFileDialog())
  1918. {
  1919. dialog.Filter = "PNG图片|*.png";
  1920. dialog.AddExtension = true;
  1921. dialog.FileName = $"Map{DateTime.Now:yyyyMMddHHmmss}.png";
  1922. if (dialog.ShowDialog() == DialogResult.OK)
  1923. {
  1924. ctrl.ExportToImage(dialog.FileName, ImageFormat.Png);
  1925. }
  1926. }
  1927. }
  1928. private static void ExportCsv_ItemClick(object sender, ItemClickEventArgs e)
  1929. {
  1930. var ctrl = e.Item.Tag as MapControl;
  1931. using (var dialog = new SaveFileDialog())
  1932. {
  1933. dialog.Filter = "CSV文件|*.csv";
  1934. dialog.AddExtension = true;
  1935. dialog.FileName = $"Pos{DateTime.Now:yyyyMMddHHmmss}.xlsx";
  1936. if (dialog.ShowDialog() == DialogResult.OK)
  1937. {
  1938. ctrl.ExportToXlsx(dialog.FileName);
  1939. }
  1940. }
  1941. }
  1942. private static void ClearDrawObj(this MapControl ctrl)
  1943. {
  1944. ctrl.Invoke(new Action(() =>
  1945. {
  1946. try
  1947. {
  1948. var innerData = ctrl.Tag as InnerData;
  1949. ctrl.MapEditor.SetTransformMode(MapItemTransform.None);
  1950. innerData.drawingRect = false;
  1951. innerData.CurrentRect = (0, 0, 0, 0, 0, 0, 0, 0);
  1952. innerData.rangeItem = null;
  1953. if (innerData.mMapStorage != null && innerData.mMapStorage.Items.Any())
  1954. {
  1955. innerData.mMapStorage.Items.Clear();
  1956. innerData._flightCache.Clear();
  1957. }
  1958. }
  1959. catch (Exception ex)
  1960. {
  1961. }
  1962. }));
  1963. }
  1964. private static void DistanceLine_ItemClick(object sender, ItemClickEventArgs e)
  1965. {
  1966. var ctrl = e.Item.Tag as MapControl;
  1967. var innerData = ctrl.Tag as InnerData;
  1968. ctrl.MapEditor.SetEditMode();
  1969. var items = innerData.mMapStorage.Items.ToArray();
  1970. foreach (var item in items)
  1971. {
  1972. if (item.Tag != null && item.Tag.ToString() == "DrawDistanceLine")
  1973. innerData.mMapStorage.Items.Remove(item);
  1974. }
  1975. if (innerData.distinctPath != null)
  1976. {
  1977. innerData.distinctPath.Points.Clear();
  1978. }
  1979. innerData.distinctPath = new MapPolyline()
  1980. {
  1981. Stroke = Color.FromArgb(127, 255, 0, 199),
  1982. StrokeWidth = 2,
  1983. IsGeodesic = true,
  1984. CanResize = false,
  1985. CanEdit = false,
  1986. CanRotate = false,
  1987. IsHitTestVisible = false,
  1988. CanMove = true,
  1989. Tag = "DrawDistanceLine"
  1990. };
  1991. innerData.mMapStorage.Items.Add(innerData.distinctPath);
  1992. innerData.hoverPoint = new MapDot() { CanResize = false, CanMove = false, IsHitTestVisible = false, Tag = "DrawDistanceLine", Size = 8 };
  1993. innerData.hoverPoint.Fill = ColorHelper.GetColor(innerData.hoverPoint.Tag.ToString());
  1994. innerData.mMapStorage.Items.Add(innerData.hoverPoint);
  1995. innerData.hoverTip = CreateHoverTip();
  1996. ctrl.MouseClick += AddDistinctPoint;
  1997. ctrl.MouseMove += MovingDistinct;
  1998. ctrl.MouseLeave += MapControl_MouseLeave;
  1999. ctrl.MouseEnter += MapControl_MouseEnter;
  2000. ctrl.DoubleClick += EndDistinct;
  2001. }
  2002. private static void MarkDot_ItemClick(object sender, ItemClickEventArgs e)
  2003. {
  2004. var ctrl = e.Item.Tag as MapControl;
  2005. ctrl.MapEditor.SetTransformMode(MapItemTransform.None);
  2006. var innerData = ctrl.Tag as InnerData;
  2007. innerData.drawingRect = false;
  2008. using (var frm = new MapEditPointView())
  2009. {
  2010. if (frm.ShowDialog() != DialogResult.OK) return;
  2011. var locPoint = new GeoPoint(frm.Lat, frm.Lon);
  2012. MapCustomElement cusItem = new MapCustomElement()
  2013. {
  2014. Location = locPoint,
  2015. UseAnimation = true,
  2016. CanMove = false,
  2017. EnableHighlighting = DefaultBoolean.True,
  2018. EnableSelection = DefaultBoolean.False,
  2019. Text = "",
  2020. ToolTipPattern = $"{frm.Caption}",
  2021. SvgImage = SvgHelper.CreatePentagram(),
  2022. SvgImageSize = new Size(32, 32),
  2023. TextAlignment = DevExpress.XtraMap.TextAlignment.BottomCenter,
  2024. Tag = "DrawMarkDot"
  2025. };
  2026. innerData.mMapStorage.Items.Add(cusItem);
  2027. }
  2028. }
  2029. private static ToolTipControllerShowEventArgs CreateHoverTip()
  2030. {
  2031. ToolTipTitleItem titleItem1 = new ToolTipTitleItem() { Text = $"0千米" };
  2032. titleItem1.Appearance.ForeColor = SystemColors.GrayText;
  2033. titleItem1.Appearance.Font = new Font(AppearanceObject.DefaultFont.FontFamily, 12, FontStyle.Bold);
  2034. SuperToolTip superToolTip = new SuperToolTip();
  2035. superToolTip.Items.Add(titleItem1);
  2036. ToolTipSeparatorItem sepItem = new ToolTipSeparatorItem();
  2037. superToolTip.Items.Add(sepItem);
  2038. ToolTipItem textItem = new ToolTipItem() { Text = "单击添加测距点,双击结束测距" };
  2039. superToolTip.Items.Add(textItem);
  2040. ToolTipControllerShowEventArgs arg = new ToolTipControllerShowEventArgs();
  2041. arg.ShowBeak = true;
  2042. arg.SuperTip = superToolTip;
  2043. return arg;
  2044. }
  2045. private static void MapControl_MouseEnter(object sender, EventArgs e)
  2046. {
  2047. var innerData = (sender as MapControl).Tag as InnerData;
  2048. innerData.hoverPoint.Visible = true;
  2049. }
  2050. private static void MapControl_MouseLeave(object sender, EventArgs e)
  2051. {
  2052. var innerData = (sender as MapControl).Tag as InnerData;
  2053. innerData.hoverPoint.Visible = false;
  2054. }
  2055. private static void AddDistinctPoint(object sender, MouseEventArgs e)
  2056. {
  2057. var innerData = (sender as MapControl).Tag as InnerData;
  2058. var ctrl = sender as MapControl;
  2059. MapCallout disItem = new MapCallout { IsHitTestVisible = false, CanMove = false };
  2060. disItem.Location = ctrl.ScreenPointToCoordPoint(e.Location);
  2061. disItem.Text = $"{CalcLineKm(innerData):F2}千米";
  2062. disItem.Tag = "DrawDistanceLine";
  2063. innerData.mMapStorage.Items.Add(disItem);
  2064. innerData.distinctPath.Points.Add(innerData.hoverPoint.Location);
  2065. innerData.hoverPoint = new MapDot() { CanResize = false, CanMove = false, IsHitTestVisible = false, Tag = "DrawDistanceLine", Size = 8 };
  2066. innerData.hoverPoint.Location = ctrl.ScreenPointToCoordPoint(e.Location);
  2067. innerData.hoverPoint.Fill = ColorHelper.GetColor(innerData.hoverPoint.Tag.ToString());
  2068. innerData.mMapStorage.Items.Add(innerData.hoverPoint);
  2069. innerData.distinctPath.Points.Add(innerData.hoverPoint.Location);
  2070. }
  2071. private static void MovingDistinct(object sender, MouseEventArgs e)
  2072. {
  2073. var innerData = (sender as MapControl).Tag as InnerData;
  2074. var ctrl = sender as MapControl;
  2075. var itemPoint = ctrl.ScreenPointToCoordPoint(e.Location);
  2076. innerData.hoverPoint.Location = itemPoint;
  2077. if (innerData.distinctPath != null && innerData.distinctPath.Points.Count > 0)
  2078. {
  2079. ctrl.MapEditor.SetEditMode();
  2080. innerData.distinctPath.Points[innerData.distinctPath.Points.Count - 1] = itemPoint;
  2081. (innerData.hoverTip.SuperTip.Items[0] as ToolTipTitleItem).Text = $"{CalcLineKm(innerData):F2}千米";
  2082. innerData.mapToolTip.ShowHint(innerData.hoverTip, ctrl.PointToScreen(e.Location));
  2083. }
  2084. if (innerData.flightpath != null && innerData.flightpath.Points.Count > 0)
  2085. {
  2086. ctrl.MapEditor.SetEditMode();
  2087. innerData.mapToolTip.ShowHint(innerData.hoverTip, ctrl.PointToScreen(e.Location));
  2088. }
  2089. }
  2090. private static double CalcLineKm(InnerData data)
  2091. {
  2092. double result = 0;
  2093. if (data.distinctPath.Points.Count < 2) return result;
  2094. for (int i = 0; i < data.distinctPath.Points.Count - 1; i++)
  2095. {
  2096. var startPoint = data.distinctPath.Points[i] as GeoPoint;
  2097. var endPoint = data.distinctPath.Points[i + 1] as GeoPoint;
  2098. MapSize sizeInKm = new SphericalMercatorProjection().GeoToKilometersSize(startPoint, new MapSize(Math.Abs(startPoint.Longitude - endPoint.Longitude), Math.Abs(startPoint.Latitude - endPoint.Latitude)));
  2099. double partlength = Math.Sqrt(sizeInKm.Width * sizeInKm.Width + sizeInKm.Height * sizeInKm.Height);
  2100. result += partlength;
  2101. }
  2102. return result;
  2103. }
  2104. public static void ClearMap(this MapControl ctrl)
  2105. {
  2106. var innerData = ctrl.Tag as InnerData;
  2107. innerData.CurrentRect = (0, 0, 0, 0, 0, 0, 0, 0);
  2108. innerData.mMapStorage?.Items.Clear();
  2109. }
  2110. private static void EndDistinct(object sender, EventArgs e)
  2111. {
  2112. var ctrl = sender as MapControl;
  2113. var innerData = ctrl.Tag as InnerData;
  2114. innerData.mapToolTip.HideHint();
  2115. ctrl.MouseClick -= AddDistinctPoint;
  2116. ctrl.MouseMove -= MovingDistinct;
  2117. ctrl.DoubleClick -= EndDistinct;
  2118. ctrl.MouseLeave -= MapControl_MouseLeave;
  2119. ctrl.MouseEnter -= MapControl_MouseEnter;
  2120. }
  2121. class MapEditPointView : DevExpress.XtraEditors.XtraForm
  2122. {
  2123. private System.ComponentModel.IContainer components = null;
  2124. private DevExpress.XtraLayout.LayoutControl layoutControl1;
  2125. private DevExpress.XtraLayout.LayoutControlGroup Root;
  2126. private DevExpress.XtraLayout.LayoutControlItem layoutControlItem1;
  2127. private DevExpress.XtraLayout.EmptySpaceItem emptySpaceItem1;
  2128. private DevExpress.XtraLayout.LayoutControlItem layoutControlItem2;
  2129. private DevExpress.XtraEditors.ButtonEdit txtLon;
  2130. private DevExpress.XtraEditors.ButtonEdit txtLat;
  2131. private DevExpress.XtraEditors.TextEdit txtCaption;
  2132. private DevExpress.XtraLayout.LayoutControlItem layoutControlItem5;
  2133. private DevExpress.XtraEditors.SimpleButton btnCancel;
  2134. private DevExpress.XtraEditors.SimpleButton btnOk;
  2135. private DevExpress.XtraLayout.LayoutControlItem layoutControlItem3;
  2136. private DevExpress.XtraLayout.LayoutControlItem layoutControlItem6;
  2137. private DevExpress.XtraEditors.DXErrorProvider.DXErrorProvider dxErrorProvider1;
  2138. private DevExpress.XtraLayout.EmptySpaceItem emptySpaceItem2;
  2139. private void InitializeComponent()
  2140. {
  2141. this.components = new System.ComponentModel.Container();
  2142. DevExpress.XtraEditors.Controls.EditorButtonImageOptions editorButtonImageOptions1 = new DevExpress.XtraEditors.Controls.EditorButtonImageOptions();
  2143. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject1 = new DevExpress.Utils.SerializableAppearanceObject();
  2144. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject2 = new DevExpress.Utils.SerializableAppearanceObject();
  2145. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject3 = new DevExpress.Utils.SerializableAppearanceObject();
  2146. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject4 = new DevExpress.Utils.SerializableAppearanceObject();
  2147. DevExpress.XtraEditors.Controls.EditorButtonImageOptions editorButtonImageOptions2 = new DevExpress.XtraEditors.Controls.EditorButtonImageOptions();
  2148. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject5 = new DevExpress.Utils.SerializableAppearanceObject();
  2149. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject6 = new DevExpress.Utils.SerializableAppearanceObject();
  2150. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject7 = new DevExpress.Utils.SerializableAppearanceObject();
  2151. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject8 = new DevExpress.Utils.SerializableAppearanceObject();
  2152. this.layoutControl1 = new DevExpress.XtraLayout.LayoutControl();
  2153. this.txtCaption = new DevExpress.XtraEditors.TextEdit();
  2154. this.txtLon = new DevExpress.XtraEditors.ButtonEdit();
  2155. this.txtLat = new DevExpress.XtraEditors.ButtonEdit();
  2156. this.Root = new DevExpress.XtraLayout.LayoutControlGroup();
  2157. this.layoutControlItem1 = new DevExpress.XtraLayout.LayoutControlItem();
  2158. this.emptySpaceItem1 = new DevExpress.XtraLayout.EmptySpaceItem();
  2159. this.layoutControlItem2 = new DevExpress.XtraLayout.LayoutControlItem();
  2160. this.layoutControlItem5 = new DevExpress.XtraLayout.LayoutControlItem();
  2161. this.btnOk = new DevExpress.XtraEditors.SimpleButton();
  2162. this.layoutControlItem3 = new DevExpress.XtraLayout.LayoutControlItem();
  2163. this.btnCancel = new DevExpress.XtraEditors.SimpleButton();
  2164. this.layoutControlItem6 = new DevExpress.XtraLayout.LayoutControlItem();
  2165. this.dxErrorProvider1 = new DevExpress.XtraEditors.DXErrorProvider.DXErrorProvider(this.components);
  2166. this.emptySpaceItem2 = new DevExpress.XtraLayout.EmptySpaceItem();
  2167. ((System.ComponentModel.ISupportInitialize)(this.layoutControl1)).BeginInit();
  2168. this.layoutControl1.SuspendLayout();
  2169. ((System.ComponentModel.ISupportInitialize)(this.txtCaption.Properties)).BeginInit();
  2170. ((System.ComponentModel.ISupportInitialize)(this.txtLon.Properties)).BeginInit();
  2171. ((System.ComponentModel.ISupportInitialize)(this.txtLat.Properties)).BeginInit();
  2172. ((System.ComponentModel.ISupportInitialize)(this.Root)).BeginInit();
  2173. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem1)).BeginInit();
  2174. ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem1)).BeginInit();
  2175. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem2)).BeginInit();
  2176. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem5)).BeginInit();
  2177. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem3)).BeginInit();
  2178. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem6)).BeginInit();
  2179. ((System.ComponentModel.ISupportInitialize)(this.dxErrorProvider1)).BeginInit();
  2180. ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem2)).BeginInit();
  2181. this.SuspendLayout();
  2182. //
  2183. // layoutControl1
  2184. //
  2185. this.layoutControl1.Controls.Add(this.btnCancel);
  2186. this.layoutControl1.Controls.Add(this.btnOk);
  2187. this.layoutControl1.Controls.Add(this.txtCaption);
  2188. this.layoutControl1.Controls.Add(this.txtLon);
  2189. this.layoutControl1.Controls.Add(this.txtLat);
  2190. this.layoutControl1.Dock = System.Windows.Forms.DockStyle.Fill;
  2191. this.layoutControl1.Location = new System.Drawing.Point(0, 0);
  2192. this.layoutControl1.Name = "layoutControl1";
  2193. this.layoutControl1.OptionsCustomizationForm.DesignTimeCustomizationFormPositionAndSize = new System.Drawing.Rectangle(689, 0, 650, 400);
  2194. this.layoutControl1.Root = this.Root;
  2195. this.layoutControl1.Size = new System.Drawing.Size(272, 208);
  2196. this.layoutControl1.TabIndex = 0;
  2197. this.layoutControl1.Text = "layoutControl1";
  2198. //
  2199. // txtCaption
  2200. //
  2201. this.txtCaption.Location = new System.Drawing.Point(12, 29);
  2202. this.txtCaption.Name = "txtCaption";
  2203. this.txtCaption.Properties.Appearance.Options.UseTextOptions = true;
  2204. this.txtCaption.Properties.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
  2205. this.txtCaption.Properties.AutoHeight = false;
  2206. this.txtCaption.Properties.MaxLength = 30;
  2207. this.txtCaption.Size = new System.Drawing.Size(248, 22);
  2208. this.txtCaption.StyleController = this.layoutControl1;
  2209. this.txtCaption.TabIndex = 9;
  2210. //
  2211. // txtLon
  2212. //
  2213. this.txtLon.Location = new System.Drawing.Point(12, 80);
  2214. this.txtLon.Name = "txtLon";
  2215. this.txtLon.Properties.Appearance.Options.UseTextOptions = true;
  2216. this.txtLon.Properties.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
  2217. this.txtLon.Properties.AutoHeight = false;
  2218. this.txtLon.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
  2219. new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph, "°", -1, false, true, false, editorButtonImageOptions1, new DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None), serializableAppearanceObject1, serializableAppearanceObject2, serializableAppearanceObject3, serializableAppearanceObject4, "", null, null, DevExpress.Utils.ToolTipAnchor.Default)});
  2220. this.txtLon.Size = new System.Drawing.Size(248, 22);
  2221. this.txtLon.StyleController = this.layoutControl1;
  2222. this.txtLon.TabIndex = 4;
  2223. //
  2224. // txtLat
  2225. //
  2226. this.txtLat.Location = new System.Drawing.Point(12, 131);
  2227. this.txtLat.Name = "txtLat";
  2228. this.txtLat.Properties.Appearance.Options.UseTextOptions = true;
  2229. this.txtLat.Properties.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
  2230. this.txtLat.Properties.AutoHeight = false;
  2231. this.txtLat.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
  2232. new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph, "°", -1, false, true, false, editorButtonImageOptions2, new DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None), serializableAppearanceObject5, serializableAppearanceObject6, serializableAppearanceObject7, serializableAppearanceObject8, "", null, null, DevExpress.Utils.ToolTipAnchor.Default)});
  2233. this.txtLat.Size = new System.Drawing.Size(248, 22);
  2234. this.txtLat.StyleController = this.layoutControl1;
  2235. this.txtLat.TabIndex = 5;
  2236. //
  2237. // Root
  2238. //
  2239. this.Root.EnableIndentsWithoutBorders = DevExpress.Utils.DefaultBoolean.True;
  2240. this.Root.GroupBordersVisible = false;
  2241. this.Root.Items.AddRange(new DevExpress.XtraLayout.BaseLayoutItem[] {
  2242. this.layoutControlItem1,
  2243. this.emptySpaceItem1,
  2244. this.layoutControlItem5,
  2245. this.layoutControlItem2,
  2246. this.layoutControlItem3,
  2247. this.layoutControlItem6,
  2248. this.emptySpaceItem2});
  2249. this.Root.Name = "Root";
  2250. this.Root.Size = new System.Drawing.Size(272, 208);
  2251. this.Root.TextVisible = false;
  2252. //
  2253. // layoutControlItem1
  2254. //
  2255. this.layoutControlItem1.Control = this.txtLon;
  2256. this.layoutControlItem1.Location = new System.Drawing.Point(0, 43);
  2257. this.layoutControlItem1.MaxSize = new System.Drawing.Size(0, 51);
  2258. this.layoutControlItem1.MinSize = new System.Drawing.Size(54, 51);
  2259. this.layoutControlItem1.Name = "layoutControlItem1";
  2260. this.layoutControlItem1.Padding = new DevExpress.XtraLayout.Utils.Padding(2, 2, 10, 2);
  2261. this.layoutControlItem1.Size = new System.Drawing.Size(252, 51);
  2262. this.layoutControlItem1.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2263. this.layoutControlItem1.Text = "经度";
  2264. this.layoutControlItem1.TextLocation = DevExpress.Utils.Locations.Top;
  2265. this.layoutControlItem1.TextSize = new System.Drawing.Size(24, 14);
  2266. //
  2267. // emptySpaceItem1
  2268. //
  2269. this.emptySpaceItem1.AllowHotTrack = false;
  2270. this.emptySpaceItem1.Location = new System.Drawing.Point(0, 162);
  2271. this.emptySpaceItem1.MaxSize = new System.Drawing.Size(0, 26);
  2272. this.emptySpaceItem1.MinSize = new System.Drawing.Size(104, 26);
  2273. this.emptySpaceItem1.Name = "emptySpaceItem1";
  2274. this.emptySpaceItem1.Size = new System.Drawing.Size(113, 26);
  2275. this.emptySpaceItem1.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2276. this.emptySpaceItem1.TextSize = new System.Drawing.Size(0, 0);
  2277. //
  2278. // layoutControlItem2
  2279. //
  2280. this.layoutControlItem2.Control = this.txtLat;
  2281. this.layoutControlItem2.Location = new System.Drawing.Point(0, 94);
  2282. this.layoutControlItem2.MaxSize = new System.Drawing.Size(0, 51);
  2283. this.layoutControlItem2.MinSize = new System.Drawing.Size(54, 51);
  2284. this.layoutControlItem2.Name = "layoutControlItem2";
  2285. this.layoutControlItem2.Padding = new DevExpress.XtraLayout.Utils.Padding(2, 2, 10, 2);
  2286. this.layoutControlItem2.Size = new System.Drawing.Size(252, 51);
  2287. this.layoutControlItem2.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2288. this.layoutControlItem2.Text = "纬度";
  2289. this.layoutControlItem2.TextLocation = DevExpress.Utils.Locations.Top;
  2290. this.layoutControlItem2.TextSize = new System.Drawing.Size(24, 14);
  2291. //
  2292. // layoutControlItem5
  2293. //
  2294. this.layoutControlItem5.Control = this.txtCaption;
  2295. this.layoutControlItem5.Location = new System.Drawing.Point(0, 0);
  2296. this.layoutControlItem5.MaxSize = new System.Drawing.Size(0, 43);
  2297. this.layoutControlItem5.MinSize = new System.Drawing.Size(54, 43);
  2298. this.layoutControlItem5.Name = "layoutControlItem5";
  2299. this.layoutControlItem5.Size = new System.Drawing.Size(252, 43);
  2300. this.layoutControlItem5.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2301. this.layoutControlItem5.Text = "标题";
  2302. this.layoutControlItem5.TextLocation = DevExpress.Utils.Locations.Top;
  2303. this.layoutControlItem5.TextSize = new System.Drawing.Size(24, 14);
  2304. //
  2305. // btnOk
  2306. //
  2307. this.btnOk.Location = new System.Drawing.Point(125, 174);
  2308. this.btnOk.Name = "btnOk";
  2309. this.btnOk.Size = new System.Drawing.Size(65, 22);
  2310. this.btnOk.StyleController = this.layoutControl1;
  2311. this.btnOk.TabIndex = 10;
  2312. this.btnOk.Text = "确定";
  2313. this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
  2314. //
  2315. // layoutControlItem3
  2316. //
  2317. this.layoutControlItem3.Control = this.btnOk;
  2318. this.layoutControlItem3.Location = new System.Drawing.Point(113, 162);
  2319. this.layoutControlItem3.MaxSize = new System.Drawing.Size(69, 26);
  2320. this.layoutControlItem3.MinSize = new System.Drawing.Size(69, 26);
  2321. this.layoutControlItem3.Name = "layoutControlItem3";
  2322. this.layoutControlItem3.Size = new System.Drawing.Size(69, 26);
  2323. this.layoutControlItem3.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2324. this.layoutControlItem3.TextSize = new System.Drawing.Size(0, 0);
  2325. this.layoutControlItem3.TextVisible = false;
  2326. //
  2327. // btnCancel
  2328. //
  2329. this.btnCancel.Location = new System.Drawing.Point(194, 174);
  2330. this.btnCancel.Name = "btnCancel";
  2331. this.btnCancel.Size = new System.Drawing.Size(66, 22);
  2332. this.btnCancel.StyleController = this.layoutControl1;
  2333. this.btnCancel.TabIndex = 11;
  2334. this.btnCancel.Text = "取消";
  2335. this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
  2336. //
  2337. // layoutControlItem6
  2338. //
  2339. this.layoutControlItem6.Control = this.btnCancel;
  2340. this.layoutControlItem6.Location = new System.Drawing.Point(182, 162);
  2341. this.layoutControlItem6.MaxSize = new System.Drawing.Size(70, 26);
  2342. this.layoutControlItem6.MinSize = new System.Drawing.Size(70, 26);
  2343. this.layoutControlItem6.Name = "layoutControlItem6";
  2344. this.layoutControlItem6.Size = new System.Drawing.Size(70, 26);
  2345. this.layoutControlItem6.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2346. this.layoutControlItem6.TextSize = new System.Drawing.Size(0, 0);
  2347. this.layoutControlItem6.TextVisible = false;
  2348. //
  2349. // dxErrorProvider1
  2350. //
  2351. this.dxErrorProvider1.ContainerControl = this;
  2352. //
  2353. // emptySpaceItem2
  2354. //
  2355. this.emptySpaceItem2.AllowHotTrack = false;
  2356. this.emptySpaceItem2.Location = new System.Drawing.Point(0, 145);
  2357. this.emptySpaceItem2.MinSize = new System.Drawing.Size(104, 1);
  2358. this.emptySpaceItem2.Name = "emptySpaceItem2";
  2359. this.emptySpaceItem2.Size = new System.Drawing.Size(252, 17);
  2360. this.emptySpaceItem2.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2361. this.emptySpaceItem2.TextSize = new System.Drawing.Size(0, 0);
  2362. //
  2363. // MapEditPointView
  2364. //
  2365. this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
  2366. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  2367. this.ClientSize = new System.Drawing.Size(272, 208);
  2368. this.Controls.Add(this.layoutControl1);
  2369. this.IconOptions.ShowIcon = false;
  2370. this.MaximizeBox = false;
  2371. this.MinimizeBox = false;
  2372. this.Name = "MapEditPointView";
  2373. this.ShowInTaskbar = false;
  2374. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  2375. this.Text = "标点";
  2376. ((System.ComponentModel.ISupportInitialize)(this.layoutControl1)).EndInit();
  2377. this.layoutControl1.ResumeLayout(false);
  2378. ((System.ComponentModel.ISupportInitialize)(this.txtCaption.Properties)).EndInit();
  2379. ((System.ComponentModel.ISupportInitialize)(this.txtLon.Properties)).EndInit();
  2380. ((System.ComponentModel.ISupportInitialize)(this.txtLat.Properties)).EndInit();
  2381. ((System.ComponentModel.ISupportInitialize)(this.Root)).EndInit();
  2382. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem1)).EndInit();
  2383. ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem1)).EndInit();
  2384. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem2)).EndInit();
  2385. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem5)).EndInit();
  2386. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem3)).EndInit();
  2387. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem6)).EndInit();
  2388. ((System.ComponentModel.ISupportInitialize)(this.dxErrorProvider1)).EndInit();
  2389. ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem2)).EndInit();
  2390. this.ResumeLayout(false);
  2391. }
  2392. protected override void Dispose(bool disposing)
  2393. {
  2394. if (disposing && (components != null))
  2395. {
  2396. components.Dispose();
  2397. }
  2398. base.Dispose(disposing);
  2399. }
  2400. public MapEditPointView()
  2401. {
  2402. InitializeComponent();
  2403. }
  2404. public string Caption
  2405. {
  2406. get
  2407. {
  2408. return txtCaption.Text.Trim();
  2409. }
  2410. set
  2411. {
  2412. txtCaption.Text = value;
  2413. }
  2414. }
  2415. public double Lon
  2416. {
  2417. get
  2418. {
  2419. return double.Parse(txtLon.Text.Trim());
  2420. }
  2421. set
  2422. {
  2423. txtLon.Text = value.ToString();
  2424. }
  2425. }
  2426. public double Lat
  2427. {
  2428. get
  2429. {
  2430. return double.Parse(txtLat.Text.Trim());
  2431. }
  2432. set
  2433. {
  2434. txtLat.Text = value.ToString();
  2435. }
  2436. }
  2437. private void btnOk_Click(object sender, EventArgs e)
  2438. {
  2439. dxErrorProvider1.ClearErrors();
  2440. double lon, lat;
  2441. if (!double.TryParse(txtLon.Text, out lon))
  2442. {
  2443. dxErrorProvider1.SetError(txtLon, "请设置正确的经度");
  2444. return;
  2445. }
  2446. if (!double.TryParse(txtLat.Text, out lat))
  2447. {
  2448. dxErrorProvider1.SetError(txtLat, "请设置正确的纬度");
  2449. return;
  2450. }
  2451. if (lon < -180 || lon > 180)
  2452. {
  2453. dxErrorProvider1.SetError(txtLon, "经度范围[-180,180]");
  2454. return;
  2455. }
  2456. if (lat < -90 || lat > 90)
  2457. {
  2458. dxErrorProvider1.SetError(txtLat, "纬度范围[-90,90]");
  2459. return;
  2460. }
  2461. this.DialogResult = DialogResult.OK;
  2462. }
  2463. private void btnCancel_Click(object sender, EventArgs e)
  2464. {
  2465. this.DialogResult = DialogResult.Cancel;
  2466. }
  2467. }
  2468. #endregion
  2469. #region 航迹名称
  2470. class MapFlightLineView : DevExpress.XtraEditors.XtraUserControl
  2471. {
  2472. private System.ComponentModel.IContainer components = null;
  2473. private DevExpress.XtraLayout.LayoutControl layoutControl1;
  2474. private DevExpress.XtraLayout.LayoutControlGroup Root;
  2475. private DevExpress.XtraLayout.LayoutControlItem layoutControlItem1;
  2476. private DevExpress.XtraLayout.EmptySpaceItem emptySpaceItem1;
  2477. private DevExpress.XtraEditors.ButtonEdit txtSpeed;
  2478. private DevExpress.XtraEditors.TextEdit txtCaption;
  2479. private DevExpress.XtraLayout.LayoutControlItem layoutControlItem5;
  2480. private DevExpress.XtraEditors.SimpleButton btnCancel;
  2481. private DevExpress.XtraEditors.SimpleButton btnOk;
  2482. private DevExpress.XtraLayout.LayoutControlItem layoutControlItem3;
  2483. private DevExpress.XtraLayout.LayoutControlItem layoutControlItem6;
  2484. private DevExpress.XtraEditors.DXErrorProvider.DXErrorProvider dxErrorProvider1;
  2485. private DevExpress.XtraLayout.EmptySpaceItem emptySpaceItem2;
  2486. private void InitializeComponent()
  2487. {
  2488. this.components = new System.ComponentModel.Container();
  2489. DevExpress.XtraEditors.Controls.EditorButtonImageOptions editorButtonImageOptions1 = new DevExpress.XtraEditors.Controls.EditorButtonImageOptions();
  2490. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject1 = new DevExpress.Utils.SerializableAppearanceObject();
  2491. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject2 = new DevExpress.Utils.SerializableAppearanceObject();
  2492. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject3 = new DevExpress.Utils.SerializableAppearanceObject();
  2493. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject4 = new DevExpress.Utils.SerializableAppearanceObject();
  2494. DevExpress.XtraEditors.Controls.EditorButtonImageOptions editorButtonImageOptions2 = new DevExpress.XtraEditors.Controls.EditorButtonImageOptions();
  2495. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject5 = new DevExpress.Utils.SerializableAppearanceObject();
  2496. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject6 = new DevExpress.Utils.SerializableAppearanceObject();
  2497. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject7 = new DevExpress.Utils.SerializableAppearanceObject();
  2498. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject8 = new DevExpress.Utils.SerializableAppearanceObject();
  2499. this.layoutControl1 = new DevExpress.XtraLayout.LayoutControl();
  2500. this.txtCaption = new DevExpress.XtraEditors.TextEdit();
  2501. this.txtSpeed = new DevExpress.XtraEditors.ButtonEdit();
  2502. this.Root = new DevExpress.XtraLayout.LayoutControlGroup();
  2503. this.layoutControlItem1 = new DevExpress.XtraLayout.LayoutControlItem();
  2504. this.emptySpaceItem1 = new DevExpress.XtraLayout.EmptySpaceItem();
  2505. this.layoutControlItem5 = new DevExpress.XtraLayout.LayoutControlItem();
  2506. this.btnOk = new DevExpress.XtraEditors.SimpleButton();
  2507. this.layoutControlItem3 = new DevExpress.XtraLayout.LayoutControlItem();
  2508. this.btnCancel = new DevExpress.XtraEditors.SimpleButton();
  2509. this.layoutControlItem6 = new DevExpress.XtraLayout.LayoutControlItem();
  2510. this.dxErrorProvider1 = new DevExpress.XtraEditors.DXErrorProvider.DXErrorProvider(this.components);
  2511. this.emptySpaceItem2 = new DevExpress.XtraLayout.EmptySpaceItem();
  2512. ((System.ComponentModel.ISupportInitialize)(this.layoutControl1)).BeginInit();
  2513. this.layoutControl1.SuspendLayout();
  2514. ((System.ComponentModel.ISupportInitialize)(this.txtCaption.Properties)).BeginInit();
  2515. ((System.ComponentModel.ISupportInitialize)(this.txtSpeed.Properties)).BeginInit();
  2516. ((System.ComponentModel.ISupportInitialize)(this.Root)).BeginInit();
  2517. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem1)).BeginInit();
  2518. ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem1)).BeginInit();
  2519. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem5)).BeginInit();
  2520. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem3)).BeginInit();
  2521. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem6)).BeginInit();
  2522. ((System.ComponentModel.ISupportInitialize)(this.dxErrorProvider1)).BeginInit();
  2523. ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem2)).BeginInit();
  2524. this.SuspendLayout();
  2525. //
  2526. // layoutControl1
  2527. //
  2528. this.layoutControl1.Controls.Add(this.btnCancel);
  2529. this.layoutControl1.Controls.Add(this.btnOk);
  2530. this.layoutControl1.Controls.Add(this.txtCaption);
  2531. this.layoutControl1.Controls.Add(this.txtSpeed);
  2532. this.layoutControl1.Dock = System.Windows.Forms.DockStyle.Fill;
  2533. this.layoutControl1.Location = new System.Drawing.Point(0, 0);
  2534. this.layoutControl1.Name = "layoutControl1";
  2535. this.layoutControl1.OptionsCustomizationForm.DesignTimeCustomizationFormPositionAndSize = new System.Drawing.Rectangle(689, 0, 650, 400);
  2536. this.layoutControl1.Root = this.Root;
  2537. this.layoutControl1.Size = new System.Drawing.Size(272, 208);
  2538. this.layoutControl1.TabIndex = 0;
  2539. this.layoutControl1.Text = "layoutControl1";
  2540. //
  2541. // txtCaption
  2542. //
  2543. this.txtCaption.Location = new System.Drawing.Point(12, 29);
  2544. this.txtCaption.Name = "txtCaption";
  2545. this.txtCaption.Properties.Appearance.Options.UseTextOptions = true;
  2546. this.txtCaption.Properties.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
  2547. this.txtCaption.Properties.AutoHeight = false;
  2548. this.txtCaption.Properties.MaxLength = 10;
  2549. this.txtCaption.Properties.NullValuePrompt = "必需";
  2550. this.txtCaption.Size = new System.Drawing.Size(248, 22);
  2551. this.txtCaption.StyleController = this.layoutControl1;
  2552. this.txtCaption.TabIndex = 9;
  2553. //
  2554. // txtLon
  2555. //
  2556. this.txtSpeed.Location = new System.Drawing.Point(12, 80);
  2557. this.txtSpeed.Name = "txtSpeed";
  2558. this.txtSpeed.Properties.MaxLength = 10;
  2559. this.txtSpeed.Properties.MaskSettings.Set("MaskManagerType", typeof(DevExpress.Data.Mask.NumericMaskManager));
  2560. this.txtSpeed.Properties.MaskSettings.Set("mask", "f");
  2561. this.txtSpeed.Properties.NullValuePrompt = "必需";
  2562. this.txtSpeed.Properties.Appearance.Options.UseTextOptions = true;
  2563. this.txtSpeed.Properties.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
  2564. this.txtSpeed.Properties.AutoHeight = false;
  2565. this.txtSpeed.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
  2566. new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph, "m/s", -1, false, true, false, editorButtonImageOptions1, new DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None), serializableAppearanceObject1, serializableAppearanceObject2, serializableAppearanceObject3, serializableAppearanceObject4, "", null, null, DevExpress.Utils.ToolTipAnchor.Default)});
  2567. this.txtSpeed.Size = new System.Drawing.Size(248, 22);
  2568. this.txtSpeed.StyleController = this.layoutControl1;
  2569. this.txtSpeed.TabIndex = 4;
  2570. //
  2571. // Root
  2572. //
  2573. this.Root.EnableIndentsWithoutBorders = DevExpress.Utils.DefaultBoolean.True;
  2574. this.Root.GroupBordersVisible = false;
  2575. this.Root.Items.AddRange(new DevExpress.XtraLayout.BaseLayoutItem[] {
  2576. this.layoutControlItem1,
  2577. this.emptySpaceItem1,
  2578. this.layoutControlItem5,
  2579. this.layoutControlItem3,
  2580. this.layoutControlItem6,
  2581. this.emptySpaceItem2});
  2582. this.Root.Name = "Root";
  2583. this.Root.Size = new System.Drawing.Size(272, 208);
  2584. this.Root.TextVisible = false;
  2585. //
  2586. // layoutControlItem1
  2587. //
  2588. this.layoutControlItem1.Control = this.txtSpeed;
  2589. this.layoutControlItem1.Location = new System.Drawing.Point(0, 43);
  2590. this.layoutControlItem1.MaxSize = new System.Drawing.Size(0, 51);
  2591. this.layoutControlItem1.MinSize = new System.Drawing.Size(54, 51);
  2592. this.layoutControlItem1.Name = "layoutControlItem1";
  2593. this.layoutControlItem1.Padding = new DevExpress.XtraLayout.Utils.Padding(2, 2, 10, 2);
  2594. this.layoutControlItem1.Size = new System.Drawing.Size(252, 51);
  2595. this.layoutControlItem1.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2596. this.layoutControlItem1.Text = "航迹速度";
  2597. this.layoutControlItem1.TextLocation = DevExpress.Utils.Locations.Top;
  2598. this.layoutControlItem1.TextSize = new System.Drawing.Size(24, 14);
  2599. //
  2600. // emptySpaceItem1
  2601. //
  2602. this.emptySpaceItem1.AllowHotTrack = false;
  2603. this.emptySpaceItem1.Location = new System.Drawing.Point(0, 162);
  2604. this.emptySpaceItem1.MaxSize = new System.Drawing.Size(0, 26);
  2605. this.emptySpaceItem1.MinSize = new System.Drawing.Size(104, 26);
  2606. this.emptySpaceItem1.Name = "emptySpaceItem1";
  2607. this.emptySpaceItem1.Size = new System.Drawing.Size(113, 26);
  2608. this.emptySpaceItem1.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2609. this.emptySpaceItem1.TextSize = new System.Drawing.Size(0, 0);
  2610. //
  2611. // layoutControlItem5
  2612. //
  2613. this.layoutControlItem5.Control = this.txtCaption;
  2614. this.layoutControlItem5.Location = new System.Drawing.Point(0, 0);
  2615. this.layoutControlItem5.MaxSize = new System.Drawing.Size(0, 43);
  2616. this.layoutControlItem5.MinSize = new System.Drawing.Size(54, 43);
  2617. this.layoutControlItem5.Name = "layoutControlItem5";
  2618. this.layoutControlItem5.Size = new System.Drawing.Size(252, 43);
  2619. this.layoutControlItem5.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2620. this.layoutControlItem5.Text = "航迹名称";
  2621. this.layoutControlItem5.TextLocation = DevExpress.Utils.Locations.Top;
  2622. this.layoutControlItem5.TextSize = new System.Drawing.Size(24, 14);
  2623. //
  2624. // btnOk
  2625. //
  2626. this.btnOk.Location = new System.Drawing.Point(125, 174);
  2627. this.btnOk.Name = "btnOk";
  2628. this.btnOk.Size = new System.Drawing.Size(65, 22);
  2629. this.btnOk.StyleController = this.layoutControl1;
  2630. this.btnOk.TabIndex = 10;
  2631. this.btnOk.Text = "确定";
  2632. this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
  2633. //
  2634. // layoutControlItem3
  2635. //
  2636. this.layoutControlItem3.Control = this.btnOk;
  2637. this.layoutControlItem3.Location = new System.Drawing.Point(113, 162);
  2638. this.layoutControlItem3.MaxSize = new System.Drawing.Size(69, 26);
  2639. this.layoutControlItem3.MinSize = new System.Drawing.Size(69, 26);
  2640. this.layoutControlItem3.Name = "layoutControlItem3";
  2641. this.layoutControlItem3.Size = new System.Drawing.Size(69, 26);
  2642. this.layoutControlItem3.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2643. this.layoutControlItem3.TextSize = new System.Drawing.Size(0, 0);
  2644. this.layoutControlItem3.TextVisible = false;
  2645. //
  2646. // btnCancel
  2647. //
  2648. this.btnCancel.Location = new System.Drawing.Point(194, 174);
  2649. this.btnCancel.Name = "btnCancel";
  2650. this.btnCancel.Size = new System.Drawing.Size(66, 22);
  2651. this.btnCancel.StyleController = this.layoutControl1;
  2652. this.btnCancel.TabIndex = 11;
  2653. this.btnCancel.Text = "取消";
  2654. this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
  2655. //
  2656. // layoutControlItem6
  2657. //
  2658. this.layoutControlItem6.Control = this.btnCancel;
  2659. this.layoutControlItem6.Location = new System.Drawing.Point(182, 162);
  2660. this.layoutControlItem6.MaxSize = new System.Drawing.Size(70, 26);
  2661. this.layoutControlItem6.MinSize = new System.Drawing.Size(70, 26);
  2662. this.layoutControlItem6.Name = "layoutControlItem6";
  2663. this.layoutControlItem6.Size = new System.Drawing.Size(70, 26);
  2664. this.layoutControlItem6.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2665. this.layoutControlItem6.TextSize = new System.Drawing.Size(0, 0);
  2666. this.layoutControlItem6.TextVisible = false;
  2667. //
  2668. // dxErrorProvider1
  2669. //
  2670. this.dxErrorProvider1.ContainerControl = this;
  2671. //
  2672. // emptySpaceItem2
  2673. //
  2674. this.emptySpaceItem2.AllowHotTrack = false;
  2675. this.emptySpaceItem2.Location = new System.Drawing.Point(0, 145);
  2676. this.emptySpaceItem2.MinSize = new System.Drawing.Size(104, 1);
  2677. this.emptySpaceItem2.Name = "emptySpaceItem2";
  2678. this.emptySpaceItem2.Size = new System.Drawing.Size(252, 17);
  2679. this.emptySpaceItem2.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2680. this.emptySpaceItem2.TextSize = new System.Drawing.Size(0, 0);
  2681. //
  2682. // MapFlightLineView
  2683. //
  2684. this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
  2685. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  2686. this.ClientSize = new System.Drawing.Size(272, 208);
  2687. this.Controls.Add(this.layoutControl1);
  2688. this.Text = "航迹";
  2689. ((System.ComponentModel.ISupportInitialize)(this.layoutControl1)).EndInit();
  2690. this.layoutControl1.ResumeLayout(false);
  2691. ((System.ComponentModel.ISupportInitialize)(this.txtCaption.Properties)).EndInit();
  2692. ((System.ComponentModel.ISupportInitialize)(this.txtSpeed.Properties)).EndInit();
  2693. ((System.ComponentModel.ISupportInitialize)(this.Root)).EndInit();
  2694. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem1)).EndInit();
  2695. ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem1)).EndInit();
  2696. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem5)).EndInit();
  2697. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem3)).EndInit();
  2698. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem6)).EndInit();
  2699. ((System.ComponentModel.ISupportInitialize)(this.dxErrorProvider1)).EndInit();
  2700. ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem2)).EndInit();
  2701. this.ResumeLayout(false);
  2702. }
  2703. protected override void Dispose(bool disposing)
  2704. {
  2705. if (disposing && (components != null))
  2706. {
  2707. components.Dispose();
  2708. }
  2709. base.Dispose(disposing);
  2710. }
  2711. public MapFlightLineView(List<string> flights)
  2712. {
  2713. InitializeComponent();
  2714. if (flights == null)
  2715. {
  2716. flights = new List<string>();
  2717. }
  2718. Names = flights;
  2719. txtCaption.EditValueChanged += TxtCaption_EditValueChanged;
  2720. txtSpeed.EditValueChanged += TxtSpeed_EditValueChanged;
  2721. }
  2722. private void TxtSpeed_EditValueChanged(object sender, EventArgs e)
  2723. {
  2724. double speed;
  2725. if (!double.TryParse(txtSpeed.Text, out speed))
  2726. {
  2727. dxErrorProvider1.SetError(txtSpeed, "请设置正确的航迹速度(m/s)");
  2728. return;
  2729. }
  2730. if (speed <= 0)
  2731. {
  2732. dxErrorProvider1.SetError(txtSpeed, "航迹速度范围不能小于等于0(m/s)");
  2733. return;
  2734. }
  2735. dxErrorProvider1.SetError(txtSpeed, string.Empty);
  2736. }
  2737. private void TxtCaption_EditValueChanged(object sender, EventArgs e)
  2738. {
  2739. string Name = txtCaption.Text.Trim();
  2740. if (string.IsNullOrEmpty(Name))
  2741. {
  2742. dxErrorProvider1.SetError(txtCaption, "请设置航迹名称");
  2743. return;
  2744. }
  2745. if (Names.Contains(Name))
  2746. {
  2747. dxErrorProvider1.SetError(txtCaption, $"航迹[{Name}]已存在");
  2748. return;
  2749. }
  2750. dxErrorProvider1.SetError(txtCaption, string.Empty);
  2751. }
  2752. private List<string> Names;
  2753. public Action<(bool isOk, string caption, double speed)> onClick;
  2754. public string Caption
  2755. {
  2756. get
  2757. {
  2758. return txtCaption.Text.Trim();
  2759. }
  2760. set
  2761. {
  2762. txtCaption.Text = value;
  2763. }
  2764. }
  2765. public double Speed
  2766. {
  2767. get
  2768. {
  2769. return double.Parse(txtSpeed.Text.Trim());
  2770. }
  2771. set
  2772. {
  2773. txtSpeed.Text = value.ToString();
  2774. }
  2775. }
  2776. private void btnOk_Click(object sender, EventArgs e)
  2777. {
  2778. dxErrorProvider1.ClearErrors();
  2779. string Name = txtCaption.Text.Trim();
  2780. if (string.IsNullOrEmpty(Name))
  2781. {
  2782. dxErrorProvider1.SetError(txtCaption, "请设置航迹名称");
  2783. return;
  2784. }
  2785. if (Names.Contains(Name))
  2786. {
  2787. dxErrorProvider1.SetError(txtCaption, $"航迹[{Name}]已存在");
  2788. return;
  2789. }
  2790. double speed;
  2791. if (!double.TryParse(txtSpeed.Text, out speed))
  2792. {
  2793. dxErrorProvider1.SetError(txtSpeed, "请设置正确的航迹速度(Km/s)");
  2794. return;
  2795. }
  2796. if (speed <= 0)
  2797. {
  2798. dxErrorProvider1.SetError(txtSpeed, "航迹速度范围不能小于等于0Km/s");
  2799. return;
  2800. }
  2801. this.onClick?.Invoke((true, Caption, Speed));
  2802. }
  2803. private void btnCancel_Click(object sender, EventArgs e)
  2804. {
  2805. this.onClick?.Invoke((false, "", 0));
  2806. }
  2807. }
  2808. #endregion
  2809. #region 半径圆
  2810. public class MyLatLng
  2811. {
  2812. public double Rc = 6378137; //赤道半径
  2813. public double Rj = 6356725; //极半径
  2814. public double m_LoDeg, m_LoMin, m_LoSec;
  2815. public double m_LaDeg, m_LaMin, m_LaSec;
  2816. public double m_Longitude, m_Latitude;
  2817. public double m_RadLo, m_RadLa;
  2818. public double Ec;
  2819. public double Ed;
  2820. public MyLatLng(double longitude, double latitude)
  2821. {
  2822. m_LoDeg = (int)longitude;
  2823. m_LoMin = (int)((longitude - m_LoDeg) * 60);
  2824. m_LoSec = (longitude - m_LoDeg - m_LoMin / 60) * 3600;
  2825. m_LaDeg = (int)latitude;
  2826. m_LaMin = (int)((latitude - m_LaDeg) * 60);
  2827. m_LaSec = (latitude - m_LaDeg - m_LaMin / 60) * 3600;
  2828. m_Longitude = longitude;
  2829. m_Latitude = latitude;
  2830. m_RadLo = longitude * Math.PI / 180;
  2831. m_RadLa = latitude * Math.PI / 180;
  2832. Ec = Rj + (Rc - Rj) * (90 - m_Latitude) / 90;
  2833. Ed = Ec * Math.Cos(m_RadLa);
  2834. }
  2835. }
  2836. #endregion
  2837. #region ImageLayer数据源接口实现(本地和Http接口)
  2838. class ImageTileSource : IImageTileSource
  2839. {
  2840. SQLiteConnection con;
  2841. public ImageTileSource()
  2842. {
  2843. var files = Directory.GetFiles(Application.StartupPath, "Data.gmdb", SearchOption.AllDirectories);
  2844. if (files.Length > 0)
  2845. {
  2846. try
  2847. {
  2848. conStr = string.Format(conStr, files[0]);
  2849. con = new SQLiteConnection(conStr);
  2850. con.Open();
  2851. }
  2852. catch
  2853. {
  2854. conStr = null;
  2855. Console.WriteLine("Data.gmdb文件读取出错!");
  2856. }
  2857. }
  2858. else
  2859. {
  2860. conStr = null;
  2861. }
  2862. }
  2863. public string Name => "GMap地图瓦片";
  2864. public bool CanDisposeSourceImage => true;
  2865. public Image GetImage(int x, int y, int level, Size size)
  2866. {
  2867. var data = QueryTile(x, y, level, 0);
  2868. if (data == null) return null;
  2869. return Image.FromStream(new MemoryStream(data));
  2870. }
  2871. string QuerySql = "SELECT Tile FROM main.TilesData WHERE id = (SELECT id FROM main.Tiles WHERE X={0} AND Y={1} AND Zoom={2} AND Type={3})";
  2872. string conStr = "Data Source=\"{0}\";Page Size=32768";
  2873. byte[] QueryTile(int x, int y, int zoom, int type)
  2874. {
  2875. if (conStr == null) return null;
  2876. type = (int)mMapType;
  2877. if (type == 0) type = 1818940751;
  2878. using (DbCommand com = con.CreateCommand())
  2879. {
  2880. com.CommandText = string.Format(QuerySql, x, y, zoom, type);
  2881. using (DbDataReader rd = com.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
  2882. {
  2883. if (rd.Read())
  2884. {
  2885. long length = rd.GetBytes(0, 0, null, 0, 0);
  2886. byte[] tile = new byte[length];
  2887. rd.GetBytes(0, 0, tile, 0, tile.Length);
  2888. return tile;
  2889. }
  2890. }
  2891. }
  2892. return null;
  2893. }
  2894. }
  2895. class HttpMapDataProvider : MapDataProviderBase
  2896. {
  2897. public HttpMapDataProvider()
  2898. {
  2899. TileSource = new HttpTileSource(this);
  2900. }
  2901. public override MapSize GetMapSizeInPixels(double zoomLevel)
  2902. {
  2903. double imageSize;
  2904. imageSize = HttpTileSource.CalculateTotalImageSize(zoomLevel);
  2905. return new MapSize(imageSize, imageSize);
  2906. }
  2907. protected override Size BaseSizeInPixels
  2908. {
  2909. get { return new Size(Convert.ToInt32(HttpTileSource.tileSize * 2), Convert.ToInt32(HttpTileSource.tileSize * 2)); }
  2910. }
  2911. }
  2912. class HttpTileSource : MapTileSourceBase
  2913. {
  2914. public const int tileSize = 256;
  2915. public const int maxZoomLevel = 14;
  2916. public string HttpServerAddr { get; set; }
  2917. public GoogleMapType MapType { get; set; } = GoogleMapType.Normal;
  2918. internal static double CalculateTotalImageSize(double zoomLevel)
  2919. {
  2920. if (zoomLevel < 1.0)
  2921. return zoomLevel * tileSize * 2;
  2922. return Math.Pow(2.0, zoomLevel) * tileSize;
  2923. }
  2924. public HttpTileSource(ICacheOptionsProvider cacheOptionsProvider) :
  2925. base((int)CalculateTotalImageSize(maxZoomLevel), (int)CalculateTotalImageSize(maxZoomLevel), tileSize, tileSize, cacheOptionsProvider)
  2926. {
  2927. }
  2928. public override Uri GetTileByZoomLevel(int zoomLevel, int tilePositionX, int tilePositionY)
  2929. {
  2930. if (string.IsNullOrWhiteSpace(HttpServerAddr)) return null;
  2931. try
  2932. {
  2933. if (zoomLevel <= maxZoomLevel)
  2934. {
  2935. string imgUrl = $"{HttpServerAddr}/{(int)MapType}/{zoomLevel}/{tilePositionX}/{tilePositionY}";
  2936. //string imgUrl = string.Format("http://192.168.0.214:58089/{0}/{1}/{2}/{3}", (int)GoogleMapType.Normal, zoomLevel, tilePositionX, tilePositionY);
  2937. Uri u = new Uri(imgUrl);
  2938. return u;
  2939. }
  2940. return null;
  2941. }
  2942. catch
  2943. {
  2944. Console.WriteLine($"加载地图数据出错,无法连接到{HttpServerAddr}");
  2945. return null;
  2946. }
  2947. }
  2948. }
  2949. #endregion
  2950. //定位点聚合器
  2951. class PosClusterer : IClusterer
  2952. {
  2953. private MapControl ctrl;
  2954. private IMapDataAdapter owner;
  2955. private MapViewport preViewPoint;
  2956. private DebounceDispatcher dispatcher = new DebounceDispatcher();
  2957. public bool IsBusy { get; private set; }
  2958. public MapItemCollection Items { get; private set; }
  2959. public PosClusterer(MapControl ctrl)
  2960. {
  2961. this.ctrl = ctrl;
  2962. }
  2963. public void SetOwner(IMapDataAdapter owner)
  2964. {
  2965. this.owner = owner;
  2966. Items = new MapItemCollection(owner);
  2967. }
  2968. public void Clusterize(IEnumerable<MapItem> sourceItems, MapViewport viewport, bool sourceChanged)
  2969. {
  2970. IsBusy = true;
  2971. if (sourceChanged)
  2972. DoClusterize(sourceItems, viewport, sourceChanged);
  2973. else
  2974. dispatcher.Debounce(100, () => DoClusterize(sourceItems, viewport, sourceChanged));
  2975. }
  2976. private void DoClusterize(IEnumerable<MapItem> sourceItems, MapViewport viewport, bool sourceChanged)
  2977. {
  2978. if (preViewPoint == null)
  2979. {
  2980. preViewPoint = viewport;
  2981. return;
  2982. }
  2983. if (!sourceChanged && preViewPoint.ZoomLevel == viewport.ZoomLevel)//地图移动或者MapControl大小发生了改变时直接操作Items避免闪烁
  2984. {
  2985. preViewPoint = viewport;
  2986. }
  2987. else//地图进行了缩放
  2988. {
  2989. Items.Clear();
  2990. var cache = new Dictionary<int, List<MapItem>>();
  2991. foreach (MapDot item in sourceItems)
  2992. {
  2993. var point = ctrl.CoordPointToScreenPoint(item.Location);
  2994. int pointX = (int)point.X;
  2995. int pointY = (int)point.Y;
  2996. bool visible = true;
  2997. if (pointX <= _dotSize || pointX > ctrl.Width - _dotSize)
  2998. visible = false;
  2999. else if (pointY <= _dotSize || pointY > ctrl.Height - _dotSize)
  3000. visible = false;
  3001. pointX /= (_dotSize * 2);
  3002. pointY /= (_dotSize * 2);
  3003. var key = pointX << 16 | pointY;
  3004. if (!visible)
  3005. key = -key;
  3006. if (!cache.ContainsKey(key))
  3007. cache.Add(key, new List<MapItem>());
  3008. cache[key].Add(item);
  3009. }
  3010. var innerData = ctrl.Tag as InnerData;
  3011. innerData._clusterCache.Clear();
  3012. LinkedList<MapItem> temp = new LinkedList<MapItem>();
  3013. foreach (var kv in cache)
  3014. {
  3015. var firstDot = kv.Value[0] as MapDot;
  3016. var firstObj = firstDot.Tag as PosData;
  3017. firstDot.Size = kv.Value.Count > 1 ? _dotSize + 2 : _dotSize;
  3018. firstObj.ClusterCount = kv.Value.Count;
  3019. firstObj.ClusterKey = kv.Key;
  3020. innerData._clusterCache.Add(kv.Key, firstDot);
  3021. temp.AddLast(firstDot);
  3022. }
  3023. Items.AddRange(temp);
  3024. cache.Clear();
  3025. preViewPoint = viewport;
  3026. owner.OnClustered();
  3027. }
  3028. this.IsBusy = false;
  3029. }
  3030. //计算多个坐标的中心位置
  3031. public GeoPoint GetCenterPointFromListOfCoordinates(List<MapItem> geoCoordinateList)
  3032. {
  3033. int total = geoCoordinateList.Count;
  3034. double lat = 0, lon = 0;
  3035. foreach (MapDot g in geoCoordinateList)
  3036. {
  3037. lat += (g.Location as GeoPoint).Latitude * Math.PI / 180;
  3038. lon += (g.Location as GeoPoint).Longitude * Math.PI / 180;
  3039. }
  3040. lat /= total;
  3041. lon /= total;
  3042. return new GeoPoint(lat * 180 / Math.PI, lon * 180 / Math.PI);
  3043. }
  3044. }
  3045. }