Skip to content

Commit 0e061cc

Browse files
[fix]webmapv3图例矢量图片问题
AI-GEN: 70% Cursor
1 parent 1b2914d commit 0e061cc

2 files changed

Lines changed: 38 additions & 5 deletions

File tree

‎src/common/mapping/WebMapV3.js‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ const MAP_LAYER_TYPE_2_SYMBOL_TYPE = {
145145
circle: 'point',
146146
line: 'line',
147147
symbol: 'point',
148+
// 聚合点图层渲染为 symbol,符号是图标而不是颜色
149+
'point-cluster': 'point',
150+
pointCluster: 'point',
151+
point: 'point',
152+
'point-3d': 'point',
148153
fill: 'polygon',
149154
'fill-extrusion': 'polygon',
150155
heatmap: 'point',
@@ -922,9 +927,14 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
922927
switch (renderType) {
923928
case 'text':
924929
return LEGEND_RENDER_TYPE.TEXT;
930+
// 聚合点图层(矢量和图片符号都可能)按点图例处理
925931
case 'circle':
926932
case 'symbol':
927933
case 'column':
934+
case 'point':
935+
case 'point-cluster':
936+
case 'pointCluster':
937+
case 'point-3d':
928938
return LEGEND_RENDER_TYPE.POINT;
929939
case 'heatGrid':
930940
case 'heatHexagon':
@@ -952,8 +962,13 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
952962
switch (renderType) {
953963
case 'text':
954964
return LEGEND_SHAPE_TYPE.TEXT;
965+
// 聚合点图层(矢量和图片符号都可能)按点图例处理
955966
case 'circle':
956967
case 'symbol':
968+
case 'point':
969+
case 'point-cluster':
970+
case 'pointCluster':
971+
case 'point-3d':
957972
return LEGEND_SHAPE_TYPE.POINT;
958973
case 'column': {
959974
const symbolIds = {
@@ -962,7 +977,8 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
962977
squareColumn: LEGEND_SHAPE_TYPE.RECTANGLE,
963978
hexagonColumn: LEGEND_SHAPE_TYPE.HEXAGON
964979
};
965-
return symbolIds[styleSetting.shape.value] || LEGEND_SHAPE_TYPE.POINT;
980+
const columnShape = (styleSetting.shape || {}).value;
981+
return symbolIds[columnShape] || LEGEND_SHAPE_TYPE.POINT;
966982
}
967983
case 'heatHexagon':
968984
case 'heat3DHexagon':
@@ -1077,8 +1093,10 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
10771093
layerTitle
10781094
};
10791095
const renderType = styleSetting.type || layer.type;
1080-
const legendRenderType = this._getLegendRenderType(renderType);
1081-
const shape = this._getLegendShape(renderType, styleSetting);
1096+
// renderer 的 type 可能比地图图层类型更细(如聚合点 point-cluster),
1097+
// 未匹配到时回退到图层类型,避免整层图例被丢弃
1098+
const legendRenderType = this._getLegendRenderType(renderType) || this._getLegendRenderType(layer.type);
1099+
const shape = this._getLegendShape(renderType, styleSetting) || this._getLegendShape(layer.type, styleSetting);
10821100
if (['heat', 'heat3D'].includes(renderType)) {
10831101
const colorKeyMap = {
10841102
heat: 'heatmap-color',
@@ -1171,9 +1189,11 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
11711189
styleGroup = this._parseUniqueStyle(params);
11721190
break;
11731191
}
1192+
const settingField = subStyleSetting.field;
11741193
const legendItem = {
11751194
...commonStyleOptions,
1176-
themeField: (subStyleSetting.field || [])[0],
1195+
// field 可能是字符串(如线性 size 专题图)也可能是数组,字符串时不能取首字符
1196+
themeField: (Array.isArray(settingField) ? settingField[0] : settingField) || commonStyleOptions.themeField,
11771197
styleField: styleField,
11781198
styleGroup
11791199
};
@@ -1325,7 +1345,12 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
13251345
...cssStyle
13261346
};
13271347
}
1328-
return this._getSpriteStyle(symbolId, cssStyle);
1348+
// 雪碧图未加载完成或符号不在雪碧图中时退化为矢量圆点,
1349+
// 否则样式为空对象,图例项会整块空白
1350+
return this._getSpriteStyle(symbolId, cssStyle) || {
1351+
type: LEGEND_STYLE_TYPES.STYLE,
1352+
...cssStyle
1353+
};
13291354
}
13301355
case LEGEND_RENDER_TYPE.BUILTINSYMBOL: {
13311356
return {

‎test/common/mapping/WebMapV3Spec.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,10 @@ describe('WebMapV3 - legend render type and shape', () => {
17601760
expect(instance._getLegendRenderType('circle')).toBe('POINT');
17611761
expect(instance._getLegendRenderType('symbol')).toBe('POINT');
17621762
expect(instance._getLegendRenderType('column')).toBe('POINT');
1763+
expect(instance._getLegendRenderType('point')).toBe('POINT');
1764+
expect(instance._getLegendRenderType('point-cluster')).toBe('POINT');
1765+
expect(instance._getLegendRenderType('pointCluster')).toBe('POINT');
1766+
expect(instance._getLegendRenderType('point-3d')).toBe('POINT');
17631767
expect(instance._getLegendRenderType('heatGrid')).toBe('BUILTINSYMBOL');
17641768
expect(instance._getLegendRenderType('heatHexagon')).toBe('BUILTINSYMBOL');
17651769
expect(instance._getLegendRenderType('heat3DGrid')).toBe('BUILTINSYMBOL');
@@ -1785,6 +1789,10 @@ describe('WebMapV3 - legend render type and shape', () => {
17851789
expect(instance._getLegendShape('column', { shape: { value: 'squareColumn' } })).toBe('RECTANGLE');
17861790
expect(instance._getLegendShape('column', { shape: { value: 'hexagonColumn' } })).toBe('HEXAGON');
17871791
expect(instance._getLegendShape('column', { shape: { value: 'other' } })).toBe('POINT');
1792+
expect(instance._getLegendShape('point')).toBe('POINT');
1793+
expect(instance._getLegendShape('point-cluster')).toBe('POINT');
1794+
expect(instance._getLegendShape('pointCluster')).toBe('POINT');
1795+
expect(instance._getLegendShape('point-3d')).toBe('POINT');
17881796
expect(instance._getLegendShape('heatHexagon')).toBe('HEXAGON');
17891797
expect(instance._getLegendShape('heat3DHexagon')).toBe('HEXAGON');
17901798
expect(instance._getLegendShape('line')).toBe('LINE');

0 commit comments

Comments
 (0)