Skip to content

Commit 3e06e94

Browse files
committed
mavproxy_kmlread: use alternate interface to get colours for KML
1 parent 3f63bd9 commit 3e06e94

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

MAVProxy/modules/mavproxy_kmlread.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -315,19 +315,20 @@ def clearkml(self):
315315
self.curtextlayers = []
316316
self.menu_needs_refreshing = True
317317

318-
def add_polygon(self, name, coords):
318+
def add_polygon(self, name, coords, line_colour=None):
319319
'''add a polygon to the KML list. coords is a list of lat/lng tuples in degrees'''
320320
self.snap_points.extend(coords)
321321

322322
# print("Adding " + name)
323-
newcolour = (random.randint(0, 255), 0, random.randint(0, 255))
323+
if line_colour is None:
324+
line_colour = (random.randint(0, 255), 0, random.randint(0, 255))
324325
layer_name = f"{name}-{self.counter}"
325326
curpoly = mp_slipmap.SlipPolygon(
326327
layer_name,
327328
coords,
328329
layer=2,
329330
linewidth=2,
330-
colour=newcolour,
331+
colour=line_colour,
331332
)
332333
self.add_map_object(curpoly)
333334
self.allayers.append(curpoly)
@@ -337,7 +338,9 @@ def add_polygon(self, name, coords):
337338
def loadkml(self, filename):
338339
'''Load a kml from file and put it on the map'''
339340
# Open the zip file
340-
nodes = kmlread.readkmz(filename)
341+
kml = kmlread.KMLRead(filename)
342+
kml.parse()
343+
nodes = kml.placemark_nodes()
341344

342345
self.snap_points = []
343346

@@ -347,15 +350,15 @@ def loadkml(self, filename):
347350
return
348351
for n in nodes:
349352
try:
350-
point = kmlread.readObject(n)
353+
point = kml.readObject(n)
351354
except Exception:
352355
continue
353356
if point is None:
354357
continue
355358

356359
# and place any polygons on the map
357360
if isinstance(point, kmlread.Polygon):
358-
self.add_polygon(point.name, point.vertexes)
361+
self.add_polygon(point.name, point.vertexes, point.line_colour)
359362

360363
# and points - barrell image and text
361364
if isinstance(point, kmlread.Point):

0 commit comments

Comments
 (0)