From 8b8ef4acc3aa1d306181b9e221b06af0e73f2d65 Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Mon, 13 Nov 2023 22:59:51 +0100 Subject: [PATCH] map: add vertical boundaries to sector --- .../src/components/map/NavaidMarker.tsx | 2 +- .../src/components/map/SectorPolygon.tsx | 18 +++++++ .../src/components/map/VerticalBoundary.tsx | 51 +++++++++++++++++++ atciss-frontend/src/index.css | 5 +- 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 atciss-frontend/src/components/map/VerticalBoundary.tsx diff --git a/atciss-frontend/src/components/map/NavaidMarker.tsx b/atciss-frontend/src/components/map/NavaidMarker.tsx index 023c3942..9a365961 100644 --- a/atciss-frontend/src/components/map/NavaidMarker.tsx +++ b/atciss-frontend/src/components/map/NavaidMarker.tsx @@ -176,7 +176,7 @@ export const NavaidMarker = ({ designator }: { designator: string }) => { > {icons[navaid.type.toLowerCase()] ?? icons["rnav"]} -
{navaid.designator}
+
{navaid.designator}
) diff --git a/atciss-frontend/src/components/map/SectorPolygon.tsx b/atciss-frontend/src/components/map/SectorPolygon.tsx index a2191fd7..cea7f181 100644 --- a/atciss-frontend/src/components/map/SectorPolygon.tsx +++ b/atciss-frontend/src/components/map/SectorPolygon.tsx @@ -16,6 +16,9 @@ import createCachedSelector from "re-reselect" import { selectLevel } from "../../services/mapSlice" import { selectAllAtis } from "../../services/atisApi" import { RootState } from "../../app/store" +import { useEffect, useRef, useState } from "react" +import { VerticalBoundary } from "./VerticalBoundary" +import { LatLng } from "leaflet" const selectSectorBounds = createCachedSelector( [ @@ -69,6 +72,14 @@ export const SectorPolygon = ({ const owner = useAppSelector((store) => selectOwner(store, id)) const sector = useAppSelector((store) => selectSector(store, id)) const selectedPosition = useAppSelector(selectSelectedPosition) + const polygon = useRef(null) + const [center, setCenter] = useState(null) + + useEffect(() => { + if (polygon.current) { + setCenter(polygon.current.getCenter()) + } + }, [polygon.current]) return ( owner && ( @@ -80,7 +91,14 @@ export const SectorPolygon = ({ fillOpacity: owner?.id === selectedPosition ? 0.5 : 0.3, }} positions={points} + ref={polygon} > + {sector.id} diff --git a/atciss-frontend/src/components/map/VerticalBoundary.tsx b/atciss-frontend/src/components/map/VerticalBoundary.tsx new file mode 100644 index 00000000..b297b532 --- /dev/null +++ b/atciss-frontend/src/components/map/VerticalBoundary.tsx @@ -0,0 +1,51 @@ +/** @jsxImportSource theme-ui */ + +import { useState } from "react" +import { Marker, useMap, useMapEvent } from "react-leaflet" +import { z3 } from "../../app/utils" +import { createPortal } from "react-dom" +import L, { LatLngExpression } from "leaflet" + +export const VerticalBoundary = ({ + min, + max, + center, + color, +}: { + min: number | null + max: number | null + center: LatLngExpression | null + color: string +}) => { + const [zoom, setZoom] = useState(0) + + const icon = color && ( +
+
{!!max && z3(max)}
+
{!!min && z3(min)}
+
+ ) + + const element = L.DomUtil.create("div") + + const divIcon = L.divIcon({ + html: element, + className: "", + iconSize: [22, 14], + }) + + const map = useMap() + useMapEvent("zoomend", () => setZoom(map.getZoom())) + + return ( + center && + zoom > 8 && ( + <> + {createPortal(icon, element)} + + <>Test + + + ) + ) +} diff --git a/atciss-frontend/src/index.css b/atciss-frontend/src/index.css index 77ce0e22..b1f03eb2 100644 --- a/atciss-frontend/src/index.css +++ b/atciss-frontend/src/index.css @@ -120,9 +120,12 @@ pre { margin: 0; } -.navaid-label { +.marker-label { font-family: "Source Code Pro", source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace; font-weight: bold; +} + +.navaid-label { margin-left: 0.7rem; margin-top: -0.3rem; text-shadow: