From 4b278f916c8049aaf798d681b2e752df92bc6cf4 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 10 May 2024 10:55:27 +1000 Subject: [PATCH 1/3] kmlread: factor out skipping of -text items ... I'm not sure what these are or why we are skipping them, but simplify things --- MAVProxy/modules/mavproxy_kmlread.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MAVProxy/modules/mavproxy_kmlread.py b/MAVProxy/modules/mavproxy_kmlread.py index 6d8dc3d60e..fa72af5535 100644 --- a/MAVProxy/modules/mavproxy_kmlread.py +++ b/MAVProxy/modules/mavproxy_kmlread.py @@ -389,14 +389,17 @@ def idle_task(self): # then add all the layers to the menu, ensuring to # check the active layers text elements aren't # included on the menu - if layer.key in self.curlayers and layer.key[-5:] != "-text": + if layer.key.endswith('-text'): + continue + + if layer.key in self.curlayers: self.menu.items.append(MPMenuCheckbox( layer.key, layer.key, '# kml toggle \"' + layer.key + '\"', checked=True, )) - elif layer.key[-5:] != "-text": + else: self.menu.items.append(MPMenuCheckbox( layer.key, layer.key, From 925db188b1d7542efd57f4c9e559d77111e8f902 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 10 May 2024 12:27:51 +1000 Subject: [PATCH 2/3] kmlread: factor checkbox menu items only difference was checked-or-not --- MAVProxy/modules/mavproxy_kmlread.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/MAVProxy/modules/mavproxy_kmlread.py b/MAVProxy/modules/mavproxy_kmlread.py index fa72af5535..818cf59957 100644 --- a/MAVProxy/modules/mavproxy_kmlread.py +++ b/MAVProxy/modules/mavproxy_kmlread.py @@ -392,20 +392,13 @@ def idle_task(self): if layer.key.endswith('-text'): continue - if layer.key in self.curlayers: - self.menu.items.append(MPMenuCheckbox( - layer.key, - layer.key, - '# kml toggle \"' + layer.key + '\"', - checked=True, - )) - else: - self.menu.items.append(MPMenuCheckbox( - layer.key, - layer.key, - '# kml toggle \"' + layer.key + '\"', - checked=False, - )) + checked = layer.key in self.curlayers + self.menu.items.append(MPMenuCheckbox( + layer.key, + layer.key, + f'# kml toggle \"{layer.key}\"', + checked=checked, + )) # and add the menu to the map popu menu self.module('map').add_menu(self.menu) self.menu_needs_refreshing = False From 52d98eb7a895d66712ca47be41e982264c9921c8 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 10 May 2024 13:05:55 +1000 Subject: [PATCH 3/3] mavproxy_kmlread: correct initial checking of checkbox polygon items the addition of the counter for the layer name broke the population of the "current layers" list --- MAVProxy/modules/mavproxy_kmlread.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MAVProxy/modules/mavproxy_kmlread.py b/MAVProxy/modules/mavproxy_kmlread.py index 818cf59957..5c82814759 100644 --- a/MAVProxy/modules/mavproxy_kmlread.py +++ b/MAVProxy/modules/mavproxy_kmlread.py @@ -316,8 +316,9 @@ def loadkml(self, filename): # print("Adding " + point[1]) newcolour = (random.randint(0, 255), 0, random.randint(0, 255)) + layer_name = point[1]+"-"+str(counter) curpoly = mp_slipmap.SlipPolygon( - point[1]+"-"+str(counter), + layer_name, point[2], layer=2, linewidth=2, @@ -325,7 +326,7 @@ def loadkml(self, filename): ) self.mpstate.map.add_object(curpoly) self.allayers.append(curpoly) - self.curlayers.append(point[1]) + self.curlayers.append(layer_name) # and points - barrell image and text if self.mpstate.map is not None and point[0] == 'Point':