@@ -7,6 +7,7 @@ import { Util } from '../../../core/Util';
7
7
import { addL7Layers , getL7MarkerLayers , isL7Layer } from '../../utils/L7LayerUtil' ;
8
8
9
9
const LEGEND_RENDER_TYPE = {
10
+ TEXT : 'TEXT' ,
10
11
POINT : 'POINT' ,
11
12
LINE : 'LINE' ,
12
13
FILL : 'FILL' ,
@@ -18,6 +19,7 @@ const LEGEND_RENDER_TYPE = {
18
19
} ;
19
20
20
21
const LEGEND_SHAPE_TYPE = {
22
+ TEXT : 'TEXT' ,
21
23
POINT : 'POINT' ,
22
24
LINE : 'LINE' ,
23
25
RECTANGLE : 'RECTANGLE' ,
@@ -35,6 +37,15 @@ const LEGEND_CSS_STATE_KEY = {
35
37
} ;
36
38
37
39
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
+ } ,
38
49
[ LEGEND_RENDER_TYPE . POINT ] : {
39
50
fontSize : '8px' ,
40
51
color : '#FFFFFF' ,
@@ -86,8 +97,15 @@ const LEGEND_CSS_DEFAULT = {
86
97
speed : 3
87
98
}
88
99
} ;
100
+ const LegendTextDataDrivenStyleKey = [
101
+ 'textSize' ,
102
+ 'textColor' ,
103
+ 'textOpacity' ,
104
+ 'textHaloColor'
105
+ ] ;
89
106
90
107
const LEGEND_STYLE_KEYS = {
108
+ [ LEGEND_RENDER_TYPE . TEXT ] : [ ...LegendTextDataDrivenStyleKey , 'symbolsContent' , 'textField' , 'textFont' , 'textHaloBlur' , 'textHaloWidth' ] ,
91
109
[ LEGEND_RENDER_TYPE . POINT ] : [ 'symbolsContent' , 'size' , 'color' , 'opacity' ] ,
92
110
[ LEGEND_RENDER_TYPE . BUILTINSYMBOL ] : [ 'symbolsContent' , 'size' , 'color' , 'opacity' ] ,
93
111
[ LEGEND_RENDER_TYPE . LINE ] : [ 'width' , 'color' , 'opacity' , 'lineDasharray' , 'symbolsContent' ] ,
@@ -979,7 +997,7 @@ export class WebMap extends mapboxgl.Evented {
979
997
const { catalogs = [ ] } = this . _mapResourceInfo ;
980
998
const originLayers = this . _getLayerInfosFromCatalogs ( catalogs , 'catalogType' ) ;
981
999
for ( const layer of originLayers ) {
982
- const { renderer } = layer . visualization || { } ;
1000
+ const { renderer, label } = layer . visualization || { } ;
983
1001
if ( ! renderer ) {
984
1002
continue ;
985
1003
}
@@ -993,6 +1011,20 @@ export class WebMap extends mapboxgl.Evented {
993
1011
}
994
1012
const nextLayer = Object . assign ( { } , layerFromMapInfo , { title : layer . title , themeField } ) ;
995
1013
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
+ }
996
1028
const layerLegends = styleSettings . reduce ( ( legends , styleSetting ) => {
997
1029
const legendItems = this . _createLayerLegendList ( nextLayer , styleSetting ) ;
998
1030
legendItems && legends . push ( ...legendItems ) ;
@@ -1038,6 +1070,8 @@ export class WebMap extends mapboxgl.Evented {
1038
1070
1039
1071
_getLegendRenderType ( renderType ) {
1040
1072
switch ( renderType ) {
1073
+ case 'text' :
1074
+ return LEGEND_RENDER_TYPE . TEXT ;
1041
1075
case 'circle' :
1042
1076
case 'symbol' :
1043
1077
case 'column' :
@@ -1066,6 +1100,8 @@ export class WebMap extends mapboxgl.Evented {
1066
1100
1067
1101
_getLegendShape ( renderType , styleSetting ) {
1068
1102
switch ( renderType ) {
1103
+ case 'text' :
1104
+ return LEGEND_SHAPE_TYPE . TEXT ;
1069
1105
case 'circle' :
1070
1106
case 'symbol' :
1071
1107
return LEGEND_SHAPE_TYPE . POINT ;
@@ -1163,6 +1199,17 @@ export class WebMap extends mapboxgl.Evented {
1163
1199
} ) ;
1164
1200
}
1165
1201
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
+
1166
1213
_createLayerLegendList ( layer , styleSetting ) {
1167
1214
const layerId = layer . id ;
1168
1215
const layerTitle = layer . title ;
@@ -1203,7 +1250,7 @@ export class WebMap extends mapboxgl.Evented {
1203
1250
this . _transStyleSetting ( renderType , styleSetting ) ;
1204
1251
const simpleStyle = this . _getLegendSimpleStyle ( styleSetting , keys ) ;
1205
1252
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 ) ;
1207
1254
// 3D线,动画线
1208
1255
if ( legendRenderType === LEGEND_RENDER_TYPE . ANIMATELINE ) {
1209
1256
// isReplaceLineColor: 3D线,动画线:使用符号替换线颜色,图例中将不再显示线颜色
@@ -1401,6 +1448,13 @@ export class WebMap extends mapboxgl.Evented {
1401
1448
} ) ;
1402
1449
let { symbolId = LEGEND_SYMBOL_DEFAULT [ legendRenderType ] , style } = customValue . symbolsContent || { } ;
1403
1450
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
+ }
1404
1458
case LEGEND_RENDER_TYPE . POINT : {
1405
1459
const icon = this . _getIconById ( symbolId ) ;
1406
1460
const iconType = icon ? 'BASE' : 'SERVICE' ;
0 commit comments