MapControlEx.cs 124 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058
  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.True,
  1562. Stroke = ColorHelper.GetColor(title),
  1563. StrokeWidth = 2,
  1564. HighlightedStrokeWidth=4,
  1565. IsGeodesic = true,
  1566. CanResize = false,
  1567. CanEdit = false,
  1568. CanRotate = false,
  1569. IsHitTestVisible = true,
  1570. CanMove = false,
  1571. Tag = $"DrawDtoLine_{title}",
  1572. ToolTipPattern = $"{title}",
  1573. };
  1574. foreach (var item in lines)
  1575. {
  1576. if (double.IsNaN(item.lat) || double.IsNaN(item.lon)) continue;
  1577. polyLine.Points.Add(new GeoPoint(item.lat, item.lon));
  1578. }
  1579. if (!polyLine.Points.Any()) return;
  1580. innerData.mMapStorage.Items.Add(polyLine);
  1581. }
  1582. /// <summary>
  1583. /// 绘制时差多条线 两个点绘制一个线段 1和2一个线段 3和4一个线段
  1584. /// </summary>
  1585. /// <param name="ctrl"></param>
  1586. /// <param name="title"></param>
  1587. /// <param name="dots"></param>
  1588. public static void DrawDtoLineTwo(this MapControl ctrl, string title, IEnumerable<(double lon, double lat)> dots)
  1589. {
  1590. if (dots == null || !dots.Any()) return;
  1591. string identify = $"DrawDtoLine_{title}";
  1592. var innerData = ctrl.Tag as InnerData;
  1593. //多条线 两个点绘制一个线段 1和2一个线段 3和4一个线段
  1594. List<MapPolyline> polylines = new List<MapPolyline>();
  1595. int index = 0;
  1596. int count = dots.Count();
  1597. MapPolyline polyLine = null;
  1598. foreach (var item in dots)
  1599. {
  1600. if (index % 2 == 0)
  1601. {
  1602. if (polyLine != null)//添加线段
  1603. {
  1604. polylines.Add(polyLine);
  1605. }
  1606. polyLine = new MapPolyline()
  1607. {
  1608. Stroke = ColorHelper.GetColor(identify),
  1609. EnableHighlighting = DefaultBoolean.False,
  1610. EnableSelection = DefaultBoolean.False,
  1611. StrokeWidth = 4,
  1612. IsGeodesic = true,
  1613. CanResize = false,
  1614. CanEdit = false,
  1615. CanRotate = false,
  1616. IsHitTestVisible = true,
  1617. CanMove = false,
  1618. Tag = $"{identify}",
  1619. ToolTipPattern = title
  1620. };
  1621. }
  1622. polyLine.Points.Add(new GeoPoint(item.lat, item.lon));
  1623. index++;
  1624. if (index == count)//添加最后一个线段
  1625. {
  1626. polylines.Add(polyLine);
  1627. }
  1628. }
  1629. if (!polyLine.Points.Any()) return;
  1630. innerData.mMapStorage.Items.AddRange(polylines);
  1631. }
  1632. public static void DrawGdopLine(this MapControl ctrl, IEnumerable<(string wcKm, double lon, double lat)> lines)
  1633. {
  1634. if (lines == null || !lines.Any()) return;
  1635. var innerData = ctrl.Tag as InnerData;
  1636. var wcKm = lines.First().wcKm;
  1637. var polyLine = new MapPolyline()
  1638. {
  1639. Stroke = ColorHelper.GetColor(wcKm),
  1640. StrokeWidth = 2,
  1641. IsGeodesic = true,
  1642. CanResize = false,
  1643. CanEdit = false,
  1644. CanRotate = false,
  1645. IsHitTestVisible = true,
  1646. CanMove = false,
  1647. Tag = $"DrawGdopLine_{wcKm}",
  1648. };
  1649. polyLine.TitleOptions.Pattern = wcKm;
  1650. foreach (var item in lines)
  1651. {
  1652. if (double.IsNaN(item.lat) || double.IsNaN(item.lon)) continue;
  1653. polyLine.Points.Add(new GeoPoint(item.lat, item.lon));
  1654. }
  1655. if (!polyLine.Points.Any()) return;
  1656. innerData.mMapStorage.Items.Add(polyLine);
  1657. }
  1658. /// <summary>
  1659. /// 绘制线
  1660. /// </summary>
  1661. /// <param name="ctrl"></param>
  1662. /// <param name="title"></param>
  1663. /// <param name="lines"></param>
  1664. /// <param name="isClear">是否清除上次绘制</param>
  1665. public static void DrawCXLine(this MapControl ctrl, string title, IEnumerable<(double lon, double lat)> lines, bool isClear = true)
  1666. {
  1667. string identify = "DrawCXLine_";
  1668. if (lines == null || !lines.Any()) return;
  1669. var innerData = ctrl.Tag as InnerData;
  1670. if (isClear)
  1671. {
  1672. var mapItem = innerData.mMapStorage.Items.Find(m => m.Tag.ToString().StartsWith(identify));
  1673. if (mapItem != null)
  1674. {
  1675. innerData.mMapStorage.Items.Remove(mapItem);
  1676. }
  1677. }
  1678. var polyLine = new MapPolyline()
  1679. {
  1680. Stroke = Color.Red,
  1681. StrokeWidth = 2,
  1682. CanMove = false,
  1683. Visible = true,
  1684. IsHitTestVisible = true,
  1685. Tag = $"{identify}{title}",
  1686. ToolTipPattern = title,
  1687. };
  1688. foreach (var item in lines)
  1689. {
  1690. if (double.IsNaN(item.lat) || double.IsNaN(item.lon)) continue;
  1691. polyLine.Points.Add(new GeoPoint(item.lat, item.lon));
  1692. }
  1693. if (!polyLine.Points.Any()) return;
  1694. innerData.mMapStorage.Items.Add(polyLine);
  1695. }
  1696. public static void DrawErrEllipse(this MapControl ctrl, double r1, double r2, IEnumerable<(double lon, double lat)> lines)
  1697. {
  1698. if (lines == null || !lines.Any()) return;
  1699. var innerData = ctrl.Tag as InnerData;
  1700. //innerData.mMapStorage.Items.Clear();
  1701. var polyLine = new MapPolyline()
  1702. {
  1703. Stroke = Color.Red,
  1704. StrokeWidth = 2,
  1705. IsGeodesic = true,
  1706. CanResize = false,
  1707. CanEdit = false,
  1708. CanRotate = false,
  1709. IsHitTestVisible = true,
  1710. CanMove = false,
  1711. Tag = $"DrawErrEllipse",
  1712. };
  1713. //polyLine.ToolTipPattern = $"长轴:{r1:f1}km\r\n短轴:{r2:f1}km";
  1714. foreach (var item in lines)
  1715. {
  1716. if (double.IsNaN(item.lat) || double.IsNaN(item.lon)) continue;
  1717. polyLine.Points.Add(new GeoPoint(item.lat, item.lon));
  1718. }
  1719. if (!polyLine.Points.Any()) return;
  1720. innerData.mMapStorage.Items.Add(polyLine);
  1721. var callout = new DevExpress.XtraMap.MapCallout()
  1722. {
  1723. Text = $"R1={r1:f1}km\r\nR2={r2:f1}km",
  1724. Location = polyLine.Points.First(),
  1725. CanMove = false,
  1726. IsHitTestVisible = false,
  1727. };
  1728. innerData.mMapStorage.Items.Add(callout);
  1729. }
  1730. /// <summary>
  1731. /// 绘制GDOP多条线 两个点绘制一个线段 1和2一个线段 3和4一个线段
  1732. /// </summary>
  1733. /// <param name="ctrl"></param>
  1734. /// <param name="wcKm"></param>
  1735. /// <param name="dots"></param>
  1736. /// <param name="patterncount"></param>
  1737. public static void DrawGdopLineTwo(this MapControl ctrl, string wcKm, IEnumerable<(double lon, double lat)> dots, int patterncount)
  1738. {
  1739. if (dots == null || !dots.Any()) return;
  1740. string identify = "DrawGdopLine_";
  1741. var innerData = ctrl.Tag as InnerData;
  1742. //多条线 两个点绘制一个线段 1和2一个线段 3和4一个线段
  1743. List<MapPolyline> polylines = new List<MapPolyline>();
  1744. int index = 0;
  1745. int count = dots.Count();
  1746. MapPolyline polyLine = null;
  1747. foreach (var item in dots)
  1748. {
  1749. if (index % 2 == 0)
  1750. {
  1751. if (polyLine != null)//添加线段
  1752. {
  1753. polylines.Add(polyLine);
  1754. }
  1755. polyLine = new MapPolyline()
  1756. {
  1757. Stroke = ColorHelper.GetColor(wcKm),
  1758. EnableHighlighting = DefaultBoolean.False,
  1759. EnableSelection = DefaultBoolean.False,
  1760. StrokeWidth = 4,
  1761. IsGeodesic = true,
  1762. CanResize = false,
  1763. CanEdit = false,
  1764. CanRotate = false,
  1765. IsHitTestVisible = true,
  1766. CanMove = false,
  1767. Tag = $"{identify}{wcKm}",
  1768. ToolTipPattern = wcKm,
  1769. };
  1770. }
  1771. polyLine.Points.Add(new GeoPoint(item.lat, item.lon));
  1772. if (patterncount == index)//提示公里信息
  1773. {
  1774. polyLine.TitleOptions.Pattern = wcKm;
  1775. }
  1776. index++;
  1777. if (index == count)//添加最后一个线段
  1778. {
  1779. polylines.Add(polyLine);
  1780. }
  1781. }
  1782. if (!polyLine.Points.Any()) return;
  1783. innerData.mMapStorage.Items.AddRange(polylines);
  1784. }
  1785. /// <summary>
  1786. /// 绘制半径圆
  1787. /// </summary>
  1788. /// <param name="ctrl"></param>
  1789. /// <param name="lat"></param>
  1790. /// <param name="lon"></param>
  1791. /// <param name="radius"></param>
  1792. public static void DrawRadiusRound(this MapControl ctrl, double lat, double lon, int radius)
  1793. {
  1794. var innerData = ctrl.Tag as InnerData;
  1795. try
  1796. {
  1797. if (radius <= 0)
  1798. return;
  1799. CoordPointCollection latLngs = new CoordPointCollection();
  1800. MyLatLng centerLatLng = new MyLatLng(lon, lat);
  1801. // 0 - 360度 寻找半径为radius,圆心为centerP的圆上点的经纬度
  1802. for (int i = 0; i < 360; i++)
  1803. {
  1804. //获取目标经纬度
  1805. MyLatLng tempLatLng = getMyLatLng(centerLatLng, radius, i);
  1806. //将自定义的经纬度类 转换成 标准经纬度类
  1807. CoordPoint p = new GeoPoint(tempLatLng.m_Latitude, tempLatLng.m_Longitude);
  1808. latLngs.Add(p);
  1809. }
  1810. //安全性检查
  1811. if (latLngs.Count < 20)
  1812. {
  1813. return;
  1814. }
  1815. //通过绘制多边形的方式绘制圆
  1816. MapPolygon gpol = new MapPolygon();
  1817. gpol.Points = latLngs;
  1818. gpol.Stroke = Color.Red;
  1819. gpol.Fill = Color.FromArgb(50, Color.Red);
  1820. gpol.IsHitTestVisible = true;
  1821. innerData.mMapStorageFixed.Items.Add(gpol);
  1822. }
  1823. catch (Exception)
  1824. {
  1825. //Dialog.Error(ex);
  1826. }
  1827. }
  1828. /// <summary>
  1829. /// 度 转换成 弧度
  1830. /// </summary>
  1831. /// <param name="degrees"></param>
  1832. /// <returns></returns>
  1833. public static double DegreesToRadians(double degrees)
  1834. {
  1835. const double degToRadFactor = Math.PI / 180;
  1836. return degrees * degToRadFactor;
  1837. }
  1838. /// <summary>
  1839. /// 计算两个点之间的距离
  1840. /// </summary>
  1841. /// <param name="startlon">开始经度</param>
  1842. /// <param name="startlat">开始纬度</param>
  1843. /// <param name="endlon">结束经度</param>
  1844. /// <param name="endlat">结束纬度</param>
  1845. /// <returns></returns>
  1846. public static double CalcLineKm(double startlon, double startlat, double endlon, double endlat)
  1847. {
  1848. GeoPoint startPoint = new GeoPoint() { Longitude = startlon, Latitude = startlat };
  1849. GeoPoint endPoint = new GeoPoint() { Longitude = endlon, Latitude = endlat };
  1850. double result = 0;
  1851. MapSize sizeInKm = new SphericalMercatorProjection().GeoToKilometersSize(startPoint, new MapSize(Math.Abs(startPoint.Longitude - endPoint.Longitude), Math.Abs(startPoint.Latitude - endPoint.Latitude)));
  1852. result = Math.Sqrt(sizeInKm.Width * sizeInKm.Width + sizeInKm.Height * sizeInKm.Height);
  1853. return result;
  1854. }
  1855. /// <summary>
  1856. /// 计算方向线坐标
  1857. /// </summary>
  1858. /// <param name="lon">经度</param>
  1859. /// <param name="lat">纬度</param>
  1860. /// <param name="deg"> 艏向角 角度制</param>
  1861. /// <param name="dis">长度 m</param>
  1862. /// <returns></returns>
  1863. public static (double, double) CalcSituation(double lon, double lat, double deg, double dis)
  1864. {
  1865. double rad = deg * (Math.PI / 180); //角度转弧度
  1866. double dx = dis * Math.Sin(rad);
  1867. double dy = dis * Math.Cos(rad);
  1868. MyLatLng A = new MyLatLng(lon, lat);
  1869. double bjd = (dx / A.Ed + A.m_RadLo) * 180 / Math.PI;
  1870. double bwd = (dy / A.Ec + A.m_RadLa) * 180 / Math.PI;
  1871. return (bjd, bwd);
  1872. }
  1873. /**
  1874. * 求B点经纬度
  1875. * @param A 已知点的经纬度,
  1876. * @param distance AB两地的距离 单位km
  1877. * @param angle AB连线与正北方向的夹角(0~360)
  1878. * @return B点的经纬度
  1879. */
  1880. private static MyLatLng getMyLatLng(MyLatLng A, double distance, double angle)
  1881. {
  1882. double dx = distance * 1000 * Math.Sin(DegreesToRadians(angle));
  1883. double dy = distance * 1000 * Math.Cos(DegreesToRadians(angle));
  1884. double bjd = (dx / A.Ed + A.m_RadLo) * 180 / Math.PI;
  1885. double bwd = (dy / A.Ec + A.m_RadLa) * 180 / Math.PI;
  1886. return new MyLatLng(bjd, bwd);
  1887. }
  1888. public static void ClearRect(this MapControl ctrl)
  1889. {
  1890. var innerDate = ctrl.Tag as InnerData;
  1891. if (innerDate.rangeItem != null)
  1892. innerDate.mMapStorage.Items.Remove(innerDate.rangeItem);
  1893. if (innerDate.dotItem != null)
  1894. innerDate.mMapStorage.Items.Remove(innerDate.dotItem);
  1895. }
  1896. /// <summary>
  1897. /// 获取地图框选的范围信息(可能为null)
  1898. /// </summary>
  1899. /// <param name="ctrl"></param>
  1900. /// <returns></returns>
  1901. public static (double starLon, double startLat, double centerLon, double centerLat,
  1902. double endLon, double endLat, double lonRange, double latRange) GetCurrentRect(this MapControl ctrl)
  1903. {
  1904. var innerData = ctrl.Tag as InnerData;
  1905. return innerData.CurrentRect;
  1906. }
  1907. /// <summary>
  1908. /// 获取地图瓦片图层
  1909. /// </summary>
  1910. /// <param name="ctrl"></param>
  1911. /// <returns></returns>
  1912. public static List<ImageLayer> GetImageLayer(this MapControl ctrl)
  1913. {
  1914. if (ctrl.Layers == null) return null;
  1915. return ctrl.Layers.Where(p => p.Name.StartsWith("WMTS:")).Select(p => (ImageLayer)p).ToList();
  1916. }
  1917. /// <summary>
  1918. /// 获取地图绘制图层
  1919. /// </summary>
  1920. /// <param name="ctrl"></param>
  1921. /// <returns></returns>
  1922. public static VectorItemsLayer GetDrawLayer(this MapControl ctrl)
  1923. {
  1924. return (VectorItemsLayer)ctrl.Layers["DrawLayer"];
  1925. }
  1926. /// <summary>
  1927. /// 获取地图绘制图层
  1928. /// </summary>
  1929. /// <param name="ctrl"></param>
  1930. /// <returns></returns>
  1931. public static VectorItemsLayer GetPosLayer(this MapControl ctrl)
  1932. {
  1933. return (VectorItemsLayer)ctrl.Layers["PosLayer"];
  1934. }
  1935. /// <summary>
  1936. /// 获取地图绘制图层的数据仓库
  1937. /// </summary>
  1938. /// <param name="ctrl"></param>
  1939. /// <returns></returns>
  1940. public static MapItemStorage GetDrawStorage(this MapControl ctrl)
  1941. {
  1942. var innerData = ctrl.Tag as InnerData;
  1943. return innerData.mMapStorage;
  1944. }
  1945. /// <summary>
  1946. /// 设置本地地图类型.默认为Normal
  1947. /// 该方法为所有MapControl实例设置地图类型
  1948. /// </summary>
  1949. /// <param name="mapType"></param>
  1950. public static void SetLocalMapType(GoogleMapType mapType)
  1951. {
  1952. mMapType = mapType;
  1953. listMapCtrl.ForEach(t =>
  1954. {
  1955. var localLayer = t.GetImageLayer()?.FirstOrDefault(p => p.Name == "WMTS:Local");
  1956. if (localLayer == null) return;
  1957. var provider = localLayer.DataProvider as MapTileDataProviderBase;
  1958. provider?.ClearCache();
  1959. t.Refresh();
  1960. });
  1961. }
  1962. #region private
  1963. private static void DrawRect_MouseMove(object sender, MouseEventArgs e)
  1964. {
  1965. var innerData = (sender as MapControl).Tag as InnerData;
  1966. if (!innerData.drawingRect) return;
  1967. innerData.dotItem.Location = innerData.rangeItem.GetCenter();
  1968. var startLon = Math.Round(innerData.rangeItem.Location.GetX(), 3);
  1969. var startLat = Math.Round(innerData.rangeItem.Location.GetY(), 3);
  1970. if (startLon >= 180)
  1971. {
  1972. startLon -= 360;
  1973. }
  1974. if (startLon <= -180)
  1975. {
  1976. startLon += 360;
  1977. }
  1978. var center = innerData.rangeItem.GetCenter();
  1979. var centerLon = Math.Round(center.GetX(), 3);
  1980. if (centerLon >= 180)
  1981. {
  1982. centerLon -= 360;
  1983. }
  1984. if (centerLon <= -180)
  1985. {
  1986. centerLon += 360;
  1987. }
  1988. var centerLat = Math.Round(center.GetY(), 3);
  1989. double endLon;
  1990. if (centerLon < 0 && startLon > 0)
  1991. endLon = startLon + 2 * (centerLon + 360 - startLon);
  1992. else
  1993. endLon = startLon + 2 * (centerLon - startLon);
  1994. var endLat = startLat + 2 * (centerLat - startLat);
  1995. var StartLon = Math.Min(startLon, endLon);
  1996. var StartLat = Math.Min(startLat, endLat);
  1997. var CenterLon = centerLon;
  1998. var CenterLat = centerLat;
  1999. var EndLon = Math.Max(startLon, endLon);
  2000. var EndLat = Math.Max(startLat, endLat);
  2001. double centerLonNew = CenterLon % 360;
  2002. CenterLon = centerLonNew;
  2003. //double LonRange = Math.Round((EndLon - StartLon) / 2, 3);
  2004. //double LatRange = Math.Round((EndLat - StartLat) / 2, 3);
  2005. double LonRange = Math.Round((EndLon - StartLon), 3);
  2006. double LatRange = Math.Round((EndLat - StartLat), 3);
  2007. if (LonRange >= 360)
  2008. {
  2009. }
  2010. innerData.CurrentRect = (StartLon, StartLat, CenterLon, CenterLat, EndLon, EndLat, LonRange, LatRange);
  2011. innerData.mOnRectChanged?.Invoke(innerData.CurrentRect);
  2012. }
  2013. private static void ExportImg_ItemClick(object sender, ItemClickEventArgs e)
  2014. {
  2015. var ctrl = e.Item.Tag as MapControl;
  2016. using (var dialog = new SaveFileDialog())
  2017. {
  2018. dialog.Filter = "PNG图片|*.png";
  2019. dialog.AddExtension = true;
  2020. dialog.FileName = $"Map{DateTime.Now:yyyyMMddHHmmss}.png";
  2021. if (dialog.ShowDialog() == DialogResult.OK)
  2022. {
  2023. ctrl.ExportToImage(dialog.FileName, ImageFormat.Png);
  2024. }
  2025. }
  2026. }
  2027. private static void ExportCsv_ItemClick(object sender, ItemClickEventArgs e)
  2028. {
  2029. var ctrl = e.Item.Tag as MapControl;
  2030. using (var dialog = new SaveFileDialog())
  2031. {
  2032. dialog.Filter = "CSV文件|*.csv";
  2033. dialog.AddExtension = true;
  2034. dialog.FileName = $"Pos{DateTime.Now:yyyyMMddHHmmss}.xlsx";
  2035. if (dialog.ShowDialog() == DialogResult.OK)
  2036. {
  2037. ctrl.ExportToXlsx(dialog.FileName);
  2038. }
  2039. }
  2040. }
  2041. private static void ClearDrawObj(this MapControl ctrl)
  2042. {
  2043. ctrl.Invoke(new Action(() =>
  2044. {
  2045. try
  2046. {
  2047. var innerData = ctrl.Tag as InnerData;
  2048. ctrl.MapEditor.SetTransformMode(MapItemTransform.None);
  2049. innerData.drawingRect = false;
  2050. innerData.CurrentRect = (0, 0, 0, 0, 0, 0, 0, 0);
  2051. innerData.rangeItem = null;
  2052. if (innerData.mMapStorage != null && innerData.mMapStorage.Items.Any())
  2053. {
  2054. innerData.mMapStorage.Items.Clear();
  2055. }
  2056. if (innerData.trackStorge != null)
  2057. {
  2058. innerData.trackStorge.Items.Clear();
  2059. }
  2060. }
  2061. catch (Exception)
  2062. {
  2063. }
  2064. }));
  2065. }
  2066. private static void DistanceLine_ItemClick(object sender, ItemClickEventArgs e)
  2067. {
  2068. var ctrl = e.Item.Tag as MapControl;
  2069. var innerData = ctrl.Tag as InnerData;
  2070. ctrl.MapEditor.SetEditMode();
  2071. var items = innerData.mMapStorage.Items.ToArray();
  2072. foreach (var item in items)
  2073. {
  2074. if (item.Tag != null && item.Tag.ToString() == "DrawDistanceLine")
  2075. innerData.mMapStorage.Items.Remove(item);
  2076. }
  2077. if (innerData.distinctPath != null)
  2078. {
  2079. innerData.distinctPath.Points.Clear();
  2080. }
  2081. innerData.distinctPath = new MapPolyline()
  2082. {
  2083. Stroke = Color.FromArgb(127, 255, 0, 199),
  2084. StrokeWidth = 2,
  2085. IsGeodesic = true,
  2086. CanResize = false,
  2087. CanEdit = false,
  2088. CanRotate = false,
  2089. IsHitTestVisible = false,
  2090. CanMove = true,
  2091. Tag = "DrawDistanceLine"
  2092. };
  2093. innerData.mMapStorage.Items.Add(innerData.distinctPath);
  2094. innerData.hoverPoint = new MapDot() { CanResize = false, CanMove = false, IsHitTestVisible = false, Tag = "DrawDistanceLine", Size = 8 };
  2095. innerData.hoverPoint.Fill = ColorHelper.GetColor(innerData.hoverPoint.Tag.ToString());
  2096. innerData.mMapStorage.Items.Add(innerData.hoverPoint);
  2097. innerData.hoverTip = CreateHoverTip();
  2098. ctrl.MouseClick += AddDistinctPoint;
  2099. ctrl.MouseMove += MovingDistinct;
  2100. ctrl.MouseLeave += MapControl_MouseLeave;
  2101. ctrl.MouseEnter += MapControl_MouseEnter;
  2102. ctrl.DoubleClick += EndDistinct;
  2103. }
  2104. private static void ShowTrack_ItemClick(object sender, ItemClickEventArgs e)
  2105. {
  2106. var ctrl = e.Item.Tag as MapControl;
  2107. var innerData = ctrl.Tag as InnerData;
  2108. innerData.trackStorge.Items.Clear();
  2109. var posData = innerData._dataCache.Keys.OrderBy(p => p.SigTime);
  2110. var itemList = posData.GroupBy(t => t.ColorKey);
  2111. List<MapPolyline> listLine = new List<MapPolyline>();
  2112. int w = 12;
  2113. int h = 20;
  2114. if (ctrl.ZoomLevel < 4)
  2115. {
  2116. w = 2;
  2117. h = 4;
  2118. }
  2119. else if (ctrl.ZoomLevel < 6)
  2120. {
  2121. w = 6;
  2122. h = 12;
  2123. }
  2124. else
  2125. {
  2126. w = 10;
  2127. h = 20;
  2128. }
  2129. foreach (var groupItems in itemList)
  2130. {
  2131. var targets = groupItems.ToList();
  2132. var colorKey = targets.First().ColorKey;
  2133. for (int i = 0; i < targets.Count - 1; i++)
  2134. {
  2135. var line = new MapPolyline();
  2136. line.CanEdit = false;
  2137. line.CanMove = false;
  2138. line.CanResize = false;
  2139. line.CanRotate = false;
  2140. line.EnableSelection = DefaultBoolean.False;
  2141. line.EnableHighlighting = DefaultBoolean.False;
  2142. line.IsGeodesic = true;
  2143. line.Stroke = ColorHelper.IsHtmlColor(colorKey) ? ColorTranslator.FromHtml(colorKey) : ColorHelper.GetColor(colorKey);
  2144. line.EndLineCap.Width = w;
  2145. line.EndLineCap.Length = h;
  2146. line.EndLineCap.Visible = true;
  2147. line.EndLineCap.IsFilled = false;
  2148. line.StrokeWidth = 2;
  2149. //line.EndLineCap.Length = 100;
  2150. var p1 = new GeoPoint(targets[i].PosLat, targets[i].PosLon);
  2151. var p2 = new GeoPoint(targets[i + 1].PosLat, targets[i + 1].PosLon);
  2152. line.Points.Add(p1);
  2153. line.Points.Add(p2);
  2154. listLine.Add(line);
  2155. }
  2156. }
  2157. innerData.trackStorge.Items.AddRange(listLine);
  2158. }
  2159. private static void MarkDot_ItemClick(object sender, ItemClickEventArgs e)
  2160. {
  2161. var ctrl = e.Item.Tag as MapControl;
  2162. ctrl.MapEditor.SetTransformMode(MapItemTransform.None);
  2163. var innerData = ctrl.Tag as InnerData;
  2164. innerData.drawingRect = false;
  2165. using (var frm = new MapEditPointView())
  2166. {
  2167. if (frm.ShowDialog() != DialogResult.OK) return;
  2168. var locPoint = new GeoPoint(frm.Lat, frm.Lon);
  2169. MapCustomElement cusItem = new MapCustomElement()
  2170. {
  2171. Location = locPoint,
  2172. UseAnimation = true,
  2173. CanMove = false,
  2174. EnableHighlighting = DefaultBoolean.True,
  2175. EnableSelection = DefaultBoolean.False,
  2176. Text = "",
  2177. ToolTipPattern = $"{frm.Caption}",
  2178. SvgImage = SvgHelper.CreatePentagram("#F12233", 24, 24),
  2179. TextAlignment = DevExpress.XtraMap.TextAlignment.BottomCenter,
  2180. Tag = "DrawMarkDot"
  2181. };
  2182. innerData.mMapStorage.Items.Add(cusItem);
  2183. }
  2184. }
  2185. private static ToolTipControllerShowEventArgs CreateHoverTip()
  2186. {
  2187. ToolTipTitleItem titleItem1 = new ToolTipTitleItem() { Text = $"0千米" };
  2188. titleItem1.Appearance.ForeColor = SystemColors.GrayText;
  2189. titleItem1.Appearance.Font = new Font(AppearanceObject.DefaultFont.FontFamily, 12, FontStyle.Bold);
  2190. SuperToolTip superToolTip = new SuperToolTip();
  2191. superToolTip.Items.Add(titleItem1);
  2192. ToolTipSeparatorItem sepItem = new ToolTipSeparatorItem();
  2193. superToolTip.Items.Add(sepItem);
  2194. ToolTipItem textItem = new ToolTipItem() { Text = "单击添加测距点,双击结束测距" };
  2195. superToolTip.Items.Add(textItem);
  2196. ToolTipControllerShowEventArgs arg = new ToolTipControllerShowEventArgs();
  2197. arg.ShowBeak = true;
  2198. arg.SuperTip = superToolTip;
  2199. return arg;
  2200. }
  2201. private static void MapControl_MouseEnter(object sender, EventArgs e)
  2202. {
  2203. var innerData = (sender as MapControl).Tag as InnerData;
  2204. innerData.hoverPoint.Visible = true;
  2205. }
  2206. private static void MapControl_MouseLeave(object sender, EventArgs e)
  2207. {
  2208. var innerData = (sender as MapControl).Tag as InnerData;
  2209. innerData.hoverPoint.Visible = false;
  2210. }
  2211. private static void AddDistinctPoint(object sender, MouseEventArgs e)
  2212. {
  2213. var innerData = (sender as MapControl).Tag as InnerData;
  2214. var ctrl = sender as MapControl;
  2215. MapCallout disItem = new MapCallout { IsHitTestVisible = false, CanMove = false };
  2216. disItem.Location = ctrl.ScreenPointToCoordPoint(e.Location);
  2217. disItem.Text = $"{CalcLineKm(innerData):F2}千米";
  2218. disItem.Tag = "DrawDistanceLine";
  2219. innerData.mMapStorage.Items.Add(disItem);
  2220. innerData.distinctPath.Points.Add(innerData.hoverPoint.Location);
  2221. innerData.hoverPoint = new MapDot() { CanResize = false, CanMove = false, IsHitTestVisible = false, Tag = "DrawDistanceLine", Size = 8 };
  2222. innerData.hoverPoint.Location = ctrl.ScreenPointToCoordPoint(e.Location);
  2223. innerData.hoverPoint.Fill = ColorHelper.GetColor(innerData.hoverPoint.Tag.ToString());
  2224. innerData.mMapStorage.Items.Add(innerData.hoverPoint);
  2225. innerData.distinctPath.Points.Add(innerData.hoverPoint.Location);
  2226. }
  2227. private static void MovingDistinct(object sender, MouseEventArgs e)
  2228. {
  2229. var innerData = (sender as MapControl).Tag as InnerData;
  2230. var ctrl = sender as MapControl;
  2231. var itemPoint = ctrl.ScreenPointToCoordPoint(e.Location);
  2232. innerData.hoverPoint.Location = itemPoint;
  2233. if (innerData.distinctPath.Points.Count > 0)
  2234. {
  2235. ctrl.MapEditor.SetEditMode();
  2236. innerData.distinctPath.Points[innerData.distinctPath.Points.Count - 1] = itemPoint;
  2237. (innerData.hoverTip.SuperTip.Items[0] as ToolTipTitleItem).Text = $"{CalcLineKm(innerData):F2}千米";
  2238. innerData.mapToolTip.ShowHint(innerData.hoverTip, ctrl.PointToScreen(e.Location));
  2239. }
  2240. }
  2241. private static double CalcLineKm(InnerData data)
  2242. {
  2243. double result = 0;
  2244. if (data.distinctPath.Points.Count < 2) return result;
  2245. for (int i = 0; i < data.distinctPath.Points.Count - 1; i++)
  2246. {
  2247. var startPoint = data.distinctPath.Points[i] as GeoPoint;
  2248. var endPoint = data.distinctPath.Points[i + 1] as GeoPoint;
  2249. MapSize sizeInKm = new SphericalMercatorProjection().GeoToKilometersSize(startPoint, new MapSize(Math.Abs(startPoint.Longitude - endPoint.Longitude), Math.Abs(startPoint.Latitude - endPoint.Latitude)));
  2250. double partlength = Math.Sqrt(sizeInKm.Width * sizeInKm.Width + sizeInKm.Height * sizeInKm.Height);
  2251. result += partlength;
  2252. }
  2253. return result;
  2254. }
  2255. public static void ClearMap(this MapControl ctrl)
  2256. {
  2257. var innerData = ctrl.Tag as InnerData;
  2258. innerData.CurrentRect = (0, 0, 0, 0, 0, 0, 0, 0);
  2259. innerData.mMapStorage?.Items.Clear();
  2260. }
  2261. private static void EndDistinct(object sender, EventArgs e)
  2262. {
  2263. var ctrl = sender as MapControl;
  2264. var innerData = ctrl.Tag as InnerData;
  2265. innerData.mapToolTip.HideHint();
  2266. ctrl.MouseClick -= AddDistinctPoint;
  2267. ctrl.MouseMove -= MovingDistinct;
  2268. ctrl.DoubleClick -= EndDistinct;
  2269. ctrl.MouseLeave -= MapControl_MouseLeave;
  2270. ctrl.MouseEnter -= MapControl_MouseEnter;
  2271. }
  2272. class MapEditPointView : DevExpress.XtraEditors.XtraForm
  2273. {
  2274. private System.ComponentModel.IContainer components = null;
  2275. private DevExpress.XtraLayout.LayoutControl layoutControl1;
  2276. private DevExpress.XtraLayout.LayoutControlGroup Root;
  2277. private DevExpress.XtraLayout.LayoutControlItem layoutControlItem1;
  2278. private DevExpress.XtraLayout.EmptySpaceItem emptySpaceItem1;
  2279. private DevExpress.XtraLayout.LayoutControlItem layoutControlItem2;
  2280. private DevExpress.XtraEditors.ButtonEdit txtLon;
  2281. private DevExpress.XtraEditors.ButtonEdit txtLat;
  2282. private DevExpress.XtraEditors.TextEdit txtCaption;
  2283. private DevExpress.XtraLayout.LayoutControlItem layoutControlItem5;
  2284. private DevExpress.XtraEditors.SimpleButton btnCancel;
  2285. private DevExpress.XtraEditors.SimpleButton btnOk;
  2286. private DevExpress.XtraLayout.LayoutControlItem layoutControlItem3;
  2287. private DevExpress.XtraLayout.LayoutControlItem layoutControlItem6;
  2288. private DevExpress.XtraEditors.DXErrorProvider.DXErrorProvider dxErrorProvider1;
  2289. private DevExpress.XtraLayout.EmptySpaceItem emptySpaceItem2;
  2290. private void InitializeComponent()
  2291. {
  2292. this.components = new System.ComponentModel.Container();
  2293. DevExpress.XtraEditors.Controls.EditorButtonImageOptions editorButtonImageOptions1 = new DevExpress.XtraEditors.Controls.EditorButtonImageOptions();
  2294. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject1 = new DevExpress.Utils.SerializableAppearanceObject();
  2295. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject2 = new DevExpress.Utils.SerializableAppearanceObject();
  2296. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject3 = new DevExpress.Utils.SerializableAppearanceObject();
  2297. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject4 = new DevExpress.Utils.SerializableAppearanceObject();
  2298. DevExpress.XtraEditors.Controls.EditorButtonImageOptions editorButtonImageOptions2 = new DevExpress.XtraEditors.Controls.EditorButtonImageOptions();
  2299. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject5 = new DevExpress.Utils.SerializableAppearanceObject();
  2300. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject6 = new DevExpress.Utils.SerializableAppearanceObject();
  2301. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject7 = new DevExpress.Utils.SerializableAppearanceObject();
  2302. DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject8 = new DevExpress.Utils.SerializableAppearanceObject();
  2303. this.layoutControl1 = new DevExpress.XtraLayout.LayoutControl();
  2304. this.txtCaption = new DevExpress.XtraEditors.TextEdit();
  2305. this.txtLon = new DevExpress.XtraEditors.ButtonEdit();
  2306. this.txtLat = new DevExpress.XtraEditors.ButtonEdit();
  2307. this.Root = new DevExpress.XtraLayout.LayoutControlGroup();
  2308. this.layoutControlItem1 = new DevExpress.XtraLayout.LayoutControlItem();
  2309. this.emptySpaceItem1 = new DevExpress.XtraLayout.EmptySpaceItem();
  2310. this.layoutControlItem2 = new DevExpress.XtraLayout.LayoutControlItem();
  2311. this.layoutControlItem5 = new DevExpress.XtraLayout.LayoutControlItem();
  2312. this.btnOk = new DevExpress.XtraEditors.SimpleButton();
  2313. this.layoutControlItem3 = new DevExpress.XtraLayout.LayoutControlItem();
  2314. this.btnCancel = new DevExpress.XtraEditors.SimpleButton();
  2315. this.layoutControlItem6 = new DevExpress.XtraLayout.LayoutControlItem();
  2316. this.dxErrorProvider1 = new DevExpress.XtraEditors.DXErrorProvider.DXErrorProvider(this.components);
  2317. this.emptySpaceItem2 = new DevExpress.XtraLayout.EmptySpaceItem();
  2318. ((System.ComponentModel.ISupportInitialize)(this.layoutControl1)).BeginInit();
  2319. this.layoutControl1.SuspendLayout();
  2320. ((System.ComponentModel.ISupportInitialize)(this.txtCaption.Properties)).BeginInit();
  2321. ((System.ComponentModel.ISupportInitialize)(this.txtLon.Properties)).BeginInit();
  2322. ((System.ComponentModel.ISupportInitialize)(this.txtLat.Properties)).BeginInit();
  2323. ((System.ComponentModel.ISupportInitialize)(this.Root)).BeginInit();
  2324. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem1)).BeginInit();
  2325. ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem1)).BeginInit();
  2326. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem2)).BeginInit();
  2327. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem5)).BeginInit();
  2328. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem3)).BeginInit();
  2329. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem6)).BeginInit();
  2330. ((System.ComponentModel.ISupportInitialize)(this.dxErrorProvider1)).BeginInit();
  2331. ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem2)).BeginInit();
  2332. this.SuspendLayout();
  2333. //
  2334. // layoutControl1
  2335. //
  2336. this.layoutControl1.Controls.Add(this.btnCancel);
  2337. this.layoutControl1.Controls.Add(this.btnOk);
  2338. this.layoutControl1.Controls.Add(this.txtCaption);
  2339. this.layoutControl1.Controls.Add(this.txtLon);
  2340. this.layoutControl1.Controls.Add(this.txtLat);
  2341. this.layoutControl1.Dock = System.Windows.Forms.DockStyle.Fill;
  2342. this.layoutControl1.Location = new System.Drawing.Point(0, 0);
  2343. this.layoutControl1.Name = "layoutControl1";
  2344. this.layoutControl1.OptionsCustomizationForm.DesignTimeCustomizationFormPositionAndSize = new System.Drawing.Rectangle(689, 0, 650, 400);
  2345. this.layoutControl1.Root = this.Root;
  2346. this.layoutControl1.Size = new System.Drawing.Size(272, 208);
  2347. this.layoutControl1.TabIndex = 0;
  2348. this.layoutControl1.Text = "layoutControl1";
  2349. //
  2350. // txtCaption
  2351. //
  2352. this.txtCaption.Location = new System.Drawing.Point(12, 29);
  2353. this.txtCaption.Name = "txtCaption";
  2354. this.txtCaption.Properties.Appearance.Options.UseTextOptions = true;
  2355. this.txtCaption.Properties.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
  2356. this.txtCaption.Properties.AutoHeight = false;
  2357. this.txtCaption.Properties.MaxLength = 30;
  2358. this.txtCaption.Size = new System.Drawing.Size(248, 22);
  2359. this.txtCaption.StyleController = this.layoutControl1;
  2360. this.txtCaption.TabIndex = 9;
  2361. //
  2362. // txtLon
  2363. //
  2364. this.txtLon.Location = new System.Drawing.Point(12, 80);
  2365. this.txtLon.Name = "txtLon";
  2366. this.txtLon.Properties.Appearance.Options.UseTextOptions = true;
  2367. this.txtLon.Properties.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
  2368. this.txtLon.Properties.AutoHeight = false;
  2369. this.txtLon.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
  2370. 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)});
  2371. this.txtLon.Size = new System.Drawing.Size(248, 22);
  2372. this.txtLon.StyleController = this.layoutControl1;
  2373. this.txtLon.TabIndex = 4;
  2374. //
  2375. // txtLat
  2376. //
  2377. this.txtLat.Location = new System.Drawing.Point(12, 131);
  2378. this.txtLat.Name = "txtLat";
  2379. this.txtLat.Properties.Appearance.Options.UseTextOptions = true;
  2380. this.txtLat.Properties.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
  2381. this.txtLat.Properties.AutoHeight = false;
  2382. this.txtLat.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
  2383. 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)});
  2384. this.txtLat.Size = new System.Drawing.Size(248, 22);
  2385. this.txtLat.StyleController = this.layoutControl1;
  2386. this.txtLat.TabIndex = 5;
  2387. //
  2388. // Root
  2389. //
  2390. this.Root.EnableIndentsWithoutBorders = DevExpress.Utils.DefaultBoolean.True;
  2391. this.Root.GroupBordersVisible = false;
  2392. this.Root.Items.AddRange(new DevExpress.XtraLayout.BaseLayoutItem[] {
  2393. this.layoutControlItem1,
  2394. this.emptySpaceItem1,
  2395. this.layoutControlItem5,
  2396. this.layoutControlItem2,
  2397. this.layoutControlItem3,
  2398. this.layoutControlItem6,
  2399. this.emptySpaceItem2});
  2400. this.Root.Name = "Root";
  2401. this.Root.Size = new System.Drawing.Size(272, 208);
  2402. this.Root.TextVisible = false;
  2403. //
  2404. // layoutControlItem1
  2405. //
  2406. this.layoutControlItem1.Control = this.txtLon;
  2407. this.layoutControlItem1.Location = new System.Drawing.Point(0, 43);
  2408. this.layoutControlItem1.MaxSize = new System.Drawing.Size(0, 51);
  2409. this.layoutControlItem1.MinSize = new System.Drawing.Size(54, 51);
  2410. this.layoutControlItem1.Name = "layoutControlItem1";
  2411. this.layoutControlItem1.Padding = new DevExpress.XtraLayout.Utils.Padding(2, 2, 10, 2);
  2412. this.layoutControlItem1.Size = new System.Drawing.Size(252, 51);
  2413. this.layoutControlItem1.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2414. this.layoutControlItem1.Text = "经度";
  2415. this.layoutControlItem1.TextLocation = DevExpress.Utils.Locations.Top;
  2416. this.layoutControlItem1.TextSize = new System.Drawing.Size(24, 14);
  2417. //
  2418. // emptySpaceItem1
  2419. //
  2420. this.emptySpaceItem1.AllowHotTrack = false;
  2421. this.emptySpaceItem1.Location = new System.Drawing.Point(0, 162);
  2422. this.emptySpaceItem1.MaxSize = new System.Drawing.Size(0, 26);
  2423. this.emptySpaceItem1.MinSize = new System.Drawing.Size(104, 26);
  2424. this.emptySpaceItem1.Name = "emptySpaceItem1";
  2425. this.emptySpaceItem1.Size = new System.Drawing.Size(113, 26);
  2426. this.emptySpaceItem1.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2427. this.emptySpaceItem1.TextSize = new System.Drawing.Size(0, 0);
  2428. //
  2429. // layoutControlItem2
  2430. //
  2431. this.layoutControlItem2.Control = this.txtLat;
  2432. this.layoutControlItem2.Location = new System.Drawing.Point(0, 94);
  2433. this.layoutControlItem2.MaxSize = new System.Drawing.Size(0, 51);
  2434. this.layoutControlItem2.MinSize = new System.Drawing.Size(54, 51);
  2435. this.layoutControlItem2.Name = "layoutControlItem2";
  2436. this.layoutControlItem2.Padding = new DevExpress.XtraLayout.Utils.Padding(2, 2, 10, 2);
  2437. this.layoutControlItem2.Size = new System.Drawing.Size(252, 51);
  2438. this.layoutControlItem2.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2439. this.layoutControlItem2.Text = "纬度";
  2440. this.layoutControlItem2.TextLocation = DevExpress.Utils.Locations.Top;
  2441. this.layoutControlItem2.TextSize = new System.Drawing.Size(24, 14);
  2442. //
  2443. // layoutControlItem5
  2444. //
  2445. this.layoutControlItem5.Control = this.txtCaption;
  2446. this.layoutControlItem5.Location = new System.Drawing.Point(0, 0);
  2447. this.layoutControlItem5.MaxSize = new System.Drawing.Size(0, 43);
  2448. this.layoutControlItem5.MinSize = new System.Drawing.Size(54, 43);
  2449. this.layoutControlItem5.Name = "layoutControlItem5";
  2450. this.layoutControlItem5.Size = new System.Drawing.Size(252, 43);
  2451. this.layoutControlItem5.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2452. this.layoutControlItem5.Text = "标题";
  2453. this.layoutControlItem5.TextLocation = DevExpress.Utils.Locations.Top;
  2454. this.layoutControlItem5.TextSize = new System.Drawing.Size(24, 14);
  2455. //
  2456. // btnOk
  2457. //
  2458. this.btnOk.Location = new System.Drawing.Point(125, 174);
  2459. this.btnOk.Name = "btnOk";
  2460. this.btnOk.Size = new System.Drawing.Size(65, 22);
  2461. this.btnOk.StyleController = this.layoutControl1;
  2462. this.btnOk.TabIndex = 10;
  2463. this.btnOk.Text = "确定";
  2464. this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
  2465. //
  2466. // layoutControlItem3
  2467. //
  2468. this.layoutControlItem3.Control = this.btnOk;
  2469. this.layoutControlItem3.Location = new System.Drawing.Point(113, 162);
  2470. this.layoutControlItem3.MaxSize = new System.Drawing.Size(69, 26);
  2471. this.layoutControlItem3.MinSize = new System.Drawing.Size(69, 26);
  2472. this.layoutControlItem3.Name = "layoutControlItem3";
  2473. this.layoutControlItem3.Size = new System.Drawing.Size(69, 26);
  2474. this.layoutControlItem3.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2475. this.layoutControlItem3.TextSize = new System.Drawing.Size(0, 0);
  2476. this.layoutControlItem3.TextVisible = false;
  2477. //
  2478. // btnCancel
  2479. //
  2480. this.btnCancel.Location = new System.Drawing.Point(194, 174);
  2481. this.btnCancel.Name = "btnCancel";
  2482. this.btnCancel.Size = new System.Drawing.Size(66, 22);
  2483. this.btnCancel.StyleController = this.layoutControl1;
  2484. this.btnCancel.TabIndex = 11;
  2485. this.btnCancel.Text = "取消";
  2486. this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
  2487. //
  2488. // layoutControlItem6
  2489. //
  2490. this.layoutControlItem6.Control = this.btnCancel;
  2491. this.layoutControlItem6.Location = new System.Drawing.Point(182, 162);
  2492. this.layoutControlItem6.MaxSize = new System.Drawing.Size(70, 26);
  2493. this.layoutControlItem6.MinSize = new System.Drawing.Size(70, 26);
  2494. this.layoutControlItem6.Name = "layoutControlItem6";
  2495. this.layoutControlItem6.Size = new System.Drawing.Size(70, 26);
  2496. this.layoutControlItem6.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2497. this.layoutControlItem6.TextSize = new System.Drawing.Size(0, 0);
  2498. this.layoutControlItem6.TextVisible = false;
  2499. //
  2500. // dxErrorProvider1
  2501. //
  2502. this.dxErrorProvider1.ContainerControl = this;
  2503. //
  2504. // emptySpaceItem2
  2505. //
  2506. this.emptySpaceItem2.AllowHotTrack = false;
  2507. this.emptySpaceItem2.Location = new System.Drawing.Point(0, 145);
  2508. this.emptySpaceItem2.MinSize = new System.Drawing.Size(104, 1);
  2509. this.emptySpaceItem2.Name = "emptySpaceItem2";
  2510. this.emptySpaceItem2.Size = new System.Drawing.Size(252, 17);
  2511. this.emptySpaceItem2.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
  2512. this.emptySpaceItem2.TextSize = new System.Drawing.Size(0, 0);
  2513. //
  2514. // MapEditPointView
  2515. //
  2516. this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
  2517. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  2518. this.ClientSize = new System.Drawing.Size(272, 208);
  2519. this.Controls.Add(this.layoutControl1);
  2520. this.IconOptions.ShowIcon = false;
  2521. this.MaximizeBox = false;
  2522. this.MinimizeBox = false;
  2523. this.Name = "MapEditPointView";
  2524. this.ShowInTaskbar = false;
  2525. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  2526. this.Text = "标点";
  2527. ((System.ComponentModel.ISupportInitialize)(this.layoutControl1)).EndInit();
  2528. this.layoutControl1.ResumeLayout(false);
  2529. ((System.ComponentModel.ISupportInitialize)(this.txtCaption.Properties)).EndInit();
  2530. ((System.ComponentModel.ISupportInitialize)(this.txtLon.Properties)).EndInit();
  2531. ((System.ComponentModel.ISupportInitialize)(this.txtLat.Properties)).EndInit();
  2532. ((System.ComponentModel.ISupportInitialize)(this.Root)).EndInit();
  2533. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem1)).EndInit();
  2534. ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem1)).EndInit();
  2535. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem2)).EndInit();
  2536. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem5)).EndInit();
  2537. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem3)).EndInit();
  2538. ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem6)).EndInit();
  2539. ((System.ComponentModel.ISupportInitialize)(this.dxErrorProvider1)).EndInit();
  2540. ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem2)).EndInit();
  2541. this.ResumeLayout(false);
  2542. }
  2543. protected override void Dispose(bool disposing)
  2544. {
  2545. if (disposing && (components != null))
  2546. {
  2547. components.Dispose();
  2548. }
  2549. base.Dispose(disposing);
  2550. }
  2551. public MapEditPointView()
  2552. {
  2553. InitializeComponent();
  2554. }
  2555. public string Caption
  2556. {
  2557. get
  2558. {
  2559. return txtCaption.Text.Trim();
  2560. }
  2561. set
  2562. {
  2563. txtCaption.Text = value;
  2564. }
  2565. }
  2566. public double Lon
  2567. {
  2568. get
  2569. {
  2570. return double.Parse(txtLon.Text.Trim());
  2571. }
  2572. set
  2573. {
  2574. txtLon.Text = value.ToString();
  2575. }
  2576. }
  2577. public double Lat
  2578. {
  2579. get
  2580. {
  2581. return double.Parse(txtLat.Text.Trim());
  2582. }
  2583. set
  2584. {
  2585. txtLat.Text = value.ToString();
  2586. }
  2587. }
  2588. private void btnOk_Click(object sender, EventArgs e)
  2589. {
  2590. dxErrorProvider1.ClearErrors();
  2591. double lon, lat;
  2592. if (!double.TryParse(txtLon.Text, out lon))
  2593. {
  2594. dxErrorProvider1.SetError(txtLon, "请设置正确的经度");
  2595. return;
  2596. }
  2597. if (!double.TryParse(txtLat.Text, out lat))
  2598. {
  2599. dxErrorProvider1.SetError(txtLat, "请设置正确的纬度");
  2600. return;
  2601. }
  2602. if (lon < -180 || lon > 180)
  2603. {
  2604. dxErrorProvider1.SetError(txtLon, "经度范围[-180,180]");
  2605. return;
  2606. }
  2607. if (lat < -90 || lat > 90)
  2608. {
  2609. dxErrorProvider1.SetError(txtLat, "纬度范围[-90,90]");
  2610. return;
  2611. }
  2612. this.DialogResult = DialogResult.OK;
  2613. }
  2614. private void btnCancel_Click(object sender, EventArgs e)
  2615. {
  2616. this.DialogResult = DialogResult.Cancel;
  2617. }
  2618. }
  2619. #endregion
  2620. #region 半径圆
  2621. public class MyLatLng
  2622. {
  2623. public double Rc = 6378137; //赤道半径
  2624. public double Rj = 6356725; //极半径
  2625. public double m_LoDeg, m_LoMin, m_LoSec;
  2626. public double m_LaDeg, m_LaMin, m_LaSec;
  2627. public double m_Longitude, m_Latitude;
  2628. public double m_RadLo, m_RadLa;
  2629. public double Ec;
  2630. public double Ed;
  2631. public MyLatLng(double longitude, double latitude)
  2632. {
  2633. m_LoDeg = (int)longitude;
  2634. m_LoMin = (int)((longitude - m_LoDeg) * 60);
  2635. m_LoSec = (longitude - m_LoDeg - m_LoMin / 60) * 3600;
  2636. m_LaDeg = (int)latitude;
  2637. m_LaMin = (int)((latitude - m_LaDeg) * 60);
  2638. m_LaSec = (latitude - m_LaDeg - m_LaMin / 60) * 3600;
  2639. m_Longitude = longitude;
  2640. m_Latitude = latitude;
  2641. m_RadLo = longitude * Math.PI / 180;
  2642. m_RadLa = latitude * Math.PI / 180;
  2643. Ec = Rj + (Rc - Rj) * (90 - m_Latitude) / 90;
  2644. Ed = Ec * Math.Cos(m_RadLa);
  2645. }
  2646. }
  2647. #endregion
  2648. #region ImageLayer数据源接口实现(本地和Http接口)
  2649. class ImageTileSource : IImageTileSource
  2650. {
  2651. SQLiteConnection con;
  2652. public ImageTileSource()
  2653. {
  2654. var files = Directory.GetFiles(Application.StartupPath, "Data.gmdb", SearchOption.AllDirectories);
  2655. if (files.Length > 0)
  2656. {
  2657. try
  2658. {
  2659. conStr = string.Format(conStr, files[0]);
  2660. con = new SQLiteConnection(conStr);
  2661. con.Open();
  2662. }
  2663. catch
  2664. {
  2665. conStr = null;
  2666. Console.WriteLine("Data.gmdb文件读取出错!");
  2667. }
  2668. }
  2669. else
  2670. {
  2671. conStr = null;
  2672. }
  2673. }
  2674. public string Name => "GMap地图瓦片";
  2675. public bool CanDisposeSourceImage => true;
  2676. public Image GetImage(int x, int y, int level, Size size)
  2677. {
  2678. var data = QueryTile(x, y, level, 0);
  2679. if (data == null) return null;
  2680. return Image.FromStream(new MemoryStream(data));
  2681. }
  2682. 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})";
  2683. string conStr = "Data Source=\"{0}\";Page Size=32768";
  2684. byte[] QueryTile(int x, int y, int zoom, int type)
  2685. {
  2686. if (conStr == null) return null;
  2687. type = (int)mMapType;
  2688. if (type == 0) type = 1818940751;
  2689. using (DbCommand com = con.CreateCommand())
  2690. {
  2691. com.CommandText = string.Format(QuerySql, x, y, zoom, type);
  2692. using (DbDataReader rd = com.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
  2693. {
  2694. if (rd.Read())
  2695. {
  2696. long length = rd.GetBytes(0, 0, null, 0, 0);
  2697. byte[] tile = new byte[length];
  2698. rd.GetBytes(0, 0, tile, 0, tile.Length);
  2699. return tile;
  2700. }
  2701. }
  2702. }
  2703. return null;
  2704. }
  2705. }
  2706. class HttpMapDataProvider : MapDataProviderBase
  2707. {
  2708. public HttpMapDataProvider()
  2709. {
  2710. TileSource = new HttpTileSource(this);
  2711. }
  2712. public override MapSize GetMapSizeInPixels(double zoomLevel)
  2713. {
  2714. double imageSize;
  2715. imageSize = HttpTileSource.CalculateTotalImageSize(zoomLevel);
  2716. return new MapSize(imageSize, imageSize);
  2717. }
  2718. protected override Size BaseSizeInPixels
  2719. {
  2720. get { return new Size(Convert.ToInt32(HttpTileSource.tileSize * 2), Convert.ToInt32(HttpTileSource.tileSize * 2)); }
  2721. }
  2722. }
  2723. class HttpTileSource : MapTileSourceBase
  2724. {
  2725. public const int tileSize = 256;
  2726. public const int maxZoomLevel = 14;
  2727. public string HttpServerAddr { get; set; }
  2728. public EnumWmtsSource WmtsSource { get; set; }
  2729. public EnumMapLayerType LayerType { get; set; }
  2730. public string LayerName { get; set; }
  2731. public GoogleMapType MapType { get; set; } = GoogleMapType.Normal;
  2732. internal static double CalculateTotalImageSize(double zoomLevel)
  2733. {
  2734. if (zoomLevel < 1.0)
  2735. return zoomLevel * tileSize * 2;
  2736. return Math.Pow(2.0, zoomLevel) * tileSize;
  2737. }
  2738. public HttpTileSource(ICacheOptionsProvider cacheOptionsProvider) :
  2739. base((int)CalculateTotalImageSize(maxZoomLevel), (int)CalculateTotalImageSize(maxZoomLevel), tileSize, tileSize, cacheOptionsProvider)
  2740. {
  2741. }
  2742. public override Uri GetTileByZoomLevel(int zoomLevel, int tilePositionX, int tilePositionY)
  2743. {
  2744. if (string.IsNullOrWhiteSpace(HttpServerAddr)) return null;
  2745. try
  2746. {
  2747. if (zoomLevel <= maxZoomLevel)
  2748. {
  2749. string imgUrl = string.Empty;
  2750. if (WmtsSource == EnumWmtsSource.SJZX)
  2751. {
  2752. imgUrl = $"{HttpServerAddr}?lyr={LayerName}&x={tilePositionX}&y={tilePositionY}&z={zoomLevel}";
  2753. }
  2754. else
  2755. {
  2756. string suffix = ".png";
  2757. if (LayerType == EnumMapLayerType.SatMap)
  2758. {
  2759. suffix = ".jpg";
  2760. }
  2761. imgUrl = $"{HttpServerAddr}/{LayerName}/{zoomLevel}/{tilePositionX}/{tilePositionY}{suffix}";
  2762. }
  2763. //string imgUrl = string.Format("http://192.168.0.214:58089/{0}/{1}/{2}/{3}", (int)GoogleMapType.Normal, zoomLevel, tilePositionX, tilePositionY);
  2764. Uri u = new Uri(imgUrl);
  2765. return u;
  2766. }
  2767. return null;
  2768. }
  2769. catch
  2770. {
  2771. Console.WriteLine($"加载地图数据出错,无法连接到{HttpServerAddr}");
  2772. return null;
  2773. }
  2774. }
  2775. }
  2776. #endregion
  2777. //定位点聚合器
  2778. class PosClusterer : IClusterer
  2779. {
  2780. private MapControl ctrl;
  2781. private IMapDataAdapter owner;
  2782. private MapViewport preViewPoint;
  2783. private DebounceDispatcher dispatcher = new DebounceDispatcher();
  2784. public bool IsBusy { get; private set; }
  2785. public MapItemCollection Items { get; private set; }
  2786. public PosClusterer(MapControl ctrl)
  2787. {
  2788. this.ctrl = ctrl;
  2789. }
  2790. public void SetOwner(IMapDataAdapter owner)
  2791. {
  2792. this.owner = owner;
  2793. Items = new MapItemCollection(owner);
  2794. }
  2795. public void Clusterize(IEnumerable<MapItem> sourceItems, MapViewport viewport, bool sourceChanged)
  2796. {
  2797. IsBusy = true;
  2798. if (sourceChanged)
  2799. DoClusterize(sourceItems, viewport, sourceChanged);
  2800. else
  2801. dispatcher.Debounce(100, () => DoClusterize(sourceItems, viewport, sourceChanged));
  2802. }
  2803. private void DoClusterize(IEnumerable<MapItem> sourceItems, MapViewport viewport, bool sourceChanged)
  2804. {
  2805. if (preViewPoint == null)
  2806. {
  2807. preViewPoint = viewport;
  2808. return;
  2809. }
  2810. if (!sourceChanged && preViewPoint.ZoomLevel == viewport.ZoomLevel)//地图移动或者MapControl大小发生了改变时直接操作Items避免闪烁
  2811. {
  2812. preViewPoint = viewport;
  2813. }
  2814. else//地图进行了缩放
  2815. {
  2816. Items.Clear();
  2817. var cache = new Dictionary<int, List<MapItem>>();
  2818. foreach (MapDot item in sourceItems)
  2819. {
  2820. var point = ctrl.CoordPointToScreenPoint(item.Location);
  2821. int pointX = (int)point.X;
  2822. int pointY = (int)point.Y;
  2823. bool visible = true;
  2824. if (pointX <= _dotSize || pointX > ctrl.Width - _dotSize)
  2825. visible = false;
  2826. else if (pointY <= _dotSize || pointY > ctrl.Height - _dotSize)
  2827. visible = false;
  2828. pointX /= (_dotSize * 2);
  2829. pointY /= (_dotSize * 2);
  2830. var key = pointX << 16 | pointY;
  2831. if (!visible)
  2832. key = -key;
  2833. if (!cache.ContainsKey(key))
  2834. cache.Add(key, new List<MapItem>());
  2835. cache[key].Add(item);
  2836. }
  2837. var innerData = ctrl.Tag as InnerData;
  2838. innerData._clusterCache.Clear();
  2839. LinkedList<MapItem> temp = new LinkedList<MapItem>();
  2840. foreach (var kv in cache)
  2841. {
  2842. var firstDot = kv.Value[0] as MapDot;
  2843. var firstObj = firstDot.Tag as PosData;
  2844. firstDot.Size = kv.Value.Count > 1 ? _dotSize + 2 : _dotSize;
  2845. firstObj.ClusterCount = kv.Value.Count;
  2846. firstObj.ClusterKey = kv.Key;
  2847. innerData._clusterCache.Add(kv.Key, firstDot);
  2848. temp.AddLast(firstDot);
  2849. }
  2850. Items.AddRange(temp);
  2851. cache.Clear();
  2852. preViewPoint = viewport;
  2853. owner.OnClustered();
  2854. }
  2855. this.IsBusy = false;
  2856. }
  2857. //计算多个坐标的中心位置
  2858. public GeoPoint GetCenterPointFromListOfCoordinates(List<MapItem> geoCoordinateList)
  2859. {
  2860. int total = geoCoordinateList.Count;
  2861. double lat = 0, lon = 0;
  2862. foreach (MapDot g in geoCoordinateList)
  2863. {
  2864. lat += (g.Location as GeoPoint).Latitude * Math.PI / 180;
  2865. lon += (g.Location as GeoPoint).Longitude * Math.PI / 180;
  2866. }
  2867. lat /= total;
  2868. lon /= total;
  2869. return new GeoPoint(lat * 180 / Math.PI, lon * 180 / Math.PI);
  2870. }
  2871. }
  2872. }
  2873. class MyLatLng
  2874. {
  2875. static double Rc = 6378137;
  2876. static double Rj = 6356725;
  2877. double m_LoDeg, m_LoMin, m_LoSec;
  2878. double m_LaDeg, m_LaMin, m_LaSec;
  2879. double m_Longitude, m_Latitude;
  2880. double m_RadLo, m_RadLa;
  2881. double Ec;
  2882. double Ed;
  2883. public MyLatLng(double longitude, double latitude)
  2884. {
  2885. m_LoDeg = (int)longitude;
  2886. m_LoMin = (int)((longitude - m_LoDeg) * 60);
  2887. m_LoSec = (longitude - m_LoDeg - m_LoMin / 60) * 3600;
  2888. m_LaDeg = (int)latitude;
  2889. m_LaMin = (int)((latitude - m_LaDeg) * 60);
  2890. m_LaSec = (latitude - m_LaDeg - m_LaMin / 60) * 3600;
  2891. m_Longitude = longitude;
  2892. m_Latitude = latitude;
  2893. m_RadLo = longitude * Math.PI / 180;
  2894. m_RadLa = latitude * Math.PI / 180;
  2895. Ec = Rj + (Rc - Rj) * (90 - m_Latitude) / 90;
  2896. Ed = Ec * Math.Cos(m_RadLa);
  2897. }
  2898. }