pass additional data to the map

This commit is contained in:
Jakob Ketterl 2023-08-25 21:15:29 +02:00
parent 06d2fbab85
commit b109ee5c45
3 changed files with 45 additions and 7 deletions

View file

@ -114,6 +114,7 @@ $(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 marker;
var markerClass = google.maps.Marker;
@ -125,6 +126,7 @@ $(function(){
aprsOptions.speed = update.location.speed;
} else if (update.source.icao) {
markerClass = PlaneMarker;
aprsOptions = update.location;
}
if (markers[key]) {
marker = markers[key];
@ -438,8 +440,14 @@ $(function(){
if (receiverMarker) {
distance = " at " + distanceKm(receiverMarker.position, marker.position) + " km";
}
var title;
if (marker.icao) {
title = marker.identification || marker.icao;
} else {
linkifySource(source);
}
infowindow.setContent(
'<h3>' + linkifySource(source) + distance + '</h3>' +
'<h3>' + title + distance + '</h3>' +
'<div>' + timestring + ' using ' + marker.mode + ( marker.band ? ' on ' + marker.band : '' ) + '</div>' +
commentString
);

View file

@ -1,6 +1,8 @@
from abc import ABC
from csdr.module import PickleModule
from math import sqrt, atan2, pi, floor, acos, cos
from owrx.map import LatLngLocation, Map
from owrx.map import LatLngLocation, IncrementalUpdate, Location, Map
import time
import logging
@ -15,9 +17,28 @@ d_lat_even = 360 / (4 * nz)
d_lat_odd = 360 / (4 * nz - 1)
class AirplaneLocation(LatLngLocation):
class AirplaneLocation(LatLngLocation, IncrementalUpdate, ABC):
def __init__(self, message):
self.props = message
if "lat" in message and "lon" in message:
super().__init__(message["lat"], message["lon"])
else:
self.lat = None
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"]
def __dict__(self):
dict = super().__dict__()
dict.update(self.props)
return dict
class CprCache:
@ -54,7 +75,7 @@ class ModeSParser(PickleModule):
message["capability"] = input[0] & 0b111
message["icao"] = icao = input[1:4].hex()
type = (input[4] & 0b11111000) >> 3
message["type"] = type
message["adsb_type"] = type
if type in [1, 2, 3, 4]:
# identification message
@ -181,9 +202,9 @@ class ModeSParser(PickleModule):
# Mode-S All-call reply
message["icao"] = input[1:4].hex()
if "icao" in message and "lat" in message and "lon" in message:
if "icao" in message and ['lat', 'lon', 'altitude', 'heading', 'groundtrack', 'identification'] & message.keys():
loc = AirplaneLocation(message)
Map.getSharedInstance().updateLocation({"icao": icao}, loc, "ADS-B", None)
Map.getSharedInstance().updateLocation({"icao": message['icao']}, loc, "ADS-B", None)
return message

View file

@ -1,6 +1,7 @@
from datetime import datetime, timedelta
from owrx.config import Config
from owrx.bands import Band
from abc import abstractmethod, ABCMeta
import threading
import time
import sys
@ -88,6 +89,8 @@ class Map(object):
ts = datetime.now()
key = self._sourceToKey(source)
with self.positionsLock:
if isinstance(loc, IncrementalUpdate) and key in self.positions:
loc.update(self.positions[key]["location"])
self.positions[key] = {"source": source, "location": loc, "updated": ts, "mode": mode, "band": band}
self.broadcast(
[
@ -148,3 +151,9 @@ class LocatorLocation(Location):
def __dict__(self):
return {"type": "locator", "locator": self.locator}
class IncrementalUpdate(Location, metaclass=ABCMeta):
@abstractmethod
def update(self, previousLocation: Location):
pass