修复样式设置覆盖的bug

This commit is contained in:
JIANG
2025-12-22 17:16:07 +08:00
parent b35af91008
commit 6c1e193f60

View File

@@ -272,8 +272,14 @@ const StyleEditorPanel: React.FC<StyleEditorPanelProps> = ({
);
// 保存当前图层的样式状态
const saveLayerStyle = useCallback(
(layerId?: string, newLegendConfig?: LegendStyleConfig) => {
if (!selectedRenderLayer || !styleConfig.property) {
(
layerId?: string,
newLegendConfig?: LegendStyleConfig,
overrideStyleConfig?: StyleConfig
) => {
const currentStyleConfig = overrideStyleConfig || styleConfig;
if (!currentStyleConfig.property) {
console.warn("无法保存样式:缺少必要的图层或样式配置");
return;
}
@@ -281,17 +287,17 @@ const StyleEditorPanel: React.FC<StyleEditorPanelProps> = ({
// 如果没有传入图例配置,则创建一个默认的空配置
const layerName =
newLegendConfig?.layerName ||
selectedRenderLayer.get("name") ||
selectedRenderLayer?.get("name") ||
`图层${layerId}`;
const property = availableProperties.find(
(p) => p.value === styleConfig.property
(p) => p.value === currentStyleConfig.property
);
let legendConfig: LegendStyleConfig = newLegendConfig || {
layerId,
layerName,
property: property?.name || styleConfig.property,
property: property?.name || currentStyleConfig.property,
colors: [],
type: selectedRenderLayer.get("type"),
type: selectedRenderLayer?.get("type") || "point",
dimensions: [],
breaks: [],
};
@@ -299,7 +305,7 @@ const StyleEditorPanel: React.FC<StyleEditorPanelProps> = ({
const newStyleState: LayerStyleState = {
layerId,
layerName,
styleConfig: { ...styleConfig },
styleConfig: { ...currentStyleConfig },
legendConfig: { ...legendConfig },
isActive: true,
};
@@ -320,7 +326,7 @@ const StyleEditorPanel: React.FC<StyleEditorPanelProps> = ({
}
});
},
[selectedRenderLayer, styleConfig]
[selectedRenderLayer, styleConfig, availableProperties]
);
// 设置分类样式参数,触发样式应用
const setStyleState = () => {
@@ -663,7 +669,7 @@ const StyleEditorPanel: React.FC<StyleEditorPanelProps> = ({
};
// 自动保存样式状态,直接传入图例配置
setTimeout(() => {
saveLayerStyle(renderLayer.get("value"), legendConfig);
saveLayerStyle(renderLayer.get("value"), legendConfig, styleConfig);
}, 100);
};
// 应用样式函数,传入 breaks 数据