mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Reorganize React project structure.
Whatever I was doing was getting out of control :)
This commit is contained in:
32
client/src/components/controlpoints/ControlPoint.tsx
Normal file
32
client/src/components/controlpoints/ControlPoint.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Icon, Point } from "leaflet";
|
||||
import { Marker, Popup } from "react-leaflet";
|
||||
|
||||
import { ControlPoint as ControlPointModel } from "../../api/controlpoint";
|
||||
import { Symbol as MilSymbol } from "milsymbol";
|
||||
|
||||
function iconForControlPoint(cp: ControlPointModel) {
|
||||
const symbol = new MilSymbol(cp.sidc, {
|
||||
size: 24,
|
||||
colorMode: "Dark",
|
||||
});
|
||||
|
||||
return new Icon({
|
||||
iconUrl: symbol.toDataURL(),
|
||||
iconAnchor: new Point(symbol.getAnchor().x, symbol.getAnchor().y),
|
||||
});
|
||||
}
|
||||
|
||||
interface ControlPointProps {
|
||||
controlPoint: ControlPointModel;
|
||||
}
|
||||
|
||||
export default function ControlPoint(props: ControlPointProps) {
|
||||
return (
|
||||
<Marker
|
||||
position={props.controlPoint.position}
|
||||
icon={iconForControlPoint(props.controlPoint)}
|
||||
>
|
||||
<Popup>{props.controlPoint.name}</Popup>
|
||||
</Marker>
|
||||
);
|
||||
}
|
||||
1
client/src/components/controlpoints/index.ts
Normal file
1
client/src/components/controlpoints/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default } from "./ControlPoint";
|
||||
@@ -0,0 +1,17 @@
|
||||
import ControlPoint from "../controlpoints";
|
||||
import { LayerGroup } from "react-leaflet";
|
||||
import { selectControlPoints } from "../../api/controlPointsSlice";
|
||||
import { useAppSelector } from "../../app/hooks";
|
||||
|
||||
export default function ControlPointsLayer() {
|
||||
const controlPoints = useAppSelector(selectControlPoints);
|
||||
return (
|
||||
<LayerGroup>
|
||||
{controlPoints.map((controlPoint) => {
|
||||
return (
|
||||
<ControlPoint key={controlPoint.name} controlPoint={controlPoint} />
|
||||
);
|
||||
})}
|
||||
</LayerGroup>
|
||||
);
|
||||
}
|
||||
1
client/src/components/controlpointslayer/index.ts
Normal file
1
client/src/components/controlpointslayer/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default } from "./ControlPointsLayer";
|
||||
33
client/src/components/flightplan/FlightPlan.tsx
Normal file
33
client/src/components/flightplan/FlightPlan.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import { Flight } from "../../api/flight";
|
||||
import { Polyline } from "react-leaflet";
|
||||
|
||||
const BLUE_PATH = "#0084ff";
|
||||
const RED_PATH = "#c85050";
|
||||
|
||||
interface FlightPlanProps {
|
||||
flight: Flight;
|
||||
selected: boolean;
|
||||
}
|
||||
|
||||
function FlightPlanPath(props: FlightPlanProps) {
|
||||
const color = props.flight.blue ? BLUE_PATH : RED_PATH;
|
||||
const waypoints = props.flight.waypoints;
|
||||
if (waypoints == null) {
|
||||
return <></>;
|
||||
}
|
||||
const points = waypoints.map((waypoint) => waypoint.position);
|
||||
return (
|
||||
<Polyline
|
||||
positions={points}
|
||||
pathOptions={{ color: color, interactive: false }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default function FlightPlan(props: FlightPlanProps) {
|
||||
return (
|
||||
<>
|
||||
<FlightPlanPath {...props} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
1
client/src/components/flightplan/index.ts
Normal file
1
client/src/components/flightplan/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default } from "./FlightPlan";
|
||||
20
client/src/components/flightplanslayer/FlightPlansLayer.tsx
Normal file
20
client/src/components/flightplanslayer/FlightPlansLayer.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import FlightPlan from "../flightplan";
|
||||
import { LayerGroup } from "react-leaflet";
|
||||
import { selectFlights } from "../../api/flightsSlice";
|
||||
import { useAppSelector } from "../../app/hooks";
|
||||
|
||||
interface FlightPlansLayerProps {
|
||||
blue: boolean;
|
||||
}
|
||||
|
||||
export default function FlightPlansLayer(props: FlightPlansLayerProps) {
|
||||
const atos = useAppSelector(selectFlights);
|
||||
const flights = props.blue ? atos.blue : atos.red;
|
||||
return (
|
||||
<LayerGroup>
|
||||
{Object.values(flights).map((flight) => {
|
||||
return <FlightPlan key={flight.id} flight={flight} selected={false} />;
|
||||
})}
|
||||
</LayerGroup>
|
||||
);
|
||||
}
|
||||
1
client/src/components/flightplanslayer/index.ts
Normal file
1
client/src/components/flightplanslayer/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default } from "./FlightPlansLayer";
|
||||
7
client/src/components/liberationmap/LiberationMap.css
Normal file
7
client/src/components/liberationmap/LiberationMap.css
Normal file
@@ -0,0 +1,7 @@
|
||||
@import "~leaflet/dist/leaflet.css";
|
||||
|
||||
.leaflet-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-height: 100vh;
|
||||
}
|
||||
22
client/src/components/liberationmap/LiberationMap.tsx
Normal file
22
client/src/components/liberationmap/LiberationMap.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import "./LiberationMap.css";
|
||||
|
||||
import { BasemapLayer } from "react-esri-leaflet";
|
||||
import ControlPointsLayer from "../controlpointslayer";
|
||||
import FlightPlansLayer from "../flightplanslayer";
|
||||
import { LatLng } from "leaflet";
|
||||
import { MapContainer } from "react-leaflet";
|
||||
|
||||
interface GameProps {
|
||||
mapCenter: LatLng;
|
||||
}
|
||||
|
||||
export default function LiberationMap(props: GameProps) {
|
||||
return (
|
||||
<MapContainer zoom={8} center={props.mapCenter}>
|
||||
<BasemapLayer name="ImageryClarity" />
|
||||
<ControlPointsLayer />
|
||||
<FlightPlansLayer blue={true} />
|
||||
<FlightPlansLayer blue={false} />
|
||||
</MapContainer>
|
||||
);
|
||||
}
|
||||
1
client/src/components/liberationmap/index.ts
Normal file
1
client/src/components/liberationmap/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default } from "./LiberationMap";
|
||||
Reference in New Issue
Block a user