diff --git a/client/src/api/liberationApi.ts b/client/src/api/liberationApi.ts index 84683a4c..cef3113d 100644 --- a/client/src/api/liberationApi.ts +++ b/client/src/api/liberationApi.ts @@ -255,7 +255,7 @@ export type GetFlightByIdApiArg = { withWaypoints?: boolean; }; export type GetCommitBoundaryForFlightApiResponse = - /** status 200 Successful Response */ number[][]; + /** status 200 Successful Response */ LatLng[]; export type GetCommitBoundaryForFlightApiArg = { flightId: string; }; @@ -352,26 +352,26 @@ export type HttpValidationError = { detail?: ValidationError[]; }; export type HoldZones = { - homeBubble: number[][]; - targetBubble: number[][]; - joinBubble: number[][]; - excludedZones: number[][][]; - permissibleZones: number[][][]; - preferredLines: number[][][]; + homeBubble: LatLng[]; + targetBubble: LatLng[]; + joinBubble: LatLng[]; + excludedZones: LatLng[][]; + permissibleZones: LatLng[][]; + preferredLines: LatLng[][]; }; export type IpZones = { - homeBubble: number[][]; - ipBubble: number[][]; - permissibleZone: number[][]; - safeZones: number[][][]; + homeBubble: LatLng[]; + ipBubble: LatLng[]; + permissibleZone: LatLng[]; + safeZones: LatLng[][]; }; export type JoinZones = { - homeBubble: number[][]; - targetBubble: number[][]; - ipBubble: number[][]; - excludedZones: number[][][]; - permissibleZones: number[][][]; - preferredLines: number[][][]; + homeBubble: LatLng[]; + targetBubble: LatLng[]; + ipBubble: LatLng[]; + excludedZones: LatLng[][]; + permissibleZones: LatLng[][]; + preferredLines: LatLng[][]; }; export type Waypoint = { name: string; @@ -415,17 +415,17 @@ export type SupplyRoute = { active_transports: string[]; }; export type ThreatZones = { - full: number[][][]; - aircraft: number[][][]; - air_defenses: number[][][]; - radar_sams: number[][][]; + full: LatLng[][]; + aircraft: LatLng[][]; + air_defenses: LatLng[][]; + radar_sams: LatLng[][]; }; export type ThreatZoneContainer = { blue: ThreatZones; red: ThreatZones; }; export type NavMeshPoly = { - poly: number[][]; + poly: LatLng[]; threatened: boolean; }; export type NavMesh = { @@ -446,9 +446,9 @@ export type Game = { map_center: LatLng; }; export type MapZones = { - inclusion: number[][][]; - exclusion: number[][][]; - sea: number[][][]; + inclusion: LatLng[][]; + exclusion: LatLng[][]; + sea: LatLng[][]; }; export type UnculledZone = { position: LatLng; diff --git a/client/src/components/flightplan/FlightPlan.tsx b/client/src/components/flightplan/FlightPlan.tsx index 51911dc5..87820bb8 100644 --- a/client/src/components/flightplan/FlightPlan.tsx +++ b/client/src/components/flightplan/FlightPlan.tsx @@ -1,7 +1,6 @@ import { Flight } from "../../api/flight"; import { useGetCommitBoundaryForFlightQuery } from "../../api/liberationApi"; import WaypointMarker from "../waypointmarker"; -import { LatLng } from "leaflet"; import { ReactElement } from "react"; import { Polyline } from "react-leaflet"; @@ -83,15 +82,8 @@ function CommitBoundary(props: CommitBoundaryProps) { ); return <>; } - // TODO: Fix the response model and clean up. - const positions = data.map(([lat, lng]) => new LatLng(lat, lng)); return ( - + ); } diff --git a/client/src/components/navmesh/NavMeshLayer.tsx b/client/src/components/navmesh/NavMeshLayer.tsx index c8c65466..6b386a33 100644 --- a/client/src/components/navmesh/NavMeshLayer.tsx +++ b/client/src/components/navmesh/NavMeshLayer.tsx @@ -1,6 +1,5 @@ import { selectNavMeshes } from "../../api/navMeshSlice"; import { useAppSelector } from "../../app/hooks"; -import { LatLng } from "leaflet"; import { LayerGroup, Polygon } from "react-leaflet"; interface NavMeshLayerProps { @@ -13,11 +12,10 @@ export default function NavMeshLayer(props: NavMeshLayerProps) { return ( {mesh.map((zone, idx) => { - const positions = zone.poly.map(([lat, lng]) => new LatLng(lat, lng)); return ( new LatLng(lat, lng)); return ( LeafletPoly: + def latlng_to_leaflet(latlng: LatLng) -> LeafletPoint: + return LeafletPoint(lat=latlng.lat, lng=latlng.lng) + + @classmethod + def poly_to_leaflet(cls, poly: Polygon, theater: ConflictTheater) -> LeafletPoly: if poly.is_empty: return [] return [ - Point(x, y, theater.terrain).latlng().as_list() + cls.latlng_to_leaflet(Point(x, y, theater.terrain).latlng()) for x, y in poly.exterior.coords ] @@ -43,15 +48,13 @@ class ShapelyUtil: return [cls.poly_to_leaflet(poly, theater) for poly in polys] @staticmethod - def line_to_leaflet( - line: LineString, theater: ConflictTheater - ) -> list[LeafletLatLon]: - return [Point(x, y, theater.terrain).latlng().as_list() for x, y in line.coords] + def line_to_leaflet(line: LineString, theater: ConflictTheater) -> list[LatLng]: + return [Point(x, y, theater.terrain).latlng() for x, y in line.coords] @classmethod def lines_to_leaflet( cls, line_string: MultiLineString | LineString, theater: ConflictTheater - ) -> list[list[LeafletLatLon]]: + ) -> list[list[LatLng]]: if isinstance(line_string, MultiLineString): lines = line_string.geoms else: diff --git a/qt_ui/widgets/map/model/controlpointjs.py b/qt_ui/widgets/map/model/controlpointjs.py index 204f5d4a..984649ae 100644 --- a/qt_ui/widgets/map/model/controlpointjs.py +++ b/qt_ui/widgets/map/model/controlpointjs.py @@ -6,12 +6,12 @@ from PySide2.QtCore import Property, QObject, Signal, Slot from dcs import Point from dcs.mapping import LatLng -from game.server.leaflet import LeafletLatLon from game.theater import ConflictTheater, ControlPoint from game.utils import meters, nautical_miles from qt_ui.dialogs import Dialog from qt_ui.models import GameModel from qt_ui.windows.basemenu.QBaseMenu2 import QBaseMenu2 +from .leaflet import LeafletLatLon MAX_SHIP_DISTANCE = nautical_miles(80) diff --git a/qt_ui/widgets/map/model/leaflet.py b/qt_ui/widgets/map/model/leaflet.py new file mode 100644 index 00000000..6222628d --- /dev/null +++ b/qt_ui/widgets/map/model/leaflet.py @@ -0,0 +1,2 @@ +LeafletLatLon = list[float] +LeafletPoly = list[LeafletLatLon] diff --git a/qt_ui/widgets/map/model/mapmodel.py b/qt_ui/widgets/map/model/mapmodel.py index cb200313..ae944fa2 100644 --- a/qt_ui/widgets/map/model/mapmodel.py +++ b/qt_ui/widgets/map/model/mapmodel.py @@ -7,13 +7,13 @@ from dcs.mapping import LatLng from game import Game from game.profiling import logged_duration -from game.server.leaflet import LeafletLatLon from game.theater import ( ConflictTheater, ) from qt_ui.models import GameModel from qt_ui.windows.GameUpdateSignal import GameUpdateSignal from .controlpointjs import ControlPointJs +from .leaflet import LeafletLatLon from .supplyroutejs import SupplyRouteJs diff --git a/qt_ui/widgets/map/model/supplyroutejs.py b/qt_ui/widgets/map/model/supplyroutejs.py index 2d6226ed..9979c235 100644 --- a/qt_ui/widgets/map/model/supplyroutejs.py +++ b/qt_ui/widgets/map/model/supplyroutejs.py @@ -5,9 +5,9 @@ from typing import List from PySide2.QtCore import Property, QObject, Signal from game import Game -from game.server.leaflet import LeafletLatLon from game.theater import ControlPoint from game.transfers import MultiGroupTransport, TransportMap +from .leaflet import LeafletLatLon class SupplyRouteJs(QObject):