Draw flight plan paths in the react UI.

https://github.com/dcs-liberation/dcs_liberation/issues/2039
This commit is contained in:
Dan Albert
2022-03-01 00:08:34 -08:00
parent bd8aa0296b
commit 406a64ae3f
12 changed files with 183 additions and 18 deletions

View File

@@ -7,6 +7,8 @@ from pydantic import BaseModel
from game.ato import Flight
from game.ato.flightstate import InFlight
from game.server.leaflet import LeafletPoint
from game.server.waypoints.models import FlightWaypointJs
from game.server.waypoints.routes import waypoints_for_flight
class FlightJs(BaseModel):
@@ -14,9 +16,10 @@ class FlightJs(BaseModel):
blue: bool
position: LeafletPoint | None
sidc: str
waypoints: list[FlightWaypointJs] | None
@staticmethod
def for_flight(flight: Flight) -> FlightJs:
def for_flight(flight: Flight, with_waypoints: bool) -> FlightJs:
# Don't provide a location for aircraft that aren't in the air. Later we can
# expand the model to include the state data for the UI so that it can make its
# own decisions about whether or not to draw the aircraft, but for now we'll
@@ -24,6 +27,13 @@ class FlightJs(BaseModel):
position = None
if isinstance(flight.state, InFlight):
position = flight.position().latlng()
waypoints = None
if with_waypoints:
waypoints = waypoints_for_flight(flight)
return FlightJs(
id=flight.id, blue=flight.blue, position=position, sidc=str(flight.sidc())
id=flight.id,
blue=flight.blue,
position=position,
sidc=str(flight.sidc()),
waypoints=waypoints,
)