Skip to content

Commit 56dc42c

Browse files
committedOct 13, 2022
FlightData: cleanup CameraOverlap on disable
NoFly: add location filter
1 parent 5cb5939 commit 56dc42c

File tree

2 files changed

+108
-57
lines changed

2 files changed

+108
-57
lines changed
 

‎GCSViews/FlightData.cs

+12-4
Original file line numberDiff line numberDiff line change
@@ -4239,16 +4239,24 @@ void NoFly_NoFlyEvent(object sender, NoFly.NoFly.NoFlyEventArgs e)
42394239
{
42404240
BeginInvoke((Action) delegate
42414241
{
4242-
foreach (var poly in e.NoFlyZones.Polygons)
4243-
{
4244-
kmlpolygons.Polygons.Add(poly);
4245-
}
4242+
gMapControl1.Overlays.Add(e.NoFlyZones);
42464243
});
42474244
}
42484245

42494246
private void onOffCameraOverlapToolStripMenuItem_Click(object sender, EventArgs e)
42504247
{
42514248
CameraOverlap = onOffCameraOverlapToolStripMenuItem.Checked;
4249+
4250+
foreach (var mark in photosoverlay.Markers.ToArray())
4251+
{
4252+
if (mark is GMapMarkerPhoto)
4253+
{
4254+
if (!CameraOverlap)
4255+
{
4256+
photosoverlay.Markers.Remove(mark);
4257+
}
4258+
}
4259+
}
42524260
}
42534261

42544262
void POI_POIModified(object sender, EventArgs e)

‎NoFly/NoFly.cs

+96-53
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace MissionPlanner.NoFly
1515
{
1616
public class NoFly
1717
{
18+
private const int proximity = 100000;
19+
1820
static GMapOverlay kmlpolygonsoverlay = new GMapOverlay();
1921

2022
private static string directory = Settings.GetRunningDirectory() + "NoFly";
@@ -72,38 +74,48 @@ public static void Scan()
7274

7375
var nfzinfo = Utilities.nfz.HK.LoadNFZ().Result;
7476

75-
if (nfzinfo != null && nfzinfo.Type == GeoJSONObjectType.FeatureCollection)
76-
{
77-
foreach (var item in nfzinfo.Features)
77+
if (nfzinfo != null)
78+
UpdateNoFlyZoneEvent += (sender, args) =>
7879
{
79-
if (item.Type == GeoJSONObjectType.Feature)
80+
if (nfzinfo.Type == GeoJSONObjectType.FeatureCollection)
8081
{
81-
if (item.Geometry.Type == GeoJSONObjectType.Polygon)
82+
foreach (var item in nfzinfo.Features)
8283
{
83-
var poly = (GeoJSON.Net.Geometry.Polygon)item.Geometry;
84-
var coordinates =
85-
poly.Coordinates[0].Coordinates.OfType<GeoJSON.Net.Geometry.Position>()
86-
.Select(c => new PointLatLng(c.Latitude, c.Longitude))
87-
.ToList();
88-
89-
var name = item.Properties["name"];
90-
var desc = item.Properties["description"];
91-
92-
GMapPolygon nfzpolygon = new GMapPolygon(coordinates, name.ToString());
93-
nfzpolygon.Tag = item;
94-
95-
nfzpolygon.Stroke.Color = Color.Purple;
96-
97-
nfzpolygon.Fill = new SolidBrush(Color.FromArgb(30, Color.Blue));
98-
99-
MainV2.instance.BeginInvoke(new Action(() =>
84+
if (item.Type == GeoJSONObjectType.Feature)
10085
{
101-
kmlpolygonsoverlay.Polygons.Add(nfzpolygon);
102-
}));
86+
if (item.Geometry.Type == GeoJSONObjectType.Polygon)
87+
{
88+
var poly = (GeoJSON.Net.Geometry.Polygon)item.Geometry;
89+
var coordinates =
90+
poly.Coordinates[0].Coordinates.OfType<GeoJSON.Net.Geometry.Position>()
91+
.Select(c => new PointLatLng(c.Latitude, c.Longitude))
92+
.ToList();
93+
94+
var close = coordinates.Any(a => a.ToPLLA(0).GetDistance(args) < 100000);
95+
if (!close)
96+
continue;
97+
98+
var name = item.Properties["name"];
99+
var desc = item.Properties["description"];
100+
101+
GMapPolygon nfzpolygon = new GMapPolygon(coordinates, "HK"+name.ToString());
102+
nfzpolygon.Tag = item;
103+
104+
nfzpolygon.Stroke.Color = Color.Purple;
105+
106+
nfzpolygon.Fill = new SolidBrush(Color.FromArgb(30, Color.Blue));
107+
108+
MainV2.instance.BeginInvoke(new Action(() =>
109+
{
110+
if (kmlpolygonsoverlay.Polygons.Any(a => a.Name == "HK" + name.ToString()))
111+
return;
112+
kmlpolygonsoverlay.Polygons.Add(nfzpolygon);
113+
}));
114+
}
115+
}
103116
}
104117
}
105-
}
106-
}
118+
};
107119
}
108120
catch
109121
{
@@ -119,46 +131,72 @@ public static void Scan()
119131
var nfzinfo = Utilities.nfz.EU.LoadNFZ().Result;
120132

121133
if (nfzinfo != null)
122-
foreach (var feat in nfzinfo.Features)
134+
UpdateNoFlyZoneEvent += (sender, args) =>
123135
{
124-
foreach (var item in feat.Geometry)
136+
foreach (var feat in nfzinfo.Features)
125137
{
126-
if (item.HorizontalProjection?.Type == "Polygon")
138+
foreach (var item in feat.Geometry)
127139
{
128-
if (item.LowerVerticalReference == "AGL" && item.UomDimensions == "M" && item.LowerLimit > 300)
129-
continue;
140+
if (item.HorizontalProjection?.Type == "Polygon")
141+
{
142+
//if (item.LowerVerticalReference == "AGL" && item.UomDimensions == "M" && item.LowerLimit > 300)
143+
//continue;
130144

131-
var coordinates = item.HorizontalProjection.Coordinates[0].Select(c => new PointLatLng(c[1], c[0])).ToList();
145+
var coordinates = item.HorizontalProjection.Coordinates[0].Select(c => new PointLatLng(c[1], c[0])).ToList();
132146

133-
GMapPolygon nfzpolygon = new GMapPolygon(coordinates, feat.Name);
147+
var close = coordinates.Any(a => a.ToPLLA(item.LowerLimit).GetDistance(args) < 100000);
148+
if (!close)
149+
continue;
134150

135-
nfzpolygon.Tag = item;
151+
GMapPolygon nfzpolygon = new GMapPolygon(coordinates, feat.Name);
136152

137-
nfzpolygon.Stroke.Color = Color.Purple;
153+
nfzpolygon.Tag = item;
138154

139-
nfzpolygon.Fill = new SolidBrush(Color.FromArgb(30, Color.Blue));
155+
nfzpolygon.Stroke.Color = Color.Purple;
140156

141-
MainV2.instance.BeginInvoke(new Action(() =>
142-
{
143-
kmlpolygonsoverlay.Polygons.Add(nfzpolygon);
144-
}));
145-
}
146-
else if (item.HorizontalProjection?.Type == "Circle")
147-
{
148-
var coordinates = new PointLatLng(item.HorizontalProjection.Center[1], item.HorizontalProjection.Center[0]);
157+
nfzpolygon.Fill = new SolidBrush(Color.FromArgb(30, Color.Blue));
149158

150-
GMapMarkerAirport nfzcircle = new GMapMarkerAirport(coordinates);
151-
nfzcircle.wprad = (int)(item.HorizontalProjection.Radius ?? 0);
152-
nfzcircle.Tag = feat;
159+
nfzpolygon.IsHitTestVisible = true;
160+
/*
161+
nfzpolygon.ToolTipMode = MarkerTooltipMode.OnMouseOver;
162+
nfzpolygon.ToolTipText = feat.Name + "\r\n" + feat.Message;
163+
*/
164+
if (kmlpolygonsoverlay.Control.IsMouseOverPolygon) {
153165

154-
MainV2.instance.BeginInvoke(new Action(() =>
166+
}
167+
MainV2.instance.BeginInvoke(new Action(() =>
168+
{
169+
if (kmlpolygonsoverlay.Polygons.Any(a => a.Name == feat.Name))
170+
return;
171+
kmlpolygonsoverlay.Polygons.Add(nfzpolygon);
172+
}));
173+
}
174+
else if (item.HorizontalProjection?.Type == "Circle")
155175
{
156-
kmlpolygonsoverlay.Markers.Add(nfzcircle);
157-
}));
176+
var coordinates = new PointLatLng(item.HorizontalProjection.Center[1], item.HorizontalProjection.Center[0]);
177+
178+
var close = coordinates.ToPLLA(item.LowerLimit).GetDistance(args) < proximity;
179+
if (!close)
180+
continue;
181+
182+
GMapMarkerAirport nfzcircle = new GMapMarkerAirport(coordinates);
183+
nfzcircle.wprad = (int)(item.HorizontalProjection.Radius ?? 0);
184+
nfzcircle.Tag = feat;
185+
nfzcircle.IsHitTestVisible = true;
186+
nfzcircle.ToolTipMode = MarkerTooltipMode.OnMouseOver;
187+
nfzcircle.ToolTipText = feat.Name +"\r\n"+ feat.Message;
188+
189+
MainV2.instance.BeginInvoke(new Action(() =>
190+
{
191+
if (kmlpolygonsoverlay.Markers.Any(a => ((Utilities.nfz.Feature)a.Tag).Name == feat.Name))
192+
return;
193+
kmlpolygonsoverlay.Markers.Add(nfzcircle);
194+
}));
195+
}
158196
}
159-
}
160197

161-
}
198+
}
199+
};
162200
}
163201
catch
164202
{
@@ -168,9 +206,14 @@ public static void Scan()
168206
NoFlyEvent(null, new NoFlyEventArgs(kmlpolygonsoverlay));
169207
}
170208

209+
static PointLatLngAlt lastUpdateLocation = PointLatLngAlt.Zero;
171210
public static void UpdateNoFlyZone(object sender, PointLatLngAlt plla)
172211
{
173-
UpdateNoFlyZoneEvent?.Invoke(sender, plla);
212+
if (plla.GetDistance(lastUpdateLocation) > 100)
213+
{
214+
UpdateNoFlyZoneEvent?.Invoke(sender, plla);
215+
lastUpdateLocation = plla;
216+
}
174217
}
175218

176219
public static event EventHandler<PointLatLngAlt> UpdateNoFlyZoneEvent;

0 commit comments

Comments
 (0)
Please sign in to comment.