Skip to content

Commit 93c10ec

Browse files
committed
feat: MS保存styleSetting带有custom类型的图层,打开地图报错
(reviewed by xjj)
1 parent f92710e commit 93c10ec

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

src/common/mapping/WebMapV3.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ const LEGEND_SYMBOL_DEFAULT = {
127127
const LegendType = {
128128
LINEAR: 'LINEAR',
129129
UNIQUE: 'UNIQUE',
130-
RANGE: 'RANGE'
130+
RANGE: 'RANGE',
131+
CUSTOM: 'CUSTOM'
131132
};
132133

133134
const SymbolType = {
@@ -1005,6 +1006,10 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
10051006
if (currentType === 'simple') {
10061007
return !!this._getImageIdFromValue(symbolsContent.value.style, SymbolType[symbolType]).length;
10071008
}
1009+
if(currentType === 'custom') {
1010+
// 表达式暂不支持图例显示
1011+
return false;
1012+
}
10081013
const styles = symbolsContent.values.map((v) => v.value).concat(symbolsContent.defaultValue);
10091014
return styles.every((v) => {
10101015
return !!this._getImageIdFromValue(v.style, SymbolType[symbolType]).length;
@@ -1171,6 +1176,9 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
11711176
}
11721177
return LegendType.UNIQUE;
11731178
}
1179+
if(currentType === 'custom') {
1180+
return LegendType.CUSTOM;
1181+
}
11741182
return LegendType.RANGE;
11751183
}
11761184

test/common/mapping/WebMapV3Spec.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,57 @@ describe('WebMapV3 - _getLegendInfos', () => {
382382
});
383383
});
384384
});
385+
386+
describe('WebMapV3 - legend symbol/style helpers', () => {
387+
let instance;
388+
389+
beforeEach(() => {
390+
instance = createWebMapV3Instance();
391+
});
392+
393+
describe('_isAllPictureSymbolSaved', () => {
394+
it('should return false when symbolsContent type is custom for line symbol', () => {
395+
// custom 为表达式类型,图例暂不支持,直接返回 false
396+
const symbolsContent = {
397+
type: 'custom',
398+
value: { style: { 'line-pattern': 'some-image' } }
399+
};
400+
401+
expect(instance._isAllPictureSymbolSaved('line', symbolsContent, {})).toBe(false);
402+
});
403+
404+
it('should return false when symbolsContent type is custom for polygon symbol', () => {
405+
const symbolsContent = {
406+
type: 'custom',
407+
values: [{ value: { style: { 'fill-pattern': 'some-image' } } }],
408+
defaultValue: { style: { 'fill-pattern': 'default-image' } }
409+
};
410+
411+
expect(instance._isAllPictureSymbolSaved('polygon', symbolsContent, {})).toBe(false);
412+
});
413+
});
414+
415+
describe('_getLegendStyleType', () => {
416+
it('should return CUSTOM when currentType is custom', () => {
417+
const result = instance._getLegendStyleType({
418+
styleField: 'color',
419+
currentType: 'custom',
420+
custom: [],
421+
interpolateInfo: {}
422+
});
423+
424+
expect(result).toBe('CUSTOM');
425+
});
426+
427+
it('should return CUSTOM for non-color styleField when currentType is custom', () => {
428+
const result = instance._getLegendStyleType({
429+
styleField: 'width',
430+
currentType: 'custom',
431+
custom: [{ key: 'expr' }],
432+
interpolateInfo: { type: 'custom' }
433+
});
434+
435+
expect(result).toBe('CUSTOM');
436+
});
437+
});
438+
});

0 commit comments

Comments
 (0)