@@ -524,6 +524,81 @@ describe('WebMapV3 - legend symbol/style helpers', () => {
524524 } ) ;
525525 } ) ;
526526
527+ describe ( '_isShowLegendSingleItem' , ( ) => {
528+ it ( '无数据驱动时显示单项' , ( ) => {
529+ expect ( instance . _isShowLegendSingleItem ( [ ] , false ) ) . toBe ( true ) ;
530+ } ) ;
531+
532+ it ( 'color 为线性数据驱动时显示单项' , ( ) => {
533+ expect ( instance . _isShowLegendSingleItem ( [ 'color' ] , true ) ) . toBe ( true ) ;
534+ } ) ;
535+
536+ it ( 'color 非线性数据驱动时不显示单项' , ( ) => {
537+ expect ( instance . _isShowLegendSingleItem ( [ 'color' ] , false ) ) . toBe ( false ) ;
538+ } ) ;
539+
540+ it ( '面与轮廓都数据驱动时不显示单项,避免重复的面图例' , ( ) => {
541+ expect ( instance . _isShowLegendSingleItem ( [ 'color' , 'outlineColor' ] , true ) ) . toBe ( false ) ;
542+ } ) ;
543+
544+ it ( '只有轮廓色数据驱动时需要显示面的单项(面 + 轮廓色专题图)' , ( ) => {
545+ expect ( instance . _isShowLegendSingleItem ( [ 'outlineColor' ] , false ) ) . toBe ( true ) ;
546+ } ) ;
547+
548+ it ( '只有轮廓符号或轮廓宽/透明度数据驱动时需要显示面的单项' , ( ) => {
549+ expect ( instance . _isShowLegendSingleItem ( [ 'outlineSymbolsContent' ] , false ) ) . toBe ( true ) ;
550+ expect ( instance . _isShowLegendSingleItem ( [ 'outlineWidth' ] , false ) ) . toBe ( true ) ;
551+ expect ( instance . _isShowLegendSingleItem ( [ 'outlineOpacity' ] , false ) ) . toBe ( true ) ;
552+ } ) ;
553+
554+ it ( '填充符号数据驱动时不显示单项,符号分组本身即为面图例' , ( ) => {
555+ expect ( instance . _isShowLegendSingleItem ( [ 'symbolsContent' ] , false ) ) . toBe ( false ) ;
556+ } ) ;
557+
558+ it ( '轮廓属性与非轮廓属性混合驱动时不显示单项' , ( ) => {
559+ expect ( instance . _isShowLegendSingleItem ( [ 'symbolsContent' , 'outlineColor' ] , false ) ) . toBe ( false ) ;
560+ } ) ;
561+ } ) ;
562+
563+ describe ( '_createLayerLegendList 面 + 轮廓色' , ( ) => {
564+ it ( '轮廓色为单值专题图时,图例同时包含面单项与轮廓色分组' , ( ) => {
565+ const layer = { id : 'beijing' , title : 'beijing' , type : 'fill' } ;
566+ const styleSetting = {
567+ type : 'fill' ,
568+ color : { type : 'simple' , value : '#826DBA' } ,
569+ opacity : { type : 'simple' , value : 0.9 } ,
570+ outline : { type : 'simple' , value : true } ,
571+ outlineWidth : { type : 'simple' , value : 0.5 } ,
572+ outlineColor : {
573+ type : 'unique' ,
574+ field : [ 'smpid' ] ,
575+ defaultValue : '#ffffff' ,
576+ values : [
577+ { value : '#d53e4f' , key : 1 } ,
578+ { value : '#3288bd' , key : 18 }
579+ ]
580+ } ,
581+ styleRenderMode : 'mapboxgl'
582+ } ;
583+
584+ const result = instance . _createLayerLegendList ( layer , styleSetting ) ;
585+
586+ // 第一项为面:带上填充底色与轮廓
587+ expect ( result . length ) . toBe ( 2 ) ;
588+ expect ( result [ 0 ] . styleField ) . toBeUndefined ( ) ;
589+ expect ( result [ 0 ] . styleGroup . length ) . toBe ( 1 ) ;
590+ expect ( result [ 0 ] . styleGroup [ 0 ] . style . backgroundColor ) . toBe ( '#826DBA' ) ;
591+ expect ( result [ 0 ] . styleGroup [ 0 ] . style . outlineStyle ) . toBe ( 'solid' ) ;
592+ expect ( result [ 0 ] . styleGroup [ 0 ] . style . shape ) . toBe ( 'RECTANGLE' ) ;
593+
594+ // 第二项为轮廓色专题图分组,且每个分组样式保留面的填充底色
595+ expect ( result [ 1 ] . styleField ) . toBe ( 'outlineColor' ) ;
596+ expect ( result [ 1 ] . styleGroup . length ) . toBeGreaterThan ( 1 ) ;
597+ expect ( result [ 1 ] . styleGroup [ 0 ] . style . outlineColor ) . toBe ( '#d53e4f' ) ;
598+ expect ( result [ 1 ] . styleGroup [ 0 ] . style . backgroundColor ) . toBe ( '#826DBA' ) ;
599+ } ) ;
600+ } ) ;
601+
527602 describe ( '_getLegendStyleType' , ( ) => {
528603 it ( 'should return CUSTOM when currentType is custom' , ( ) => {
529604 const result = instance . _getLegendStyleType ( {
0 commit comments