Skip to content

Commit

Permalink
mavproxy_kmlread: break out an add_polygon function
Browse files Browse the repository at this point in the history
also make the module public so other modules can add to the list
  • Loading branch information
peterbarker authored and tridge committed May 22, 2024
1 parent 6b15590 commit acad27e
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions MAVProxy/modules/mavproxy_kmlread.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class KmlReadModule(mp_module.MPModule):
def __init__(self, mpstate):
super(KmlReadModule, self).__init__(mpstate, "kmlread", "Add kml or kmz layers to map")
super(KmlReadModule, self).__init__(mpstate, "kmlread", "Add kml or kmz layers to map", public=True)
self.add_command('kml', self.cmd_param, "kml map handling",
["<clear|snapwp|snapfence>",
"<load> (FILENAME)", '<layers>'])
Expand Down Expand Up @@ -314,13 +314,31 @@ def clearkml(self):
self.curtextlayers = []
self.menu_needs_refreshing = True

def add_polygon(self, name, coords):
'''add a polygon to the KML list. coords is a list of lat/lng tuples in degrees'''
self.snap_points.extend(coords)

# print("Adding " + name)
newcolour = (random.randint(0, 255), 0, random.randint(0, 255))
layer_name = f"{name}-{self.counter}"
curpoly = mp_slipmap.SlipPolygon(
layer_name,
coords,
layer=2,
linewidth=2,
colour=newcolour,
)
self.add_map_object(curpoly)
self.allayers.append(curpoly)
self.curlayers.append(layer_name)
self.counter += 1

def loadkml(self, filename):
'''Load a kml from file and put it on the map'''
# Open the zip file
nodes = kmlread.readkmz(filename)

self.snap_points = []
counter = 0

# go through each object in the kml...
if nodes is None:
Expand All @@ -334,28 +352,13 @@ def loadkml(self, filename):
if point is None:
continue

counter += 1

# and place any polygons on the map
if point[0] == 'Polygon':
self.snap_points.extend(point[2])

# print("Adding " + point[1])
newcolour = (random.randint(0, 255), 0, random.randint(0, 255))
layer_name = point[1]+"-"+str(counter)
curpoly = mp_slipmap.SlipPolygon(
layer_name,
point[2],
layer=2,
linewidth=2,
colour=newcolour,
)
self.add_map_object(curpoly)
self.allayers.append(curpoly)
self.curlayers.append(layer_name)
(pointtype, name, coords) = point
if pointtype == 'Polygon':
self.add_polygon(name, coords)

# and points - barrell image and text
if point[0] == 'Point':
if pointtype == 'Point':
# print("Adding " + point[1])
curpoint = mp_slipmap.SlipIcon(
point[1],
Expand Down

0 comments on commit acad27e

Please sign in to comment.