@@ -117,6 +117,23 @@ const SymbolType = {
117
117
polygon : 'polygon'
118
118
} ;
119
119
120
+ const MAP_LAYER_TYPE_2_SYMBOL_TYPE = {
121
+ circle : 'point' ,
122
+ line : 'line' ,
123
+ symbol : 'point' ,
124
+ fill : 'polygon' ,
125
+ 'fill-extrusion' : 'polygon' ,
126
+ heatmap : 'point' ,
127
+ // background: 'background',//无此符号类型
128
+ // L7
129
+ radar : 'point' ,
130
+ 'point-extrusion' : 'point' ,
131
+ 'heatmap-extrusion' : 'point' ,
132
+ 'line-extrusion' : 'line' ,
133
+ 'line-curve' : 'line' ,
134
+ 'line-curve-extrusion' : 'line'
135
+ } ;
136
+
120
137
const LEGEND_LINE_WIDTH = 100 ;
121
138
const LINE_WIDTH_KEY = 'line-width' ;
122
139
@@ -362,6 +379,7 @@ export class WebMap extends mapboxgl.Evented {
362
379
this . _sendMapToUser ( ) ;
363
380
} catch ( error ) {
364
381
this . fire ( 'getlayersfailed' , { error, map : this . map } ) ;
382
+ console . error ( error ) ;
365
383
}
366
384
}
367
385
@@ -936,6 +954,70 @@ export class WebMap extends mapboxgl.Evented {
936
954
}
937
955
}
938
956
957
+ /**
958
+ * 1) 无数据驱动时;
959
+ * 2) 只有一个颜色数据驱动,且性线数据驱动时
960
+ * 以上两种情况图例中需要单独的显示符号项
961
+ * @returns
962
+ */
963
+ _isShowLegendSingleItem ( dataKeys , isLinearColor ) {
964
+ return dataKeys . length === 0 || ( dataKeys . length === 1 && dataKeys [ 0 ] === 'color' && isLinearColor ) ;
965
+ }
966
+
967
+ _isWebsymbolById ( id ) {
968
+ const a = [ 'line-' , 'polygon-' , 'point-' ] ;
969
+ return a . some ( ( el ) => id ?. startsWith ( el ) ) ;
970
+ }
971
+
972
+ /**
973
+ * 获取icon-image 的sdf状态
974
+ * 目前webSymbol为false, 基本符号为true, 雪碧图从json中获取sdf的状态
975
+ * @param id
976
+ * @param spriteJson
977
+ * @returns
978
+ */
979
+ _getSymbolSDFStatus ( id , spriteJson ) {
980
+ if ( this . _isWebsymbolById ( id ) ) {
981
+ return false ;
982
+ }
983
+ if ( this . _getIconById ( id ) ) {
984
+ return true ;
985
+ }
986
+ return spriteJson ?. [ id ] ?. sdf || false ;
987
+ }
988
+
989
+ _isAllPicturePoint ( symbolsContent , spriteJson ) {
990
+ if ( ! symbolsContent ) {
991
+ return false ;
992
+ }
993
+ if ( symbolsContent . type === 'simple' ) {
994
+ return ! this . _getSymbolSDFStatus ( symbolsContent ?. value . symbolId , spriteJson ) ;
995
+ } else {
996
+ return [ ...symbolsContent ?. values , { value : symbolsContent ?. defaultValue } ]
997
+ . filter ( ( v ) => v . value . symbolId )
998
+ . every ( ( v ) => {
999
+ return ! this . _getSymbolSDFStatus ( v . value . symbolId , spriteJson ) ;
1000
+ } ) ;
1001
+ }
1002
+ }
1003
+
1004
+ _isAllPictureSymbolSaved ( symbolType , symbolsContent , spriteJson ) {
1005
+ if ( symbolType === 'point' ) {
1006
+ return this . _isAllPicturePoint ( symbolsContent , spriteJson ) ;
1007
+ }
1008
+ if ( ! symbolsContent || ! symbolsContent . value ) {
1009
+ return false ;
1010
+ }
1011
+ const currentType = symbolsContent . type ;
1012
+ if ( currentType === 'simple' ) {
1013
+ return ! ! this . _getImageIdFromValue ( symbolsContent ?. value ?. style , SymbolType [ symbolType ] ) . length ;
1014
+ }
1015
+ const styles = ( symbolsContent . values ) . map ( ( v ) => v . value ) . concat ( symbolsContent . defaultValue ) ;
1016
+ return styles . every ( ( v ) => {
1017
+ return ! ! this . _getImageIdFromValue ( v . style , SymbolType [ symbolType ] ) . length ;
1018
+ } ) ;
1019
+ }
1020
+
939
1021
_createLayerLegendList ( layer , styleSetting ) {
940
1022
const layerId = layer . id ;
941
1023
const layerTitle = layer . title ;
@@ -976,25 +1058,20 @@ export class WebMap extends mapboxgl.Evented {
976
1058
this . _transStyleSetting ( renderType , styleSetting ) ;
977
1059
const simpleStyle = this . _getLegendSimpleStyle ( styleSetting , keys ) ;
978
1060
const simpleResData = this . _parseLegendtyle ( { legendRenderType, customValue : simpleStyle } ) ;
979
- const dataKeys = keys . filter ( ( k ) => styleSetting [ k ] && styleSetting [ k ] . type !== 'simple' ) ;
980
- if ( ! dataKeys . length ) {
981
- return [
982
- {
983
- ...commonStyleOptions ,
984
- styleGroup : [
985
- {
986
- fieldValue : layerTitle || layerId ,
987
- style : {
988
- ...simpleResData ,
989
- shape
990
- }
991
- }
992
- ]
993
- }
994
- ] ;
1061
+ let dataKeys = keys . filter ( ( k ) => styleSetting [ k ] && styleSetting [ k ] . type !== 'simple' ) ;
1062
+ // isReplaceLineColor: 3D线,动画线:使用符号替换线颜色,图例中将不再显示线颜色
1063
+ const isReplaceLineColor = styleSetting . textureBlend ?. value === 'replace' ;
1064
+ const hasTexture = ! ! styleSetting . symbolsContent ?. value ?. symbolId ;
1065
+ // isAllPic: 如果符号为图片,图例中将不再显示颜色
1066
+ const symbolTypes = MAP_LAYER_TYPE_2_SYMBOL_TYPE [ layer . type ] ;
1067
+ const isAllPic = this . _isAllPictureSymbolSaved ( symbolTypes , styleSetting . symbolsContent , this . _spriteDatas ) ;
1068
+ if ( ( isReplaceLineColor && hasTexture ) || isAllPic ) {
1069
+ dataKeys = dataKeys . filter ( ( key ) => key !== 'color' )
995
1070
}
1071
+ const isLinearColor = styleSetting . color ?. interpolateInfo ?. type === 'linear' ;
1072
+ const isShowSingleItem = this . _isShowLegendSingleItem ( dataKeys , isLinearColor ) ;
996
1073
const resultList = [ ] ;
997
- if ( ! dataKeys . includes ( 'symbolsContent' ) ) {
1074
+ if ( isShowSingleItem ) {
998
1075
resultList . push ( {
999
1076
...commonStyleOptions ,
1000
1077
styleGroup : [
@@ -1275,6 +1352,24 @@ export class WebMap extends mapboxgl.Evented {
1275
1352
return BaseIcons . find ( ( icon ) => icon . id === id ) ;
1276
1353
}
1277
1354
1355
+ _getImageIdFromValue ( style , type ) {
1356
+ const imageKeys = {
1357
+ symbol : 'icon-image' ,
1358
+ line : 'line-pattern' ,
1359
+ fill : 'fill-pattern' ,
1360
+ 'fill-extrusion' : 'fill-pattern'
1361
+ } ;
1362
+ const styles = Array . isArray ( style ) ? style : [ style ] ;
1363
+ const imageKey = imageKeys [ type ] ;
1364
+ if ( type === 'symbol' ) {
1365
+ const imageIds = styles . map ( ( item ) => item . layout ?. [ imageKey ] ) ;
1366
+ return imageIds . filter ( ( id ) => id ) ;
1367
+ }
1368
+ // 'line' 'fill' 'fill-extrusion'
1369
+ const imageIds = styles . map ( ( item ) => item . paint ?. [ imageKey ] ) ;
1370
+ return imageIds . filter ( ( id ) => id ) ;
1371
+ }
1372
+
1278
1373
_getImageIdByLegendType ( symbol , legendType ) {
1279
1374
const symbolTypes = {
1280
1375
ANIMATELINE : SymbolType . point ,
0 commit comments