Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _onload():
setattr(Airspace, "kepler", airspace_kepler)
setattr(Flight, "kepler", flight_kepler)
setattr(Traffic, "kepler", traffic_kepler)
setattr(KeplerGl, "add_data", map_add_data)
"id": flight.flight_id
if flight.flight_id is not None
else flight.aircraft,
"wkt_string": dumps(flight.shape),
"icao24": flight.icao24,
"callsign": flight.callsign,
"registration": flight.registration,
"start": f"{flight.start:%Y-%m-%d %H:%M:%S}",
"stop": f"{flight.stop:%Y-%m-%d %H:%M:%S}",
}
for flight in traffic
]
)
_old_add_data = KeplerGl.add_data
def map_add_data(_map, data, *args, **kwargs):
if any(isinstance(data, c) for c in (Airspace, Flight, Traffic)):
layer = data.kepler()
return _old_add_data(_map, layer, *args, **kwargs)
if any(isinstance(data, c) for c in (list, Generator)):
layer = dict(
type="FeatureCollection", features=[elt.kepler() for elt in data]
)
return _old_add_data(_map, layer, *args, **kwargs)
# convenient for airports, navaids, etc.
if hasattr(data, "data"):
data = data.data