@@ -1669,6 +1669,75 @@ describe('WebMapV3 - _createLegendInfo', () => {
16691669 expect ( instance . _legendList [ 0 ] . themeField ) . toBe ( 'CLUSTER_COUNT' ) ;
16701670 } ) ;
16711671
1672+ [ 'line' , 'fill' ] . forEach ( ( layerType ) => {
1673+ [ 'unique' , 'range' , 'simple' , 'empty' , 'custom' ] . forEach ( ( symbolMode ) => {
1674+ it ( `should preserve ${ layerType } legends with ${ symbolMode } label symbols` , ( ) => {
1675+ const { instance } = createTestContext ( ) ;
1676+ const symbol = { symbolId : 'shape1' , style : { layout : { 'icon-image' : 'shape1' } } } ;
1677+ const symbolsContent = symbolMode === 'unique' || symbolMode === 'range' ? {
1678+ type : symbolMode ,
1679+ field : [ 'smpid' ] ,
1680+ defaultValue : symbol ,
1681+ values : symbolMode === 'unique'
1682+ ? [ { key : 1 , value : symbol } , { key : 10 , value : symbol } ]
1683+ : [ { start : 0 , end : 10 , value : symbol } , { start : 10 , end : 20 , value : symbol } ] ,
1684+ interpolateInfo : { type : 'custom' }
1685+ } : symbolMode === 'custom'
1686+ ? { type : 'custom' , value : [ 'get' , 'symbol' ] }
1687+ : { type : 'simple' , value : symbolMode === 'empty' ? { symbolId : '' } : symbol } ;
1688+ const renderer = [ {
1689+ color : { type : 'simple' , value : '#4CC8A3' } ,
1690+ opacity : { type : 'simple' , value : 0 } ,
1691+ width : { type : 'simple' , value : 2 }
1692+ } ] ;
1693+ const label = {
1694+ symbolsContent,
1695+ textField : { type : 'simple' , value : '标准名称' } ,
1696+ textColor : { type : 'simple' , value : '#FFFFFF' } ,
1697+ textSize : { type : 'simple' , value : 16 } ,
1698+ color : { type : 'simple' , value : '#EE4D5A' } ,
1699+ size : { type : 'simple' , value : 8 } ,
1700+ opacity : { type : 'simple' , value : 0.9 }
1701+ } ;
1702+ instance . _legendList = [ ] ;
1703+ instance . _mapInfo = {
1704+ layers : [ { id : 'l1' , type : layerType , source : 's1' } ] ,
1705+ sources : { s1 : { } }
1706+ } ;
1707+ instance . _mapResourceInfo = { catalogs : [ legendCatalog ( renderer , { visualization : { renderer, label } } ) ] } ;
1708+ instance . _spriteDatas = { shape1 : { x : 0 , y : 0 , width : 20 , height : 20 , sdf : false } } ;
1709+ instance . _sprite = 'http://localhost/sprite' ;
1710+
1711+ instance . _createLegendInfo ( ) ;
1712+
1713+ const legends = instance . _legendList ;
1714+ expect ( legends [ 0 ] . styleGroup [ 0 ] . style . shape ) . toBe ( layerType === 'line' ? 'LINE' : 'RECTANGLE' ) ;
1715+ expect ( legends . some ( ( item ) => item . styleGroup . some ( ( entry ) => entry . style . shape === 'TEXT' ) ) ) . toBe ( true ) ;
1716+ if ( symbolMode === 'unique' || symbolMode === 'range' ) {
1717+ const symbolLegend = legends . find ( ( item ) => item . styleField === 'symbolsContent' ) ;
1718+ expect ( symbolLegend . themeField ) . toBe ( 'smpid' ) ;
1719+ expect ( symbolLegend . styleGroup . length ) . toBe ( 3 ) ;
1720+ expect ( symbolLegend . styleGroup . every ( ( entry ) => entry . style . shape === 'POINT' ) ) . toBe ( true ) ;
1721+ if ( symbolMode === 'unique' ) {
1722+ expect ( symbolLegend . styleGroup . map ( ( entry ) => entry . fieldValue ) ) . toEqual ( [ 1 , 10 , null ] ) ;
1723+ } else {
1724+ expect ( symbolLegend . styleGroup . map ( ( entry ) => [ entry . start , entry . end ] ) ) . toEqual ( [ [ 0 , 10 ] , [ 10 , 20 ] , [ null , null ] ] ) ;
1725+ }
1726+ } else if ( symbolMode === 'simple' ) {
1727+ expect ( legends . some ( ( item ) => item . styleGroup . some ( ( entry ) => entry . style . shape === 'POINT' ) ) ) . toBe ( true ) ;
1728+ } else {
1729+ expect ( legends . some ( ( item ) => item . styleGroup . some ( ( entry ) => entry . style . shape === 'POINT' ) ) ) . toBe ( false ) ;
1730+ expect ( legends . some ( ( item ) => item . styleField === 'symbolsContent' ) ) . toBe ( false ) ;
1731+ }
1732+ // Rebuilding legends must not append label settings to the saved renderer.
1733+ expect ( renderer . length ) . toBe ( 1 ) ;
1734+ instance . _legendList = [ ] ;
1735+ instance . _createLegendInfo ( ) ;
1736+ expect ( instance . _legendList ) . toEqual ( legends ) ;
1737+ } ) ;
1738+ } ) ;
1739+ } ) ;
1740+
16721741 it ( 'should append text style for point renderer with text field' , ( ) => {
16731742 const { instance } = createTestContext ( ) ;
16741743 instance . _legendList = [ ] ;
@@ -2132,6 +2201,30 @@ describe('WebMapV3 - setting style helpers', () => {
21322201 } ) ;
21332202} ) ;
21342203
2204+ describe ( 'WebMapV3 - _transformLineStyle' , ( ) => {
2205+ it ( '应保留图层自身的 0 不透明度,不回退成符号的不透明度' , ( ) => {
2206+ const { instance } = createTestContext ( ) ;
2207+ const result = instance . _transformLineStyle ( {
2208+ oldWidth : 2 ,
2209+ symbol : { paint : { 'line-width' : 2 , 'line-color' : '#FF0000' , 'line-opacity' : 0.8 } } ,
2210+ defaultStyle : { height : 8 , opacity : 1 , backgroundColor : '#FFFFFF' } ,
2211+ customValue : { opacity : 0 }
2212+ } ) ;
2213+ expect ( result . opacity ) . toBe ( 0 ) ;
2214+ } ) ;
2215+
2216+ it ( '图层未设置不透明度时回退到符号自身的 line-opacity' , ( ) => {
2217+ const { instance } = createTestContext ( ) ;
2218+ const result = instance . _transformLineStyle ( {
2219+ oldWidth : 2 ,
2220+ symbol : { paint : { 'line-width' : 2 , 'line-color' : '#FF0000' , 'line-opacity' : 0.8 } } ,
2221+ defaultStyle : { height : 8 , opacity : 1 , backgroundColor : '#FFFFFF' } ,
2222+ customValue : { }
2223+ } ) ;
2224+ expect ( result . opacity ) . toBe ( 0.8 ) ;
2225+ } ) ;
2226+ } ) ;
2227+
21352228describe ( 'WebMapV3 - _parseLegendtyle types' , ( ) => {
21362229 it ( 'TEXT should return text icon and css style' , ( ) => {
21372230 const { instance } = createTestContext ( ) ;
0 commit comments