|
@@ -82,7 +82,7 @@ public static class MapControlEx
|
|
|
internal MapDot hoverPoint;
|
|
|
internal ToolTipControllerShowEventArgs hoverTip;
|
|
|
internal ToolTipController mapToolTip;
|
|
|
- internal MapItemStorage posStorge;
|
|
|
+ internal MapItemStorage flightStorge;
|
|
|
internal MapRectangle rangeItem;
|
|
|
internal MapDot dotItem = new MapDot() { Tag = "DrawRect" };
|
|
|
internal bool drawingRect = false;
|
|
@@ -270,7 +270,7 @@ public static class MapControlEx
|
|
|
if (!selectPos.Selected)
|
|
|
{
|
|
|
selectPos.Selected = true;
|
|
|
- ctrl.UpdatePosItem(selectPos);
|
|
|
+ //ctrl.UpdatePosItem(selectPos);
|
|
|
}
|
|
|
if (selectPos.ClusterCount == 1)
|
|
|
{
|
|
@@ -300,7 +300,7 @@ public static class MapControlEx
|
|
|
if (!selectPos.Selected)
|
|
|
{
|
|
|
selectPos.Selected = true;
|
|
|
- ctrl.UpdatePosItem(selectPos);
|
|
|
+ //ctrl.UpdatePosItem(selectPos);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -383,16 +383,16 @@ public static class MapControlEx
|
|
|
innerData.mMapStorageFixed = drawDataStorageFixed;
|
|
|
|
|
|
|
|
|
- //定位点专用PosLayer
|
|
|
- var layerPos = new VectorItemsLayer() { Name = "PosLayer" };
|
|
|
- layerPos.ToolTipPattern = "Test";//随便给一个,不然不会显示定位点的tooltip
|
|
|
- layerPos.AllowEditItems = true;
|
|
|
- layerPos.EnableHighlighting = false;
|
|
|
- layerPos.EnableSelection = false;
|
|
|
- ctrl.Layers.Add(layerPos);
|
|
|
- var posStorge = new MapItemStorage();
|
|
|
- layerPos.Data = posStorge;
|
|
|
- innerData.posStorge = posStorge;
|
|
|
+ //定位点专用FlightLayer
|
|
|
+ var layerFlight = new VectorItemsLayer() { Name = "FlightLayer" };
|
|
|
+ layerFlight.ToolTipPattern = "Test";//随便给一个,不然不会显示定位点的tooltip
|
|
|
+ layerFlight.AllowEditItems = true;
|
|
|
+ layerFlight.EnableHighlighting = false;
|
|
|
+ layerFlight.EnableSelection = false;
|
|
|
+ ctrl.Layers.Add(layerFlight);
|
|
|
+ var flightStorge = new MapItemStorage();
|
|
|
+ layerFlight.Data = flightStorge;
|
|
|
+ innerData.flightStorge = flightStorge;
|
|
|
return ctrl;
|
|
|
}
|
|
|
/// <summary>
|
|
@@ -490,212 +490,6 @@ public static class MapControlEx
|
|
|
}
|
|
|
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 重新设置定位数据
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="T"></typeparam>
|
|
|
- /// <param name="items">数据源(指定null或空集合可以清空已有数据)</param>
|
|
|
- /// <param name="clearDrawLayer">是否清除DrawLayer上临时绘制的内容</param>
|
|
|
- public static void SetPosDataSource<T>(this MapControl ctrl, IEnumerable<T> items, bool clearDrawLayer = true) where T : PosData, new()
|
|
|
- {
|
|
|
- var innerData = ctrl.Tag as InnerData;
|
|
|
- innerData._dataCache.Clear();
|
|
|
- if (clearDrawLayer)
|
|
|
- ctrl.ClearDrawObj();
|
|
|
- innerData.posStorge.Items.Clear();
|
|
|
- if (items == null || !items.Any())
|
|
|
- {
|
|
|
- ctrl.Refresh();
|
|
|
- return;
|
|
|
- }
|
|
|
- List<MapDot> list = new List<MapDot>();
|
|
|
- for (int i = 0; i < items.Count(); i++)
|
|
|
- {
|
|
|
- var p = items.ElementAt(i);
|
|
|
- if (p.PosLon > 180) continue;
|
|
|
- var mapItem = new MapDot()
|
|
|
- {
|
|
|
- EnableHighlighting = DefaultBoolean.True,
|
|
|
- EnableSelection = DefaultBoolean.False,
|
|
|
- CanMove = false,
|
|
|
- Visible = p.Visible,
|
|
|
- IsHitTestVisible = true,
|
|
|
- Fill = ColorHelper.IsHtmlColor(p.ColorKey) ? ColorTranslator.FromHtml(p.ColorKey) : ColorHelper.GetColor(p.ColorKey),
|
|
|
- Size = _dotSize,
|
|
|
- Tag = items.ElementAt(i),
|
|
|
- Location = new GeoPoint(p.PosLat, p.PosLon)
|
|
|
- };
|
|
|
- list.Add(mapItem);
|
|
|
- innerData._dataCache.Add(p, mapItem);
|
|
|
- }
|
|
|
- innerData.posStorge.Items.AddRange(list);
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 定位图层数据源添加一个定位点
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="T"></typeparam>
|
|
|
- /// <param name="item"></param>
|
|
|
- public static void AddPosItem<T>(this MapControl ctrl, T item) where T : PosData, new()
|
|
|
- {
|
|
|
- if (item.PosLon > 180) return;
|
|
|
- var innerData = ctrl.Tag as InnerData;
|
|
|
- var mapItem = new MapDot()
|
|
|
- {
|
|
|
- EnableHighlighting = DefaultBoolean.True,
|
|
|
- EnableSelection = DefaultBoolean.False,
|
|
|
- CanMove = false,
|
|
|
- Visible = item.Visible,
|
|
|
- IsHitTestVisible = true,
|
|
|
- Fill = ColorHelper.IsHtmlColor(item.ColorKey) ? ColorTranslator.FromHtml(item.ColorKey) : ColorHelper.GetColor(item.ColorKey),
|
|
|
- Size = _dotSize,
|
|
|
- Tag = item,
|
|
|
- Location = new GeoPoint(item.PosLat, item.PosLon)
|
|
|
- };
|
|
|
- innerData._dataCache.Add(item, mapItem);
|
|
|
- innerData.posStorge.Items.Add(mapItem);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 定位图层数据源删除定位点
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="T"></typeparam>
|
|
|
- /// <param name="ctrl"></param>
|
|
|
- /// <param name="data"></param>
|
|
|
- public static void DelPosItem<T>(this MapControl ctrl, IEnumerable<T> data) where T : PosData, new()
|
|
|
- {
|
|
|
- if (data == null || !data.Any()) return;
|
|
|
- foreach (var item in data)
|
|
|
- {
|
|
|
- ctrl.DelPosItem(item);
|
|
|
- }
|
|
|
- ctrl.Refresh();
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 定位图层数据源删除定位点
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="T"></typeparam>
|
|
|
- /// <param name="ctrl"></param>
|
|
|
- /// <param name="data"></param>
|
|
|
- public static void DelPosItem<T>(this MapControl ctrl, T item) where T : PosData, new()
|
|
|
- {
|
|
|
- if (item == null) return;
|
|
|
- var innerData = ctrl.Tag as InnerData;
|
|
|
- if (innerData._dataCache.ContainsKey(item))
|
|
|
- {
|
|
|
- innerData.posStorge.Items.Remove(innerData._dataCache[item]);
|
|
|
- innerData._dataCache.Remove(item);
|
|
|
- }
|
|
|
- ctrl.Refresh();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 定位图层数据源删除定位点
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="T"></typeparam>
|
|
|
- /// <param name="ctrl"></param>
|
|
|
- /// <param name="data"></param>
|
|
|
- public static void DelPosItem<T>(this MapControl ctrl, Func<T, bool> predicate) where T : PosData, new()
|
|
|
- {
|
|
|
- var innerData = ctrl.Tag as InnerData;
|
|
|
- List<PosData> keys = new List<PosData>();
|
|
|
- foreach (var item in innerData._dataCache.Keys)
|
|
|
- {
|
|
|
- if (predicate((T)item))
|
|
|
- keys.Add(item);
|
|
|
-
|
|
|
- }
|
|
|
- foreach (var item in keys)
|
|
|
- {
|
|
|
- ctrl.DelPosItem(item);
|
|
|
- }
|
|
|
- ctrl.Refresh();
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 更新定位数据(可以更新可见性、颜色、经纬度、选中状态)
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="T"></typeparam>
|
|
|
- /// <param name="ctrl"></param>
|
|
|
- /// <param name="item"></param>
|
|
|
- /// <param name="setCenter">是否将这个点设置到地图中心显示</param>
|
|
|
- public static void UpdatePosItem<T>(this MapControl ctrl, T item, bool setCenter = false) where T : PosData, new()
|
|
|
- {
|
|
|
- if (item == null) return;
|
|
|
- var innerData = ctrl.Tag as InnerData;
|
|
|
- if (innerData._dataCache.ContainsKey(item))
|
|
|
- {
|
|
|
- var mapDot = innerData._dataCache[item] as MapDot;
|
|
|
- mapDot.Visible = item.Visible;//外部修改了可见性
|
|
|
- mapDot.Fill = ColorHelper.IsHtmlColor(item.ColorKey) ? ColorTranslator.FromHtml(item.ColorKey) : ColorHelper.GetColor(item.ColorKey);//外部修改了颜色
|
|
|
- mapDot.Location = new GeoPoint(item.PosLat, item.PosLon);//外部修改了位置
|
|
|
- if (mapDot.Size != (item.Selected ? _selectedDotSize : _dotSize))//外部修改了选中状态
|
|
|
- {
|
|
|
- mapDot.Size = item.Selected ? _selectedDotSize : _dotSize;
|
|
|
- mapDot.StrokeWidth = item.Selected ? 0 : 1;
|
|
|
- if (item.ClusterCount > 1)
|
|
|
- {
|
|
|
- if (innerData._clusterCache.TryGetValue(item.ClusterKey, out MapItem clusterItem))
|
|
|
- {
|
|
|
- (clusterItem as MapDot).Size = item.Selected ? _selectedDotSize : _dotSize;
|
|
|
- }
|
|
|
- }
|
|
|
- if (mapDot.ClusteredItems.Any())
|
|
|
- (mapDot.ClusteredItems[0] as MapDot).Size = _selectedDotSize;
|
|
|
- if (item.Selected)
|
|
|
- {
|
|
|
- //让选中的Item在上层
|
|
|
- var idx = innerData.posStorge.Items.IndexOf(mapDot);
|
|
|
- innerData.posStorge.Items.Swap(idx, innerData.posStorge.Items.Count - 1);
|
|
|
- //innerData.posStorge.Items.Add(mapDot);
|
|
|
-
|
|
|
- //需要将上次选中的点设置为未选中
|
|
|
- if (innerData.preSelectedItem != null)
|
|
|
- {
|
|
|
- innerData.preSelectedItem.Size = _dotSize;
|
|
|
- (innerData.preSelectedItem.Tag as PosData).Selected = false;
|
|
|
- if ((innerData.preSelectedItem.Tag as PosData).ClusterCount > 1)
|
|
|
- {
|
|
|
- if (innerData._clusterCache.TryGetValue((innerData.preSelectedItem.Tag as PosData).ClusterKey, out MapItem clusterItem))
|
|
|
- {
|
|
|
- (clusterItem as MapDot).Size = _dotSize + 2;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- innerData.preSelectedItem = mapDot;
|
|
|
- }
|
|
|
- }
|
|
|
- if (setCenter && item.Visible)
|
|
|
- ctrl.SetCenterPoint(item.PosLon, item.PosLat, false);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 更新定位数据(可以更新可见性、颜色、经纬度)
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="T"></typeparam>
|
|
|
- /// <param name="ctrl"></param>
|
|
|
- /// <param name="item"></param>
|
|
|
- public static void UpdatePosItem<T>(this MapControl ctrl, IEnumerable<T> items) where T : PosData, new()
|
|
|
- {
|
|
|
- if (items == null || !items.Any()) return;
|
|
|
- var innerData = ctrl.Tag as InnerData;
|
|
|
- foreach (var item in items)
|
|
|
- {
|
|
|
- if (innerData._dataCache.ContainsKey(item))
|
|
|
- {
|
|
|
- var mapDot = innerData._dataCache[item] as MapDot;
|
|
|
- mapDot.Visible = item.Visible;//外部修改了可见性
|
|
|
- mapDot.Fill = ColorHelper.IsHtmlColor(item.ColorKey) ? ColorTranslator.FromHtml(item.ColorKey) : ColorHelper.GetColor(item.ColorKey);//外部修改了颜色
|
|
|
- mapDot.Location = new GeoPoint(item.PosLat, item.PosLon);//外部修改了位置
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// 设置地图中心点
|
|
|
/// </summary>
|
|
@@ -798,17 +592,7 @@ public static class MapControlEx
|
|
|
return ctrl;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 定位点使用内置聚合器
|
|
|
- /// </summary>
|
|
|
- /// <param name="ctrl"></param>
|
|
|
- /// <returns></returns>
|
|
|
- public static MapControl UseCluster(this MapControl ctrl)
|
|
|
- {
|
|
|
- var innerData = ctrl.Tag as InnerData;
|
|
|
- innerData.posStorge.Clusterer = new PosClusterer(ctrl);//定位点聚合器
|
|
|
- return ctrl;
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
/// <summary>
|
|
|
/// 为地图添加右键测距功能
|
|
@@ -857,7 +641,7 @@ public static class MapControlEx
|
|
|
|
|
|
string filghtName = $"DrawFlightLine{caption}";
|
|
|
ctrl.MapEditor.SetEditMode();
|
|
|
- var items = innerData.mMapStorage.Items.ToArray();
|
|
|
+ var items = innerData.flightStorge.Items.ToArray();
|
|
|
innerData.flightpath = new MapSpline()
|
|
|
{
|
|
|
Stroke = Color.FromArgb(127, 255, 0, 199),
|
|
@@ -870,10 +654,10 @@ public static class MapControlEx
|
|
|
Tag = filghtName
|
|
|
|
|
|
};
|
|
|
- innerData.mMapStorage.Items.Add(innerData.flightpath);
|
|
|
+ innerData.flightStorge.Items.Add(innerData.flightpath);
|
|
|
innerData.hoverPoint = new MapDot() { CanResize = false, CanMove = false, Tag = filghtName, Size = 8 };
|
|
|
innerData.hoverPoint.Fill = ColorHelper.GetColor(innerData.hoverPoint.Tag.ToString());
|
|
|
- innerData.mMapStorage.Items.Add(innerData.hoverPoint);
|
|
|
+ innerData.flightStorge.Items.Add(innerData.hoverPoint);
|
|
|
//提示框
|
|
|
SuperToolTip superToolTip = new SuperToolTip();
|
|
|
ToolTipItem textItem = new ToolTipItem() { Text = "单击添加航迹点,双击结束绘制航迹" };
|
|
@@ -915,11 +699,11 @@ public static class MapControlEx
|
|
|
{
|
|
|
|
|
|
var innerData = ctrl.Tag as InnerData;
|
|
|
- var items = innerData.mMapStorage.Items.ToArray();
|
|
|
+ var items = innerData.flightStorge.Items.ToArray();
|
|
|
foreach (var item in items)
|
|
|
{
|
|
|
if (item.Tag != null && item.Tag.ToString().Contains("DrawDistanceLine"))
|
|
|
- innerData.mMapStorage.Items.Remove(item);
|
|
|
+ innerData.flightStorge.Items.Remove(item);
|
|
|
}
|
|
|
if (innerData.distinctPath != null)
|
|
|
{
|
|
@@ -942,10 +726,10 @@ public static class MapControlEx
|
|
|
Tag = filghtName
|
|
|
|
|
|
};
|
|
|
- innerData.mMapStorage.Items.Add(innerData.flightpath);
|
|
|
+ innerData.flightStorge.Items.Add(innerData.flightpath);
|
|
|
innerData.hoverPoint = new MapDot() { CanResize = false, CanMove = false, Tag = filghtName, Size = 8 };
|
|
|
innerData.hoverPoint.Fill = ColorHelper.GetColor(innerData.hoverPoint.Tag.ToString());
|
|
|
- innerData.mMapStorage.Items.Add(innerData.hoverPoint);
|
|
|
+ innerData.flightStorge.Items.Add(innerData.hoverPoint);
|
|
|
//提示框
|
|
|
SuperToolTip superToolTip = new SuperToolTip();
|
|
|
ToolTipItem textItem = new ToolTipItem() { Text = "单击添加航迹点,双击结束绘制航迹" };
|
|
@@ -998,7 +782,7 @@ public static class MapControlEx
|
|
|
};
|
|
|
innerData.hoverPoint.Location = location;
|
|
|
innerData.hoverPoint.Fill = ColorHelper.GetColor(innerData.hoverPoint.Tag.ToString());
|
|
|
- innerData.mMapStorage.Items.Add(innerData.hoverPoint);
|
|
|
+ innerData.flightStorge.Items.Add(innerData.hoverPoint);
|
|
|
innerData.flightpath.Points.Add(innerData.hoverPoint.Location);
|
|
|
if (!innerData._flightCache[Name].flights.Any(m => m.FlightLon == lon && m.FlightLat == lat))
|
|
|
{
|
|
@@ -1012,6 +796,10 @@ public static class MapControlEx
|
|
|
innerData._flightCache.Clear();
|
|
|
if (clearDrawLayer)
|
|
|
ctrl.ClearDrawObj();
|
|
|
+ if (innerData.flightStorge != null && innerData.flightStorge.Items.Any())
|
|
|
+ {
|
|
|
+ innerData.flightStorge.Items.Clear();
|
|
|
+ }
|
|
|
if (items == null || !items.Any())
|
|
|
{
|
|
|
ctrl.Refresh();
|
|
@@ -1042,10 +830,10 @@ public static class MapControlEx
|
|
|
Tag = filghtName
|
|
|
|
|
|
};
|
|
|
- innerData.mMapStorage.Items.Add(flightpath);
|
|
|
+ innerData.flightStorge.Items.Add(flightpath);
|
|
|
var hoverPoint = new MapDot() { CanResize = false, CanMove = false, Tag = filghtName, Size = 8 };
|
|
|
hoverPoint.Fill = ColorHelper.GetColor(hoverPoint.Tag.ToString());
|
|
|
- innerData.mMapStorage.Items.Add(hoverPoint);
|
|
|
+ innerData.flightStorge.Items.Add(hoverPoint);
|
|
|
if (flight.flights.Count > 0)
|
|
|
{
|
|
|
var center = new GeoPoint(flight.flights.First().FlightLat, flight.flights.First().FlightLon);
|
|
@@ -1067,7 +855,7 @@ public static class MapControlEx
|
|
|
};
|
|
|
hoverPointj.Location = location;
|
|
|
hoverPointj.Fill = ColorHelper.GetColor(hoverPointj.Tag.ToString());
|
|
|
- innerData.mMapStorage.Items.Add(hoverPointj);
|
|
|
+ innerData.flightStorge.Items.Add(hoverPointj);
|
|
|
flightpath.Points.Add(hoverPointj.Location);
|
|
|
Thread.Sleep(1000);
|
|
|
});
|
|
@@ -1595,307 +1383,7 @@ public static class MapControlEx
|
|
|
if (recCallback)
|
|
|
innerData.mOnRectChanged?.Invoke(ctrl.GetCurrentRect());
|
|
|
}
|
|
|
- public static void DrawDtoPonit(this MapControl ctrl, string title, IEnumerable<(double lon, double lat)> lines)
|
|
|
- {
|
|
|
- string identify = "DrawPoint_";
|
|
|
- if (lines == null || !lines.Any()) return;
|
|
|
- var innerData = ctrl.Tag as InnerData;
|
|
|
-
|
|
|
- List<MapDot> list = new List<MapDot>();
|
|
|
- var color = ColorHelper.GetColor(title);
|
|
|
- for (int i = 0; i < lines.Count(); i++)
|
|
|
- {
|
|
|
- var p = lines.ElementAt(i);
|
|
|
- if (p.lon < -180 || p.lon > 180) continue;
|
|
|
- if (p.lon == 0 && p.lon == 0) continue;
|
|
|
- var mapItem = new MapDot()
|
|
|
- {
|
|
|
- EnableHighlighting = DefaultBoolean.True,
|
|
|
- EnableSelection = DefaultBoolean.False,
|
|
|
- CanMove = false,
|
|
|
- Visible = true,
|
|
|
- IsHitTestVisible = true,
|
|
|
- Fill = color,
|
|
|
- Size = 4,
|
|
|
- Tag = $"{identify}{title}{lines.ElementAt(i).lon}",
|
|
|
- Location = new GeoPoint(p.lat, p.lon),
|
|
|
- ToolTipPattern = $"{title}",
|
|
|
-
|
|
|
- };
|
|
|
- list.Add(mapItem);
|
|
|
- }
|
|
|
-
|
|
|
- if (!list.Any()) return;
|
|
|
- innerData.mMapStorage.Items.AddRange(list);
|
|
|
- }
|
|
|
- public static void DrawGdopLine(this MapControl ctrl, IEnumerable<(string wcKm, double lon, double lat)> lines)
|
|
|
- {
|
|
|
- if (lines == null || !lines.Any()) return;
|
|
|
- var innerData = ctrl.Tag as InnerData;
|
|
|
- var wcKm = lines.First().wcKm;
|
|
|
- var polyLine = new MapPolyline()
|
|
|
- {
|
|
|
- Stroke = ColorHelper.GetColor(wcKm),
|
|
|
- StrokeWidth = 2,
|
|
|
- IsGeodesic = true,
|
|
|
- CanResize = false,
|
|
|
- CanEdit = false,
|
|
|
- CanRotate = false,
|
|
|
- IsHitTestVisible = true,
|
|
|
- CanMove = false,
|
|
|
- Tag = $"DrawGdopLine_{wcKm}",
|
|
|
- };
|
|
|
- polyLine.TitleOptions.Pattern = wcKm;
|
|
|
- foreach (var item in lines)
|
|
|
- {
|
|
|
- if (double.IsNaN(item.lat) || double.IsNaN(item.lon)) continue;
|
|
|
- polyLine.Points.Add(new GeoPoint(item.lat, item.lon));
|
|
|
- }
|
|
|
- if (!polyLine.Points.Any()) return;
|
|
|
- innerData.mMapStorage.Items.Add(polyLine);
|
|
|
- }
|
|
|
- /// <summary>
|
|
|
- /// 绘制线
|
|
|
- /// </summary>
|
|
|
- /// <param name="ctrl"></param>
|
|
|
- /// <param name="title"></param>
|
|
|
- /// <param name="lines"></param>
|
|
|
- /// <param name="isClear">是否清除上次绘制</param>
|
|
|
- public static void DrawCXLine(this MapControl ctrl, string title, IEnumerable<(double lon, double lat)> lines, bool isClear = true)
|
|
|
- {
|
|
|
- string identify = "DrawCXLine_";
|
|
|
- if (lines == null || !lines.Any()) return;
|
|
|
- var innerData = ctrl.Tag as InnerData;
|
|
|
- if (isClear)
|
|
|
- {
|
|
|
- var mapItem = innerData.mMapStorage.Items.Find(m => m.Tag.ToString().StartsWith(identify));
|
|
|
- if (mapItem != null)
|
|
|
- {
|
|
|
- innerData.mMapStorage.Items.Remove(mapItem);
|
|
|
- }
|
|
|
- }
|
|
|
- var polyLine = new MapPolyline()
|
|
|
- {
|
|
|
- Stroke = Color.Red,
|
|
|
- StrokeWidth = 3,
|
|
|
- CanMove = false,
|
|
|
- Visible = true,
|
|
|
- IsHitTestVisible = true,
|
|
|
- Tag = $"{identify}{title}",
|
|
|
- ToolTipPattern = title,
|
|
|
-
|
|
|
- };
|
|
|
- foreach (var item in lines)
|
|
|
- {
|
|
|
- if (double.IsNaN(item.lat) || double.IsNaN(item.lon)) continue;
|
|
|
- polyLine.Points.Add(new GeoPoint(item.lat, item.lon));
|
|
|
- }
|
|
|
- if (!polyLine.Points.Any()) return;
|
|
|
- innerData.mMapStorage.Items.Add(polyLine);
|
|
|
- }
|
|
|
- public static void DrawErrEllipse(this MapControl ctrl, double r1, double r2, IEnumerable<(double lon, double lat)> lines)
|
|
|
- {
|
|
|
- if (lines == null || !lines.Any()) return;
|
|
|
- var innerData = ctrl.Tag as InnerData;
|
|
|
- //innerData.mMapStorage.Items.Clear();
|
|
|
- var polyLine = new MapPolyline()
|
|
|
- {
|
|
|
- Stroke = Color.Red,
|
|
|
- StrokeWidth = 4,
|
|
|
- IsGeodesic = true,
|
|
|
- CanResize = false,
|
|
|
- CanEdit = false,
|
|
|
- CanRotate = false,
|
|
|
- IsHitTestVisible = true,
|
|
|
- CanMove = false,
|
|
|
- Tag = $"DrawErrEllipse",
|
|
|
- };
|
|
|
- //polyLine.ToolTipPattern = $"长轴:{r1:f1}km\r\n短轴:{r2:f1}km";
|
|
|
- foreach (var item in lines)
|
|
|
- {
|
|
|
- if (double.IsNaN(item.lat) || double.IsNaN(item.lon)) continue;
|
|
|
- polyLine.Points.Add(new GeoPoint(item.lat, item.lon));
|
|
|
- }
|
|
|
- if (!polyLine.Points.Any()) return;
|
|
|
- innerData.mMapStorage.Items.Add(polyLine);
|
|
|
- var callout = new DevExpress.XtraMap.MapCallout()
|
|
|
- {
|
|
|
- Text = $"R1={r1:f1}km\r\nR2={r2:f1}km",
|
|
|
- Location = polyLine.Points.First(),
|
|
|
- CanMove = false,
|
|
|
- IsHitTestVisible = false,
|
|
|
- };
|
|
|
- innerData.mMapStorage.Items.Add(callout);
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 绘制GDOP多条线 两个点绘制一个线段 1和2一个线段 3和4一个线段
|
|
|
- /// </summary>
|
|
|
- /// <param name="ctrl"></param>
|
|
|
- /// <param name="wcKm"></param>
|
|
|
- /// <param name="dots"></param>
|
|
|
- /// <param name="patterncount"></param>
|
|
|
- public static void DrawGdopLineTwo(this MapControl ctrl, string wcKm, IEnumerable<(double lon, double lat)> dots, int patterncount)
|
|
|
- {
|
|
|
- if (dots == null || !dots.Any()) return;
|
|
|
- string identify = "DrawGdopLine_";
|
|
|
- var innerData = ctrl.Tag as InnerData;
|
|
|
- //多条线 两个点绘制一个线段 1和2一个线段 3和4一个线段
|
|
|
- List<MapPolyline> polylines = new List<MapPolyline>();
|
|
|
- int index = 0;
|
|
|
- int count = dots.Count();
|
|
|
-
|
|
|
- MapPolyline polyLine = null;
|
|
|
- foreach (var item in dots)
|
|
|
- {
|
|
|
- if (index % 2 == 0)
|
|
|
- {
|
|
|
- if (polyLine != null)//添加线段
|
|
|
- {
|
|
|
- polylines.Add(polyLine);
|
|
|
- }
|
|
|
- polyLine = new MapPolyline()
|
|
|
- {
|
|
|
- Stroke = ColorHelper.GetColor(wcKm),
|
|
|
- StrokeWidth = 2,
|
|
|
- IsGeodesic = true,
|
|
|
- CanResize = false,
|
|
|
- CanEdit = false,
|
|
|
- CanRotate = false,
|
|
|
- IsHitTestVisible = true,
|
|
|
- CanMove = false,
|
|
|
- Tag = $"{identify}{wcKm}",
|
|
|
- };
|
|
|
-
|
|
|
- }
|
|
|
- polyLine.Points.Add(new GeoPoint(item.lat, item.lon));
|
|
|
- if (patterncount == index)//提示公里信息
|
|
|
- {
|
|
|
- polyLine.TitleOptions.Pattern = wcKm;
|
|
|
- }
|
|
|
- index++;
|
|
|
- if (index == count)//添加最后一个线段
|
|
|
- {
|
|
|
- polylines.Add(polyLine);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- if (!polyLine.Points.Any()) return;
|
|
|
- innerData.mMapStorage.Items.AddRange(polylines);
|
|
|
-
|
|
|
- }
|
|
|
- /// <summary>
|
|
|
- /// 绘制半径圆
|
|
|
- /// </summary>
|
|
|
- /// <param name="ctrl"></param>
|
|
|
- /// <param name="lat"></param>
|
|
|
- /// <param name="lon"></param>
|
|
|
- /// <param name="radius"></param>
|
|
|
- public static void DrawRadiusRound(this MapControl ctrl, double lat, double lon, int radius)
|
|
|
- {
|
|
|
- var innerData = ctrl.Tag as InnerData;
|
|
|
- try
|
|
|
- {
|
|
|
- if (radius <= 0)
|
|
|
- return;
|
|
|
-
|
|
|
- CoordPointCollection latLngs = new CoordPointCollection();
|
|
|
- MyLatLng centerLatLng = new MyLatLng(lon, lat);
|
|
|
-
|
|
|
- // 0 - 360度 寻找半径为radius,圆心为centerP的圆上点的经纬度
|
|
|
- for (int i = 0; i < 360; i++)
|
|
|
- {
|
|
|
- //获取目标经纬度
|
|
|
- MyLatLng tempLatLng = getMyLatLng(centerLatLng, radius, i);
|
|
|
- //将自定义的经纬度类 转换成 标准经纬度类
|
|
|
- CoordPoint p = new GeoPoint(tempLatLng.m_Latitude, tempLatLng.m_Longitude);
|
|
|
- latLngs.Add(p);
|
|
|
- }
|
|
|
-
|
|
|
- //安全性检查
|
|
|
- if (latLngs.Count < 20)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- //通过绘制多边形的方式绘制圆
|
|
|
- MapPolygon gpol = new MapPolygon();
|
|
|
- gpol.Points = latLngs;
|
|
|
- gpol.Stroke = Color.Red;
|
|
|
- gpol.Fill = Color.FromArgb(50, Color.Red);
|
|
|
- gpol.IsHitTestVisible = true;
|
|
|
- innerData.mMapStorageFixed.Items.Add(gpol);
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- //Dialog.Error(ex);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 度 转换成 弧度
|
|
|
- /// </summary>
|
|
|
- /// <param name="degrees"></param>
|
|
|
- /// <returns></returns>
|
|
|
- public static double DegreesToRadians(double degrees)
|
|
|
- {
|
|
|
- const double degToRadFactor = Math.PI / 180;
|
|
|
- return degrees * degToRadFactor;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 计算两个点之间的距离
|
|
|
- /// </summary>
|
|
|
- /// <param name="startlon">开始经度</param>
|
|
|
- /// <param name="startlat">开始纬度</param>
|
|
|
- /// <param name="endlon">结束经度</param>
|
|
|
- /// <param name="endlat">结束纬度</param>
|
|
|
- /// <returns></returns>
|
|
|
- public static double CalcLineKm(double startlon, double startlat, double endlon, double endlat)
|
|
|
- {
|
|
|
- GeoPoint startPoint = new GeoPoint() { Longitude = startlon, Latitude = startlat };
|
|
|
- GeoPoint endPoint = new GeoPoint() { Longitude = endlon, Latitude = endlat };
|
|
|
- double result = 0;
|
|
|
- MapSize sizeInKm = new SphericalMercatorProjection().GeoToKilometersSize(startPoint, new MapSize(Math.Abs(startPoint.Longitude - endPoint.Longitude), Math.Abs(startPoint.Latitude - endPoint.Latitude)));
|
|
|
- result = Math.Sqrt(sizeInKm.Width * sizeInKm.Width + sizeInKm.Height * sizeInKm.Height);
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 计算方向线坐标
|
|
|
- /// </summary>
|
|
|
- /// <param name="lon">经度</param>
|
|
|
- /// <param name="lat">纬度</param>
|
|
|
- /// <param name="deg"> 艏向角 角度制</param>
|
|
|
- /// <param name="dis">长度 m</param>
|
|
|
- /// <returns></returns>
|
|
|
- public static (double, double) CalcSituation(double lon, double lat, double deg, double dis)
|
|
|
- {
|
|
|
- double arc = 6371.393 * 1000; //地球平均半径
|
|
|
- double rad = deg * (Math.PI / 180); //角度转弧度
|
|
|
- double c_lng = lon + dis * Math.Sin(rad) / (arc * Math.Cos(lat) * 2 * Math.PI / 360);
|
|
|
-
|
|
|
- double c_lat = lat + dis * Math.Cos(rad) / (arc * 2 * Math.PI / 360);
|
|
|
-
|
|
|
- return (c_lng, c_lat); //方向上的另一点坐标
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 求B点经纬度
|
|
|
- * @param A 已知点的经纬度,
|
|
|
- * @param distance AB两地的距离 单位km
|
|
|
- * @param angle AB连线与正北方向的夹角(0~360)
|
|
|
- * @return B点的经纬度
|
|
|
-*/
|
|
|
- private static MyLatLng getMyLatLng(MyLatLng A, double distance, double angle)
|
|
|
- {
|
|
|
- double dx = distance * 1000 * Math.Sin(DegreesToRadians(angle));
|
|
|
- double dy = distance * 1000 * Math.Cos(DegreesToRadians(angle));
|
|
|
-
|
|
|
- double bjd = (dx / A.Ed + A.m_RadLo) * 180 / Math.PI;
|
|
|
- double bwd = (dy / A.Ec + A.m_RadLa) * 180 / Math.PI;
|
|
|
- return new MyLatLng(bjd, bwd);
|
|
|
- }
|
|
|
+
|
|
|
public static void ClearRect(this MapControl ctrl)
|
|
|
{
|
|
|
var innerDate = ctrl.Tag as InnerData;
|
|
@@ -2074,7 +1562,6 @@ public static class MapControlEx
|
|
|
if (innerData.mMapStorage != null && innerData.mMapStorage.Items.Any())
|
|
|
{
|
|
|
innerData.mMapStorage.Items.Clear();
|
|
|
- innerData._flightCache.Clear();
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|