mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add culling exclusion zones display to the new map.
https://github.com/dcs-liberation/dcs_liberation/issues/2158
This commit is contained in:
@@ -479,6 +479,7 @@ export type Game = {
|
||||
threat_zones: ThreatZoneContainer;
|
||||
navmeshes: NavMeshes;
|
||||
map_center?: LatLng;
|
||||
unculled_zones: UnculledZone[];
|
||||
};
|
||||
export type MapZones = {
|
||||
inclusion: LatLng[][];
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
import { navMeshUpdated } from "./navMeshSlice";
|
||||
import { updateTgo } from "./tgosSlice";
|
||||
import { threatZonesUpdated } from "./threatZonesSlice";
|
||||
import { unculledZonesUpdated } from "./unculledZonesSlice";
|
||||
import { LatLng } from "leaflet";
|
||||
import { updateIadsConnection } from "./iadsNetworkSlice";
|
||||
import { IadsConnection } from "./_liberationApi";
|
||||
@@ -87,6 +88,16 @@ export const handleStreamedEvents = (
|
||||
});
|
||||
}
|
||||
|
||||
if (events.unculled_zones_updated) {
|
||||
backend.get(`/map-zones/unculled`).then(
|
||||
(result) => {
|
||||
if (result.data) {
|
||||
dispatch(unculledZonesUpdated(result.data));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (events.threat_zones_updated) {
|
||||
dispatch(liberationApi.endpoints.getThreatZones.initiate()).then(
|
||||
(result) => {
|
||||
|
||||
36
client/src/api/unculledZonesSlice.ts
Normal file
36
client/src/api/unculledZonesSlice.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { RootState } from "../app/store";
|
||||
import { gameLoaded, gameUnloaded } from "./actions";
|
||||
import { UnculledZone } from "./liberationApi";
|
||||
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
interface UnculledZonesState {
|
||||
zones: UnculledZone[];
|
||||
}
|
||||
|
||||
const initialState: UnculledZonesState = {
|
||||
zones: [],
|
||||
};
|
||||
|
||||
export const unculledZonesSlice = createSlice({
|
||||
name: "unculledZonesState",
|
||||
initialState,
|
||||
reducers: {
|
||||
updated: (state, action: PayloadAction<UnculledZone[]>) => {
|
||||
state.zones = action.payload;
|
||||
},
|
||||
},
|
||||
extraReducers: (builder) => {
|
||||
builder.addCase(gameLoaded, (state, action) => {
|
||||
state.zones = action.payload.unculled_zones;
|
||||
});
|
||||
builder.addCase(gameUnloaded, (state) => {
|
||||
state.zones = initialState.zones;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const { updated: unculledZonesUpdated } = unculledZonesSlice.actions;
|
||||
|
||||
export const selectUnculledZones = (state: RootState) => state.unculledZones;
|
||||
|
||||
export default unculledZonesSlice.reducer;
|
||||
@@ -9,6 +9,7 @@ import supplyRoutesReducer from "../api/supplyRoutesSlice";
|
||||
import tgosReducer from "../api/tgosSlice";
|
||||
import iadsNetworkReducer from "../api/iadsNetworkSlice";
|
||||
import threatZonesReducer from "../api/threatZonesSlice";
|
||||
import unculledZonesReducer from "../api/unculledZonesSlice";
|
||||
import { Action, ThunkAction, configureStore } from "@reduxjs/toolkit";
|
||||
|
||||
export const store = configureStore({
|
||||
@@ -24,6 +25,7 @@ export const store = configureStore({
|
||||
tgos: tgosReducer,
|
||||
threatZones: threatZonesReducer,
|
||||
[baseApi.reducerPath]: baseApi.reducer,
|
||||
unculledZones: unculledZonesReducer,
|
||||
},
|
||||
middleware: (getDefaultMiddleware) =>
|
||||
getDefaultMiddleware().concat(baseApi.middleware),
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { UnculledZone } from "../../api/liberationApi";
|
||||
import { selectUnculledZones } from "../../api/unculledZonesSlice";
|
||||
import { useAppSelector } from "../../app/hooks";
|
||||
import { LayerGroup, LayersControl, Circle } from "react-leaflet";
|
||||
|
||||
interface CullingExclusionCirclesProps {
|
||||
zones: UnculledZone[];
|
||||
}
|
||||
|
||||
const CullingExclusionCircles = (props: CullingExclusionCirclesProps) => {
|
||||
return (
|
||||
<>
|
||||
<LayerGroup>
|
||||
{props.zones.map((zone, idx) => {
|
||||
return (
|
||||
<Circle
|
||||
key={idx}
|
||||
center={zone.position}
|
||||
radius={zone.radius}
|
||||
color="#b4ff8c"
|
||||
fill={false}
|
||||
interactive={false}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</LayerGroup>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default function CullingExclusionZones() {
|
||||
const data = useAppSelector(selectUnculledZones).zones;
|
||||
var cez = <></>;
|
||||
|
||||
if (!data) {
|
||||
console.log("Empty response when loading culling exclusion zones");
|
||||
} else {
|
||||
cez = (
|
||||
<CullingExclusionCircles zones={data}></CullingExclusionCircles>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<LayersControl.Overlay name="Culling exclusion zones">
|
||||
{cez}
|
||||
</LayersControl.Overlay>
|
||||
);
|
||||
}
|
||||
1
client/src/components/cullingexclusionzones/index.ts
Normal file
1
client/src/components/cullingexclusionzones/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default } from "./CullingExclusionZones";
|
||||
@@ -18,6 +18,7 @@ import { useEffect, useRef } from "react";
|
||||
import { BasemapLayer } from "react-esri-leaflet";
|
||||
import { LayersControl, MapContainer, ScaleControl } from "react-leaflet";
|
||||
import Iadsnetworklayer from "../iadsnetworklayer";
|
||||
import CullingExclusionZones from "../cullingexclusionzones/CullingExclusionZones"
|
||||
import LeafletRuler from "../ruler/Ruler";
|
||||
|
||||
export default function LiberationMap() {
|
||||
@@ -109,6 +110,7 @@ export default function LiberationMap() {
|
||||
<NavMeshLayer blue={false} />
|
||||
</LayersControl.Overlay>
|
||||
<TerrainZonesLayers />
|
||||
<CullingExclusionZones />
|
||||
<WaypointDebugZonesControls />
|
||||
</LayersControl>
|
||||
</MapContainer>
|
||||
|
||||
Reference in New Issue
Block a user