Skip to content

Commit e5234a6

Browse files
committed
mavproxy_map: enhance map_circle to be able to consume click position
prior to this patch you had to know the lat/lng you wanted a circle. After this patch you supplying 1 or 2 arguments only will assume you want the circle at the click location. Usage: map circle <lat> <lon> <radius> <colour> Usage: map circle <radius> <colour>
1 parent 0f1e9e6 commit e5234a6

File tree

1 file changed

+59
-28
lines changed

1 file changed

+59
-28
lines changed

MAVProxy/modules/mavproxy_map/__init__.py

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -200,34 +200,7 @@ def cmd_map(self, args):
200200
self.vehicle_type_override[sysid] = vtype
201201
print("Set sysid %u to vehicle type %u" % (sysid, vtype))
202202
elif args[0] == "circle":
203-
if len(args) < 4:
204-
# map circle -27.70533373 153.23404844 5 red
205-
print("Usage: map circle <lat> <lon> <radius> <colour>")
206-
else:
207-
lat = args[1]
208-
lon = args[2]
209-
radius = args[3]
210-
colour = 'red'
211-
if len(args) > 4:
212-
colour = args[4]
213-
if colour == "red":
214-
colour = (255,0,0)
215-
elif colour == "green":
216-
colour = (0,255,0)
217-
elif colour == "blue":
218-
colour = (0,0,255)
219-
else:
220-
colour = eval(colour)
221-
circle = mp_slipmap.SlipCircle(
222-
"circle %u" % self.circle_counter,
223-
3,
224-
(float(lat), float(lon)),
225-
float(radius),
226-
colour,
227-
linewidth=1,
228-
)
229-
self.map.add_object(circle)
230-
self.circle_counter += 1
203+
self.cmd_map_circle(args[1:])
231204
elif args[0] == "set":
232205
self.map_settings.command(args[1:])
233206
self.map.add_object(mp_slipmap.SlipBrightness(self.map_settings.brightness))
@@ -254,6 +227,64 @@ def cmd_map(self, args):
254227
else:
255228
print("usage: map <icon|set>")
256229

230+
def cmd_map_circle(self, args):
231+
usage = '''
232+
Usage: map circle <lat> <lon> <radius> <colour>
233+
Usage: map circle <radius> <colour>
234+
'''
235+
236+
lat = None
237+
colour = None
238+
# syntax 1, lat/lon/radius/colour
239+
if len(args) == 4:
240+
colour = args[3]
241+
args = args[0:3]
242+
if len(args) == 3:
243+
lat = args[0]
244+
lon = args[1]
245+
radius = args[2]
246+
247+
# syntax 2, radius/colour, uses click position
248+
if len(args) == 2:
249+
colour = args[1]
250+
args = args[0:1]
251+
if len(args) == 1:
252+
pos = self.mpstate.click_location
253+
if pos is None:
254+
print("Need click or location")
255+
print(usage)
256+
return
257+
258+
(lat, lon) = pos
259+
radius = args[0]
260+
261+
if lat is None:
262+
print(usage)
263+
return
264+
265+
if colour is None:
266+
colour = "red"
267+
268+
if colour == "red":
269+
colour = (255,0,0)
270+
elif colour == "green":
271+
colour = (0,255,0)
272+
elif colour == "blue":
273+
colour = (0,0,255)
274+
else:
275+
colour = eval(colour)
276+
277+
circle = mp_slipmap.SlipCircle(
278+
"circle %u" % self.circle_counter,
279+
3,
280+
(float(lat), float(lon)),
281+
float(radius),
282+
colour,
283+
linewidth=1,
284+
)
285+
self.map.add_object(circle)
286+
self.circle_counter += 1
287+
257288
def colour_for_wp(self, wp_num):
258289
'''return a tuple describing the colour a waypoint should appear on the map'''
259290
wp = self.module('wp').wploader.wp(wp_num)

0 commit comments

Comments
 (0)