Skip to content

Commit 05e3dd2

Browse files
committed
fix:修复3D柱状图开启符号数据驱动和切换填充为渐变时,图例不显示的问题
AI-GEN: 100% gpt-6.1-sol
1 parent 932e37d commit 05e3dd2

2 files changed

Lines changed: 144 additions & 0 deletions

File tree

‎src/common/mapping/WebMapV3.js‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ const MAP_LAYER_TYPE_2_SYMBOL_TYPE = {
150150
pointCluster: 'point',
151151
point: 'point',
152152
'point-3d': 'point',
153+
column: 'point',
153154
fill: 'polygon',
154155
'fill-extrusion': 'polygon',
155156
heatmap: 'point',
@@ -906,6 +907,53 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
906907
}
907908
}
908909

910+
_normalizeColumnStyleSetting(styleSetting) {
911+
if (!styleSetting || styleSetting.type !== 'column') {
912+
return styleSetting;
913+
}
914+
const normalizedStyleSetting = { ...styleSetting };
915+
const symbolIds = {
916+
cylinder: 'circle',
917+
triangleColumn: 'triangle',
918+
squareColumn: 'rectangle',
919+
hexagonColumn: 'hexagon'
920+
};
921+
const toSymbol = (value) => ({ symbolId: value ? symbolIds[value] || 'circle' : 'circle' });
922+
const shape = styleSetting.shape;
923+
if (shape && shape.type === 'simple') {
924+
normalizedStyleSetting.symbolsContent = {
925+
...shape,
926+
value: toSymbol(shape.value)
927+
};
928+
} else if (shape && ['unique', 'range'].includes(shape.type)) {
929+
normalizedStyleSetting.symbolsContent = {
930+
...shape,
931+
defaultValue: toSymbol(shape.defaultValue),
932+
values: Array.isArray(shape.values)
933+
? shape.values.map((item) => ({ ...item, value: toSymbol(item.value) }))
934+
: []
935+
};
936+
}
937+
938+
const sourceColor = styleSetting.sourceColor && styleSetting.sourceColor.value;
939+
const targetColor = styleSetting.targetColor && styleSetting.targetColor.value;
940+
if (sourceColor && targetColor) {
941+
normalizedStyleSetting.color = {
942+
type: 'unique',
943+
field: '',
944+
defaultCustomFields: [],
945+
values: [
946+
{ key: 'sourceColor', value: sourceColor },
947+
{ key: 'targetColor', value: targetColor }
948+
],
949+
defaultValue: sourceColor,
950+
interpolateInfo: { type: 'linear' },
951+
ribbon: [sourceColor, targetColor]
952+
};
953+
}
954+
return normalizedStyleSetting;
955+
}
956+
909957
_getLegendSimpleStyle(styleSetting, keys) {
910958
const simpleStyle = {};
911959
if (keys) {
@@ -1085,6 +1133,7 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
10851133
}
10861134

10871135
_createLayerLegendList(layer, styleSetting) {
1136+
styleSetting = this._normalizeColumnStyleSetting(styleSetting);
10881137
const layerId = layer.id;
10891138
const layerTitle = layer.title;
10901139
const textFieldName = styleSetting.type === 'text' && styleSetting.textField && styleSetting.textField.value.replace(/^\{|\}$/g, '');

‎test/common/mapping/WebMapV3Spec.js‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,6 +2028,101 @@ describe('WebMapV3 - _createLayerLegendList', () => {
20282028
expect(linearLegend.styleGroup[0].style.colors).toEqual(['#FF0000', '#0000FF']);
20292029
});
20302030

2031+
it('should create gradient legend for column source and target colors', () => {
2032+
const { instance } = createTestContext();
2033+
// Column symbols contain symbolId, not the style.paint used by line/fill symbols.
2034+
spyOn(instance, '_getImageIdFromValue').and.callThrough();
2035+
const layer = { id: 'column1', title: 'Column', type: 'point-extrusion' };
2036+
const styleSetting = {
2037+
type: 'column',
2038+
color: { type: 'simple', value: '#EE4D5A' },
2039+
sourceColor: { type: 'simple', value: '#4A90E2' },
2040+
targetColor: { type: 'simple', value: '#7ED321' },
2041+
size: { type: 'simple', value: 12 },
2042+
opacity: { type: 'simple', value: 1 },
2043+
shape: { type: 'simple', value: 'cylinder' }
2044+
};
2045+
2046+
const result = instance._createLayerLegendList(layer, styleSetting);
2047+
const colorLegend = result.find((item) => item.styleField === 'color');
2048+
2049+
expect(result).toHaveLength(2);
2050+
expect(result.some((item) => !item.styleField)).toBe(true);
2051+
expect(colorLegend).toBeDefined();
2052+
expect(colorLegend.styleGroup).toHaveLength(1);
2053+
expect(colorLegend.styleGroup[0].style.colors).toEqual([
2054+
{ key: 'sourceColor', value: '#4A90E2' },
2055+
{ key: 'targetColor', value: '#7ED321' }
2056+
]);
2057+
expect(instance._getImageIdFromValue).not.toHaveBeenCalled();
2058+
});
2059+
2060+
it('should keep the column gradient legend when size is data driven', () => {
2061+
const { instance } = createTestContext();
2062+
const layer = { id: 'column3', title: 'Column', type: 'point-extrusion' };
2063+
const styleSetting = {
2064+
type: 'column',
2065+
color: { type: 'simple', value: 'rgba(34,3,6,1)' },
2066+
sourceColor: { type: 'simple', value: '#D53E4F' },
2067+
targetColor: { type: 'simple', value: '#3288BD' },
2068+
size: {
2069+
type: 'unique',
2070+
field: ['smpid'],
2071+
defaultValue: 12,
2072+
values: [
2073+
{ key: 1, value: 1 },
2074+
{ key: 136, value: 136 }
2075+
],
2076+
interpolateInfo: { type: 'linear' }
2077+
},
2078+
opacity: { type: 'simple', value: 0.9 },
2079+
shape: { type: 'simple', value: 'cylinder' }
2080+
};
2081+
2082+
const result = instance._createLayerLegendList(layer, styleSetting);
2083+
const colorLegend = result.find((item) => item.styleField === 'color');
2084+
const sizeLegend = result.find((item) => item.styleField === 'size');
2085+
2086+
expect(colorLegend).toBeDefined();
2087+
expect(colorLegend.styleGroup[0].style.colors).toEqual([
2088+
{ key: 'sourceColor', value: '#D53E4F' },
2089+
{ key: 'targetColor', value: '#3288BD' }
2090+
]);
2091+
expect(sizeLegend).toBeDefined();
2092+
});
2093+
2094+
it('should expose data driven column shapes as symbolsContent legends', () => {
2095+
const { instance } = createTestContext();
2096+
const layer = { id: 'column2', title: 'Column', type: 'point-extrusion' };
2097+
const styleSetting = {
2098+
type: 'column',
2099+
color: { type: 'simple', value: '#4A90E2' },
2100+
size: { type: 'simple', value: 12 },
2101+
opacity: { type: 'simple', value: 1 },
2102+
shape: {
2103+
type: 'unique',
2104+
field: ['TYPE'],
2105+
values: [
2106+
{ key: 'A', value: 'triangleColumn' },
2107+
{ key: 'B', value: 'squareColumn' }
2108+
],
2109+
defaultValue: 'cylinder',
2110+
interpolateInfo: { type: 'custom' }
2111+
}
2112+
};
2113+
2114+
const normalized = instance._normalizeColumnStyleSetting(styleSetting);
2115+
expect(normalized.symbolsContent.values.map((item) => item.value.symbolId)).toEqual(['triangle', 'rectangle']);
2116+
expect(normalized.symbolsContent.defaultValue).toEqual({ symbolId: 'circle' });
2117+
2118+
const result = instance._createLayerLegendList(layer, styleSetting);
2119+
const symbolLegend = result.find((item) => item.styleField === 'symbolsContent');
2120+
expect(symbolLegend).toBeDefined();
2121+
expect(symbolLegend.themeField).toBe('TYPE');
2122+
expect(symbolLegend.styleGroup).toHaveLength(3);
2123+
expect(symbolLegend.styleGroup.map((item) => item.fieldValue)).toEqual(['A', 'B', null]);
2124+
});
2125+
20312126
it('should create range style groups for non-color data driven field', () => {
20322127
const { instance } = createTestContext();
20332128
const layer = { id: 'l1', title: 'Layer', type: 'circle' };

0 commit comments

Comments
 (0)