From 9dc8549f31a298b8d46fc9e97b80a357157331f8 Mon Sep 17 00:00:00 2001 From: Huarch Date: Thu, 28 May 2026 17:02:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B0=B4=E6=B5=81=E3=80=81?= =?UTF-8?q?=E7=AD=89=E5=80=BC=E7=BA=BF=E5=9B=BE=E5=B1=82=E6=98=BE=E7=A4=BA?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../olmap/core/Controls/LayerControl.tsx | 42 +++++++++++++++++-- src/components/olmap/core/MapComponent.tsx | 4 ++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/components/olmap/core/Controls/LayerControl.tsx b/src/components/olmap/core/Controls/LayerControl.tsx index 6796d4d..a503e3b 100644 --- a/src/components/olmap/core/Controls/LayerControl.tsx +++ b/src/components/olmap/core/Controls/LayerControl.tsx @@ -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); }); diff --git a/src/components/olmap/core/MapComponent.tsx b/src/components/olmap/core/MapComponent.tsx index 94d76e2..64ad653 100644 --- a/src/components/olmap/core/MapComponent.tsx +++ b/src/components/olmap/core/MapComponent.tsx @@ -65,8 +65,10 @@ interface DataContextType { setShowPipeTextLayer?: React.Dispatch>; setShowJunctionId?: React.Dispatch>; setShowPipeId?: React.Dispatch>; + showContourLayer?: boolean; setShowContourLayer?: React.Dispatch>; isContourLayerAvailable?: boolean; + showWaterflowLayer?: boolean; setShowWaterflowLayer?: React.Dispatch>; setContourLayerAvailable?: React.Dispatch>; isWaterflowLayerAvailable?: boolean; @@ -1504,8 +1506,10 @@ const MapComponent: React.FC = ({ children }) => { setShowPipeId, showJunctionId, showPipeId, + showContourLayer, setShowContourLayer, isContourLayerAvailable, + showWaterflowLayer, setContourLayerAvailable, isWaterflowLayerAvailable, setWaterflowLayerAvailable,