Skip to content

Commit

Permalink
map: runway dependent sector display
Browse files Browse the repository at this point in the history
Fixes #35
  • Loading branch information
globin committed Sep 24, 2023
1 parent eb78c1b commit 5750b07
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
7 changes: 5 additions & 2 deletions atciss-frontend/src/components/map/AerodromeLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export const AerodromeLayer = () => {
<LayerGroup>
{allADs.map((ad) => {
const station = data?.airports?.[ad]?.topdown?.find(
(pos) => activePositions[pos]?.[syncedToOnline ? "online" : "manual"],
(pos) =>
// TODO don't ignore rwy-dependent topdown
typeof pos === "string" &&
activePositions[pos]?.[syncedToOnline ? "online" : "manual"],
)
const metar = metars?.[ad]
const taf = tafs?.[ad]
Expand Down Expand Up @@ -81,7 +84,7 @@ export const AerodromeLayer = () => {
>
<Box>
<Text variant="mapAd">{ad} </Text>
{station ? (
{typeof station === "string" ? (
<>
by <Text variant="label">{station}</Text>
</>
Expand Down
17 changes: 16 additions & 1 deletion atciss-frontend/src/components/map/SectorLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { selectLevel, selectSectors } from "../../services/mapSlice"
import { Sector, sectorApi } from "../../services/airspaceApi"
import { usePollControllers } from "../../services/controllerApi"
import { SectorPolygon } from "./SectorPolygon"
import { usePollAtisByIcaoCodes } from "../../services/atisApi"

export const SectorLayer = () => {
const { data } = sectorApi.useGetByRegionQuery()
Expand All @@ -18,16 +19,30 @@ export const SectorLayer = () => {

const level = useAppSelector(selectLevel)
const displaySectors = useAppSelector(selectSectors)

const { data: atis } = usePollAtisByIcaoCodes(
Object.keys(data?.airports ?? {}),
)

const levelFilter = (s: Sector) =>
(s.min ?? 0) <= level && level < (s.max ?? 999)
const rwyFilter = (s: Sector) =>
s.runways.length === 0 ||
s.runways.some((rwy) => {
const rwysInUse = atis?.[rwy.icao]?.runways_in_use ?? []
const rwyPriority = data?.airports?.[rwy.icao].runways ?? []
return rwysInUse.length > 0
? rwysInUse.some((activeRwy) => activeRwy.startsWith(rwy.runway))
: rwyPriority[0] === rwy.runway
})

const sectors = data?.airspace
.filter((a) => a.sectors.some(levelFilter))
.map(({ id: name, remark, owner, sectors }) => ({
name,
remark,
owner,
sectors: sectors.filter(levelFilter),
sectors: sectors.filter(levelFilter).filter(rwyFilter),
}))

return (
Expand Down
14 changes: 13 additions & 1 deletion atciss-frontend/src/services/airspaceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import { createApi } from "@reduxjs/toolkit/query/react"
import { fetchWithAuth } from "../app/auth"
import { LatLngExpression } from "leaflet"

export type Runway = {
icao: string
runway: string
}

export type Sector = {
points: LatLngExpression[]
min: number | null
max: number | null
runways: Runway[]
}

export type Airspace = {
Expand All @@ -16,10 +22,16 @@ export type Airspace = {
sectors: Sector[]
}

export type RwyDependentTopDown = {
runway: Runway
topdown: string[]
}

export type Airport = {
callsign: string
coord: LatLngExpression
topdown: string[]
topdown: (string | RwyDependentTopDown)[]
runways: string[]
}

export type Position = {
Expand Down
18 changes: 10 additions & 8 deletions atciss/app/views/sector.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ def convert_point(point: Tuple[str, str] | Coordinate) -> Coordinate:
return cast(Coordinate, [convert_coordinate(cast(str, coord)) for coord in point])


@dataclass
class Runway:
icao: str
runway: str


class Sector(BaseModel):
points: list[Coordinate]
min: Optional[int] = None
max: Optional[int] = None
runways: list[Runway] = field(default_factory=list)

@field_validator("points", mode="before")
@classmethod
Expand Down Expand Up @@ -64,13 +71,7 @@ class Position:


@dataclass
class Runway:
icao: str
runway: str


@dataclass
class RwyDependantTopDown:
class RwyDependentTopDown:
runway: Runway
topdown: list[str]

Expand All @@ -79,7 +80,8 @@ class RwyDependantTopDown:
class Airport:
callsign: str
coord: Coordinate
topdown: list[str | RwyDependantTopDown] = field(default_factory=list)
runways: list[str] = field(default_factory=list)
topdown: list[str | RwyDependentTopDown] = field(default_factory=list)


@dataclass
Expand Down

0 comments on commit 5750b07

Please sign in to comment.