From cf3ef5b40321c073ba1f943b0ce5cc720c6b785f Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Mon, 7 Mar 2022 00:26:13 -0800 Subject: [PATCH] Support terrain zones on the new map. https://github.com/dcs-liberation/dcs_liberation/issues/2039 --- .../liberationmap/LiberationMap.tsx | 2 + .../terrainzones/TerrainZonesLayers.tsx | 71 +++++++++++++++++++ client/src/components/terrainzones/index.ts | 1 + 3 files changed, 74 insertions(+) create mode 100644 client/src/components/terrainzones/TerrainZonesLayers.tsx create mode 100644 client/src/components/terrainzones/index.ts diff --git a/client/src/components/liberationmap/LiberationMap.tsx b/client/src/components/liberationmap/LiberationMap.tsx index 9a97fadc..ba1bb932 100644 --- a/client/src/components/liberationmap/LiberationMap.tsx +++ b/client/src/components/liberationmap/LiberationMap.tsx @@ -8,6 +8,7 @@ import FlightPlansLayer from "../flightplanslayer"; import FrontLinesLayer from "../frontlineslayer"; import NavMeshLayer from "../navmesh/NavMeshLayer"; import SupplyRoutesLayer from "../supplyrouteslayer"; +import TerrainZonesLayers from "../terrainzones/TerrainZonesLayers"; import TgosLayer from "../tgoslayer/TgosLayer"; import { CoalitionThreatZones } from "../threatzones"; import "./LiberationMap.css"; @@ -94,6 +95,7 @@ export default function LiberationMap() { + ); diff --git a/client/src/components/terrainzones/TerrainZonesLayers.tsx b/client/src/components/terrainzones/TerrainZonesLayers.tsx new file mode 100644 index 00000000..aed0916d --- /dev/null +++ b/client/src/components/terrainzones/TerrainZonesLayers.tsx @@ -0,0 +1,71 @@ +import { useGetTerrainZonesQuery } from "../../api/liberationApi"; +import { LatLngLiteral } from "leaflet"; +import { LayerGroup, LayersControl, Polygon } from "react-leaflet"; + +interface TerrainZoneLayerProps { + zones: LatLngLiteral[][]; + color: string; + fillColor: string; +} + +function TerrainZoneLayer(props: TerrainZoneLayerProps) { + return ( + + {props.zones.map((poly, idx) => { + return ( + + ); + })} + + ); +} + +export default function TerrainZonesLayers() { + const { data, error, isLoading } = useGetTerrainZonesQuery(); + var exclusion = <>; + var inclusion = <>; + var sea = <>; + + if (error) { + console.error("Error while loading terrain zones", error); + } else if (isLoading) { + } else if (!data) { + console.log("Empty response when loading terrain zones"); + } else { + exclusion = ( + + ); + inclusion = ( + + ); + sea = ( + + ); + } + return ( + <> + + {exclusion} + + + {inclusion} + + {sea} + + ); +} diff --git a/client/src/components/terrainzones/index.ts b/client/src/components/terrainzones/index.ts new file mode 100644 index 00000000..87d28bd1 --- /dev/null +++ b/client/src/components/terrainzones/index.ts @@ -0,0 +1 @@ +export { default } from "./TerrainZonesLayers";