MapControlEx.cs 124 KB

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