Skip to content

Commit 6f0013d

Browse files
committed
[feature] 对接文本标签图例 review by xiongjj
1 parent 02bf9a3 commit 6f0013d

File tree

3 files changed

+464
-2
lines changed

3 files changed

+464
-2
lines changed

src/mapboxgl/mapping/webmap/v3/WebMap.js

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Util } from '../../../core/Util';
77
import { addL7Layers, getL7MarkerLayers, isL7Layer } from '../../utils/L7LayerUtil';
88

99
const LEGEND_RENDER_TYPE = {
10+
TEXT: 'TEXT',
1011
POINT: 'POINT',
1112
LINE: 'LINE',
1213
FILL: 'FILL',
@@ -18,6 +19,7 @@ const LEGEND_RENDER_TYPE = {
1819
};
1920

2021
const LEGEND_SHAPE_TYPE = {
22+
TEXT: 'TEXT',
2123
POINT: 'POINT',
2224
LINE: 'LINE',
2325
RECTANGLE: 'RECTANGLE',
@@ -35,6 +37,15 @@ const LEGEND_CSS_STATE_KEY = {
3537
};
3638

3739
const LEGEND_CSS_DEFAULT = {
40+
[LEGEND_RENDER_TYPE.TEXT]: {
41+
textSize: '16px',
42+
textColor: '#FFFFFF',
43+
textOpacity: 1,
44+
textHaloColor: '#242424',
45+
textHaloBlur: 1,
46+
textHaloWidth: 1,
47+
textFont: 'Microsoft YaHei'
48+
},
3849
[LEGEND_RENDER_TYPE.POINT]: {
3950
fontSize: '8px',
4051
color: '#FFFFFF',
@@ -86,8 +97,15 @@ const LEGEND_CSS_DEFAULT = {
8697
speed: 3
8798
}
8899
};
100+
const LegendTextDataDrivenStyleKey = [
101+
'textSize',
102+
'textColor',
103+
'textOpacity',
104+
'textHaloColor'
105+
];
89106

90107
const LEGEND_STYLE_KEYS = {
108+
[LEGEND_RENDER_TYPE.TEXT]: [...LegendTextDataDrivenStyleKey, 'symbolsContent', 'textField', 'textFont', 'textHaloBlur', 'textHaloWidth'],
91109
[LEGEND_RENDER_TYPE.POINT]: ['symbolsContent', 'size', 'color', 'opacity'],
92110
[LEGEND_RENDER_TYPE.BUILTINSYMBOL]: ['symbolsContent', 'size', 'color', 'opacity'],
93111
[LEGEND_RENDER_TYPE.LINE]: ['width', 'color', 'opacity', 'lineDasharray', 'symbolsContent'],
@@ -979,7 +997,7 @@ export class WebMap extends mapboxgl.Evented {
979997
const { catalogs = [] } = this._mapResourceInfo;
980998
const originLayers = this._getLayerInfosFromCatalogs(catalogs, 'catalogType');
981999
for (const layer of originLayers) {
982-
const { renderer } = layer.visualization || {};
1000+
const { renderer, label } = layer.visualization || {};
9831001
if (!renderer) {
9841002
continue;
9851003
}
@@ -993,6 +1011,20 @@ export class WebMap extends mapboxgl.Evented {
9931011
}
9941012
const nextLayer = Object.assign({}, layerFromMapInfo, { title: layer.title, themeField });
9951013
const styleSettings = this._parseRendererStyleData(renderer);
1014+
// 线面文本标签
1015+
if (label) {
1016+
styleSettings.push({...label, type: 'text'});
1017+
if (label.symbolsContent.value.symbolId) {
1018+
styleSettings.push({...label, type: 'symbol'});
1019+
}
1020+
}
1021+
// 点文本标签
1022+
if (styleSettings[0].textField && styleSettings[0].textField.value) {
1023+
styleSettings.push({
1024+
...styleSettings[0],
1025+
type: 'text'
1026+
});
1027+
}
9961028
const layerLegends = styleSettings.reduce((legends, styleSetting) => {
9971029
const legendItems = this._createLayerLegendList(nextLayer, styleSetting);
9981030
legendItems && legends.push(...legendItems);
@@ -1038,6 +1070,8 @@ export class WebMap extends mapboxgl.Evented {
10381070

10391071
_getLegendRenderType(renderType) {
10401072
switch (renderType) {
1073+
case 'text':
1074+
return LEGEND_RENDER_TYPE.TEXT;
10411075
case 'circle':
10421076
case 'symbol':
10431077
case 'column':
@@ -1066,6 +1100,8 @@ export class WebMap extends mapboxgl.Evented {
10661100

10671101
_getLegendShape(renderType, styleSetting) {
10681102
switch (renderType) {
1103+
case 'text':
1104+
return LEGEND_SHAPE_TYPE.TEXT;
10691105
case 'circle':
10701106
case 'symbol':
10711107
return LEGEND_SHAPE_TYPE.POINT;
@@ -1163,6 +1199,17 @@ export class WebMap extends mapboxgl.Evented {
11631199
});
11641200
}
11651201

1202+
_getDataDrivenStyleKeys(legendType, keys, styleSetting) {
1203+
const DataDrivenStyleKeyObj = {
1204+
[LEGEND_RENDER_TYPE.TEXT]: LegendTextDataDrivenStyleKey
1205+
};
1206+
const porpertyKeys = DataDrivenStyleKeyObj[legendType] || keys;
1207+
const dataKeys = porpertyKeys.filter(
1208+
(k) => styleSetting[k] && styleSetting[k].type !== 'simple'
1209+
);
1210+
return dataKeys;
1211+
}
1212+
11661213
_createLayerLegendList(layer, styleSetting) {
11671214
const layerId = layer.id;
11681215
const layerTitle = layer.title;
@@ -1203,7 +1250,7 @@ export class WebMap extends mapboxgl.Evented {
12031250
this._transStyleSetting(renderType, styleSetting);
12041251
const simpleStyle = this._getLegendSimpleStyle(styleSetting, keys);
12051252
const simpleResData = this._parseLegendtyle({ legendRenderType, customValue: simpleStyle });
1206-
let dataKeys = keys.filter((k) => styleSetting[k] && styleSetting[k].type !== 'simple');
1253+
let dataKeys = this._getDataDrivenStyleKeys(legendRenderType, keys, styleSetting);
12071254
// 3D线,动画线
12081255
if (legendRenderType === LEGEND_RENDER_TYPE.ANIMATELINE) {
12091256
// isReplaceLineColor: 3D线,动画线:使用符号替换线颜色,图例中将不再显示线颜色
@@ -1401,6 +1448,13 @@ export class WebMap extends mapboxgl.Evented {
14011448
});
14021449
let { symbolId = LEGEND_SYMBOL_DEFAULT[legendRenderType], style } = customValue.symbolsContent || {};
14031450
switch (legendRenderType) {
1451+
case LEGEND_RENDER_TYPE.TEXT: {
1452+
return {
1453+
type: LEGEND_STYLE_TYPES.STYLE,
1454+
icon: 'supermapol-icons-text-layer',
1455+
...cssStyle
1456+
}
1457+
}
14041458
case LEGEND_RENDER_TYPE.POINT: {
14051459
const icon = this._getIconById(symbolId);
14061460
const iconType = icon ? 'BASE' : 'SERVICE';

test/mapboxgl/mapping/WebMapV3Spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,4 +947,27 @@ describe('mapboxgl-webmap3.0', () => {
947947
done();
948948
});
949949
});
950+
951+
it('label legend', (done) => {
952+
spyOn(FetchRequest, 'get').and.callFake((url) => {
953+
if (url.indexOf('map.json') > -1) {
954+
return Promise.resolve(new Response(mapstudioWebMap_labelLegend));
955+
} else if (url.indexOf('617580084.json') > -1) {
956+
return Promise.resolve(new Response(msProjectINfo_labelLegend));
957+
} else if (url.indexOf('/sprite') > -1) {
958+
return Promise.resolve(new Response(msSpriteInfo));
959+
}
960+
return Promise.resolve();
961+
});
962+
mapstudioWebmap = new WebMap(id, {
963+
server: server
964+
});
965+
966+
mapstudioWebmap.on('addlayerssucceeded', ({ map }) => {
967+
const webMapV3 = mapstudioWebmap._getWebMapInstance();
968+
expect(map).not.toBeUndefined();
969+
expect(webMapV3.getLegendInfo().length).toBe(6);
970+
done();
971+
});
972+
});
950973
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy