修复水流、等值线图层显示bug
This commit is contained in:
@@ -37,6 +37,8 @@ const LayerControl: React.FC = () => {
|
|||||||
const deckLayers = data?.deckLayers ?? (deckLayer ? [deckLayer] : []);
|
const deckLayers = data?.deckLayers ?? (deckLayer ? [deckLayer] : []);
|
||||||
const isContourLayerAvailable = data?.isContourLayerAvailable;
|
const isContourLayerAvailable = data?.isContourLayerAvailable;
|
||||||
const isWaterflowLayerAvailable = data?.isWaterflowLayerAvailable;
|
const isWaterflowLayerAvailable = data?.isWaterflowLayerAvailable;
|
||||||
|
const showContourLayer = data?.showContourLayer;
|
||||||
|
const showWaterflowLayer = data?.showWaterflowLayer;
|
||||||
const setShowWaterflowLayer = data?.setShowWaterflowLayer;
|
const setShowWaterflowLayer = data?.setShowWaterflowLayer;
|
||||||
const setShowContourLayer = data?.setShowContourLayer;
|
const setShowContourLayer = data?.setShowContourLayer;
|
||||||
|
|
||||||
@@ -46,6 +48,14 @@ const LayerControl: React.FC = () => {
|
|||||||
if (!map || !data) return [];
|
if (!map || !data) return [];
|
||||||
|
|
||||||
const items: LayerItem[] = [];
|
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) => {
|
map.getLayers().getArray().forEach((layer) => {
|
||||||
if (
|
if (
|
||||||
@@ -56,7 +66,7 @@ const LayerControl: React.FC = () => {
|
|||||||
const value = layer.get("value");
|
const value = layer.get("value");
|
||||||
const name = layer.get("name");
|
const name = layer.get("name");
|
||||||
if (value) {
|
if (value) {
|
||||||
items.push({
|
upsertLayerItem({
|
||||||
id: value,
|
id: value,
|
||||||
name: name || value,
|
name: name || value,
|
||||||
visible: layer.getVisible(),
|
visible: layer.getVisible(),
|
||||||
@@ -80,7 +90,7 @@ const LayerControl: React.FC = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
items.push({
|
upsertLayerItem({
|
||||||
id: layer.props.id,
|
id: layer.props.id,
|
||||||
name: layer.props.name,
|
name: layer.props.name,
|
||||||
visible:
|
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
|
return items
|
||||||
.filter((item) => LAYER_ORDER.includes(item.id))
|
.filter((item) => LAYER_ORDER.includes(item.id))
|
||||||
.sort((a, b) => LAYER_ORDER.indexOf(a.id) - LAYER_ORDER.indexOf(b.id));
|
.sort((a, b) => LAYER_ORDER.indexOf(a.id) - LAYER_ORDER.indexOf(b.id));
|
||||||
@@ -100,6 +134,8 @@ const LayerControl: React.FC = () => {
|
|||||||
deckLayer,
|
deckLayer,
|
||||||
isContourLayerAvailable,
|
isContourLayerAvailable,
|
||||||
isWaterflowLayerAvailable,
|
isWaterflowLayerAvailable,
|
||||||
|
showContourLayer,
|
||||||
|
showWaterflowLayer,
|
||||||
refreshKey,
|
refreshKey,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -126,7 +162,7 @@ const LayerControl: React.FC = () => {
|
|||||||
.filter((layer) => layer.get("value") === item.id)
|
.filter((layer) => layer.get("value") === item.id)
|
||||||
.forEach((layer) => layer.setVisible(checked));
|
.forEach((layer) => layer.setVisible(checked));
|
||||||
});
|
});
|
||||||
} else if (item.type === "deck" && deckLayers.length > 0) {
|
} else if (item.type === "deck") {
|
||||||
deckLayers.forEach((targetDeckLayer) => {
|
deckLayers.forEach((targetDeckLayer) => {
|
||||||
targetDeckLayer.setDeckLayerVisible(item.id, checked);
|
targetDeckLayer.setDeckLayerVisible(item.id, checked);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -65,8 +65,10 @@ interface DataContextType {
|
|||||||
setShowPipeTextLayer?: React.Dispatch<React.SetStateAction<boolean>>;
|
setShowPipeTextLayer?: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
setShowJunctionId?: React.Dispatch<React.SetStateAction<boolean>>;
|
setShowJunctionId?: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
setShowPipeId?: React.Dispatch<React.SetStateAction<boolean>>;
|
setShowPipeId?: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
|
showContourLayer?: boolean;
|
||||||
setShowContourLayer?: React.Dispatch<React.SetStateAction<boolean>>;
|
setShowContourLayer?: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
isContourLayerAvailable?: boolean;
|
isContourLayerAvailable?: boolean;
|
||||||
|
showWaterflowLayer?: boolean;
|
||||||
setShowWaterflowLayer?: React.Dispatch<React.SetStateAction<boolean>>;
|
setShowWaterflowLayer?: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
setContourLayerAvailable?: React.Dispatch<React.SetStateAction<boolean>>;
|
setContourLayerAvailable?: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
isWaterflowLayerAvailable?: boolean;
|
isWaterflowLayerAvailable?: boolean;
|
||||||
@@ -1504,8 +1506,10 @@ const MapComponent: React.FC<MapComponentProps> = ({ children }) => {
|
|||||||
setShowPipeId,
|
setShowPipeId,
|
||||||
showJunctionId,
|
showJunctionId,
|
||||||
showPipeId,
|
showPipeId,
|
||||||
|
showContourLayer,
|
||||||
setShowContourLayer,
|
setShowContourLayer,
|
||||||
isContourLayerAvailable,
|
isContourLayerAvailable,
|
||||||
|
showWaterflowLayer,
|
||||||
setContourLayerAvailable,
|
setContourLayerAvailable,
|
||||||
isWaterflowLayerAvailable,
|
isWaterflowLayerAvailable,
|
||||||
setWaterflowLayerAvailable,
|
setWaterflowLayerAvailable,
|
||||||
|
|||||||
Reference in New Issue
Block a user