mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Clean up leaflet polygon API surface.
This commit is contained in:
@@ -3,14 +3,12 @@ from __future__ import annotations
|
||||
from typing import Union
|
||||
|
||||
from dcs import Point
|
||||
from dcs.mapping import LatLng
|
||||
from pydantic import BaseModel
|
||||
from shapely.geometry import LineString, MultiLineString, MultiPolygon, Polygon
|
||||
|
||||
from game.theater import ConflictTheater
|
||||
|
||||
LeafletLatLon = list[float]
|
||||
LeafletPoly = list[LeafletLatLon]
|
||||
|
||||
|
||||
class LeafletPoint(BaseModel):
|
||||
lat: float
|
||||
@@ -22,13 +20,20 @@ class LeafletPoint(BaseModel):
|
||||
title = "LatLng"
|
||||
|
||||
|
||||
LeafletPoly = list[LeafletPoint]
|
||||
|
||||
|
||||
class ShapelyUtil:
|
||||
@staticmethod
|
||||
def poly_to_leaflet(poly: Polygon, theater: ConflictTheater) -> 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:
|
||||
|
||||
Reference in New Issue
Block a user