@@ -15,6 +15,8 @@ namespace MissionPlanner.NoFly
15
15
{
16
16
public class NoFly
17
17
{
18
+ private const int proximity = 100000 ;
19
+
18
20
static GMapOverlay kmlpolygonsoverlay = new GMapOverlay ( ) ;
19
21
20
22
private static string directory = Settings . GetRunningDirectory ( ) + "NoFly" ;
@@ -72,38 +74,48 @@ public static void Scan()
72
74
73
75
var nfzinfo = Utilities . nfz . HK . LoadNFZ ( ) . Result ;
74
76
75
- if ( nfzinfo != null && nfzinfo . Type == GeoJSONObjectType . FeatureCollection )
76
- {
77
- foreach ( var item in nfzinfo . Features )
77
+ if ( nfzinfo != null )
78
+ UpdateNoFlyZoneEvent += ( sender , args ) =>
78
79
{
79
- if ( item . Type == GeoJSONObjectType . Feature )
80
+ if ( nfzinfo . Type == GeoJSONObjectType . FeatureCollection )
80
81
{
81
- if ( item . Geometry . Type == GeoJSONObjectType . Polygon )
82
+ foreach ( var item in nfzinfo . Features )
82
83
{
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 )
100
85
{
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
+ }
103
116
}
104
117
}
105
- }
106
- }
118
+ } ;
107
119
}
108
120
catch
109
121
{
@@ -119,46 +131,72 @@ public static void Scan()
119
131
var nfzinfo = Utilities . nfz . EU . LoadNFZ ( ) . Result ;
120
132
121
133
if ( nfzinfo != null )
122
- foreach ( var feat in nfzinfo . Features )
134
+ UpdateNoFlyZoneEvent += ( sender , args ) =>
123
135
{
124
- foreach ( var item in feat . Geometry )
136
+ foreach ( var feat in nfzinfo . Features )
125
137
{
126
- if ( item . HorizontalProjection ? . Type == "Polygon" )
138
+ foreach ( var item in feat . Geometry )
127
139
{
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;
130
144
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 ( ) ;
132
146
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 ;
134
150
135
- nfzpolygon . Tag = item ;
151
+ GMapPolygon nfzpolygon = new GMapPolygon ( coordinates , feat . Name ) ;
136
152
137
- nfzpolygon . Stroke . Color = Color . Purple ;
153
+ nfzpolygon . Tag = item ;
138
154
139
- nfzpolygon . Fill = new SolidBrush ( Color . FromArgb ( 30 , Color . Blue ) ) ;
155
+ nfzpolygon . Stroke . Color = Color . Purple ;
140
156
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 ) ) ;
149
158
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 ) {
153
165
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" )
155
175
{
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
+ }
158
196
}
159
- }
160
197
161
- }
198
+ }
199
+ } ;
162
200
}
163
201
catch
164
202
{
@@ -168,9 +206,14 @@ public static void Scan()
168
206
NoFlyEvent ( null , new NoFlyEventArgs ( kmlpolygonsoverlay ) ) ;
169
207
}
170
208
209
+ static PointLatLngAlt lastUpdateLocation = PointLatLngAlt . Zero ;
171
210
public static void UpdateNoFlyZone ( object sender , PointLatLngAlt plla )
172
211
{
173
- UpdateNoFlyZoneEvent ? . Invoke ( sender , plla ) ;
212
+ if ( plla . GetDistance ( lastUpdateLocation ) > 100 )
213
+ {
214
+ UpdateNoFlyZoneEvent ? . Invoke ( sender , plla ) ;
215
+ lastUpdateLocation = plla ;
216
+ }
174
217
}
175
218
176
219
public static event EventHandler < PointLatLngAlt > UpdateNoFlyZoneEvent ;
0 commit comments