From 71eee49fe245c709d8cc1bdef9d7ee663353f7ef Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Fri, 25 Aug 2023 23:29:27 +0200 Subject: [PATCH] improve update pipeline; remove expired markers --- htdocs/map.js | 24 +++++++++++++++++------- owrx/adsb/modes.py | 35 ++++++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/htdocs/map.js b/htdocs/map.js index 6f7a5bfb..76a40913 100644 --- a/htdocs/map.js +++ b/htdocs/map.js @@ -114,8 +114,10 @@ $(function(){ switch (update.location.type) { case 'latlon': - if (!update.location.lat || !update.location.lon) break; - var pos = new google.maps.LatLng(update.location.lat, update.location.lon); + var pos = false; + if (update.location.lat && update.location.lon) { + pos = new google.maps.LatLng(update.location.lat, update.location.lon); + } var marker; var markerClass = google.maps.Marker; var aprsOptions = {} @@ -130,13 +132,21 @@ $(function(){ } if (markers[key]) { marker = markers[key]; + if (!pos) { + delete markers[key]; + marker.setMap(); + return; + } } else { - marker = new markerClass(); - marker.addListener('click', function(){ - showMarkerInfoWindow(update.source, pos); - }); - markers[key] = marker; + if (pos) { + marker = new markerClass(); + marker.addListener('click', function () { + showMarkerInfoWindow(update.source, pos); + }); + markers[key] = marker; + } } + if (!marker) return; marker.setOptions($.extend({ position: pos, map: map, diff --git a/owrx/adsb/modes.py b/owrx/adsb/modes.py index 3bc76fb6..2d580c30 100644 --- a/owrx/adsb/modes.py +++ b/owrx/adsb/modes.py @@ -18,7 +18,12 @@ d_lat_odd = 360 / (4 * nz - 1) class AirplaneLocation(LatLngLocation, IncrementalUpdate, ABC): + mapKeys = ['icao', 'lat', 'lon', 'altitude', 'heading', 'groundtrack', 'identification'] + ttl = 30 + def __init__(self, message): + self.history = [] + self.timestamp = time.time() self.props = message if "lat" in message and "lon" in message: super().__init__(message["lat"], message["lon"]) @@ -27,13 +32,24 @@ class AirplaneLocation(LatLngLocation, IncrementalUpdate, ABC): self.lon = None def update(self, previousLocation: Location): - props = previousLocation.props - props.update(self.props) - self.props = props - if "lat" in props: - self.lat = props["lat"] - if "lon" in props: - self.lon = props["lon"] + history = previousLocation.history + history += [{ + "timestamp": self.timestamp, + "props": self.props, + }] + now = time.time() + history = [p for p in history if now - p["timestamp"] < self.ttl] + self.history = sorted(history, key=lambda p: p["timestamp"]) + + merged = {} + for p in self.history: + merged.update(p["props"]) + + self.props = merged + if "lat" in merged: + self.lat = merged["lat"] + if "lon" in merged: + self.lon = merged["lon"] def __dict__(self): dict = super().__dict__() @@ -202,8 +218,9 @@ class ModeSParser(PickleModule): # Mode-S All-call reply message["icao"] = input[1:4].hex() - if "icao" in message and ['lat', 'lon', 'altitude', 'heading', 'groundtrack', 'identification'] & message.keys(): - loc = AirplaneLocation(message) + if "icao" in message and AirplaneLocation.mapKeys & message.keys(): + data = {k: message[k] for k in AirplaneLocation.mapKeys if k in message} + loc = AirplaneLocation(data) Map.getSharedInstance().updateLocation({"icao": message['icao']}, loc, "ADS-B", None) return message