@@ -7,6 +7,7 @@ import { Util } from '../../../core/Util';
77import { addL7Layers , getL7MarkerLayers , isL7Layer } from '../../utils/L7LayerUtil' ;
88
99const 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
2021const 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
3739const 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
90107const 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' ;
0 commit comments