修复水流、等值线图层显示bug

This commit is contained in:
2026-05-28 17:02:38 +08:00
parent 6b447eb398
commit 9dc8549f31
2 changed files with 43 additions and 3 deletions
@@ -37,6 +37,8 @@ const LayerControl: React.FC = () => {
const deckLayers = data?.deckLayers ?? (deckLayer ? [deckLayer] : []);
const isContourLayerAvailable = data?.isContourLayerAvailable;
const isWaterflowLayerAvailable = data?.isWaterflowLayerAvailable;
const showContourLayer = data?.showContourLayer;
const showWaterflowLayer = data?.showWaterflowLayer;
const setShowWaterflowLayer = data?.setShowWaterflowLayer;
const setShowContourLayer = data?.setShowContourLayer;
@@ -46,6 +48,14 @@ const LayerControl: React.FC = () => {
if (!map || !data) return [];
const items: LayerItem[] = [];
const upsertLayerItem = (nextItem: LayerItem) => {
const index = items.findIndex((item) => item.id === nextItem.id);
if (index >= 0) {
items[index] = nextItem;
return;
}
items.push(nextItem);
};
map.getLayers().getArray().forEach((layer) => {
if (
@@ -56,7 +66,7 @@ const LayerControl: React.FC = () => {
const value = layer.get("value");
const name = layer.get("name");
if (value) {
items.push({
upsertLayerItem({
id: value,
name: name || value,
visible: layer.getVisible(),
@@ -80,7 +90,7 @@ const LayerControl: React.FC = () => {
return;
}
items.push({
upsertLayerItem({
id: layer.props.id,
name: layer.props.name,
visible:
@@ -91,6 +101,30 @@ const LayerControl: React.FC = () => {
});
}
if (isWaterflowLayerAvailable) {
upsertLayerItem({
id: "waterflowLayer",
name: "水流",
visible:
deckLayer?.getDeckLayerVisible("waterflowLayer") ?? showWaterflowLayer ?? false,
type: "deck",
layerRef: deckLayer?.getDeckLayerById("waterflowLayer") ?? null,
});
}
if (isContourLayerAvailable) {
upsertLayerItem({
id: "junctionContourLayer",
name: "等值线",
visible:
deckLayer?.getDeckLayerVisible("junctionContourLayer") ??
showContourLayer ??
false,
type: "deck",
layerRef: deckLayer?.getDeckLayerById("junctionContourLayer") ?? null,
});
}
return items
.filter((item) => LAYER_ORDER.includes(item.id))
.sort((a, b) => LAYER_ORDER.indexOf(a.id) - LAYER_ORDER.indexOf(b.id));
@@ -100,6 +134,8 @@ const LayerControl: React.FC = () => {
deckLayer,
isContourLayerAvailable,
isWaterflowLayerAvailable,
showContourLayer,
showWaterflowLayer,
refreshKey,
]);
@@ -126,7 +162,7 @@ const LayerControl: React.FC = () => {
.filter((layer) => layer.get("value") === item.id)
.forEach((layer) => layer.setVisible(checked));
});
} else if (item.type === "deck" && deckLayers.length > 0) {
} else if (item.type === "deck") {
deckLayers.forEach((targetDeckLayer) => {
targetDeckLayer.setDeckLayerVisible(item.id, checked);
});
@@ -65,8 +65,10 @@ interface DataContextType {
setShowPipeTextLayer?: React.Dispatch<React.SetStateAction<boolean>>;
setShowJunctionId?: React.Dispatch<React.SetStateAction<boolean>>;
setShowPipeId?: React.Dispatch<React.SetStateAction<boolean>>;
showContourLayer?: boolean;
setShowContourLayer?: React.Dispatch<React.SetStateAction<boolean>>;
isContourLayerAvailable?: boolean;
showWaterflowLayer?: boolean;
setShowWaterflowLayer?: React.Dispatch<React.SetStateAction<boolean>>;
setContourLayerAvailable?: React.Dispatch<React.SetStateAction<boolean>>;
isWaterflowLayerAvailable?: boolean;
@@ -1504,8 +1506,10 @@ const MapComponent: React.FC<MapComponentProps> = ({ children }) => {
setShowPipeId,
showJunctionId,
showPipeId,
showContourLayer,
setShowContourLayer,
isContourLayerAvailable,
showWaterflowLayer,
setContourLayerAvailable,
isWaterflowLayerAvailable,
setWaterflowLayerAvailable,