@@ -5,7 +5,7 @@ import { Util } from "@supermap/iclient-common/commontypes/Util";
55import CompositeSymbolRender from "./CompositeSymbolRender" ;
66import SingleSymbolRender from "./SingleSymbolRender" ;
77import SymbolManager from "./SymbolManager" ;
8- import { getImageKey , isMapboxExpression , isMultiSymbol , validateSymbol } from "./SymbolUtil" ;
8+ import { getImageKey , isMapboxExpression , isMultiSymbol , isPaintKey , validateSymbol } from "./SymbolUtil" ;
99
1010/**
1111 * 符号图层管理器
@@ -385,7 +385,7 @@ class SymbolHandler {
385385 */
386386 getFilter ( layerId ) {
387387 const realLayerId = this . getFirstLayerId ( layerId ) ;
388- if ( this . map . style . getLayer ( realLayerId ) ) {
388+ if ( this . map . style . getLayer ( realLayerId ) ) {
389389 return this . map . style . getFilter ( realLayerId ) ;
390390 }
391391 }
@@ -458,6 +458,110 @@ class SymbolHandler {
458458 const realLayerId = this . getFirstLayerId ( layerId ) ;
459459 return this . map . style . getLayoutProperty ( realLayerId , name ) ;
460460 }
461+
462+ /**
463+ * 遍历this._layerSymbols, 更新使用到symbolId的图层
464+ * @param {string } symbolId
465+ */
466+ updateLayerSymbol ( symbolId ) {
467+ Object . keys ( this . _layerSymbols ) . forEach ( layerId => {
468+ const symbol = this . _layerSymbols [ layerId ] ;
469+ if ( symbol . includes ( symbolId ) ) {
470+ this . setSymbol ( layerId , symbol ) ;
471+ }
472+ } )
473+ }
474+
475+ /**
476+ * 更新符号
477+ * @param {string } symbolId
478+ * @param {object | array } symbol
479+ */
480+ updateSymbol ( symbolId , symbol ) {
481+ // symbol不存在
482+ if ( ! this . symbolManager . getSymbol ( symbolId ) ) {
483+ return this . map . fire ( 'error' , {
484+ error : new Error ( `Symbol "${ symbolId } " could not be loaded. Please make sure you have added the symbol with map.addSymbol().` )
485+ } ) ;
486+ }
487+ if ( validateSymbol ( symbol ) ) {
488+ // 更新symbol
489+ this . symbolManager . addSymbol ( symbolId , symbol ) ;
490+ this . updateLayerSymbol ( symbolId ) ;
491+ } else {
492+ return this . map . fire ( 'error' , {
493+ error : new Error ( 'Symbol is not supported expressions.' )
494+ } ) ;
495+ }
496+ }
497+
498+ /**
499+ * 设置symbol属性值
500+ * @param {string } symbolId
501+ * @param {number } symbolIndex
502+ * @param {string } name
503+ * @param {any } value
504+ */
505+ setSymbolProperty ( symbolId , symbolIndex , name , value ) {
506+ const symbol = this . symbolManager . getSymbol ( symbolId ) ;
507+ // symbol不存在
508+ if ( ! symbol ) {
509+ return this . map . fire ( 'error' , {
510+ error : new Error ( `Symbol "${ symbolId } " could not be loaded. Please make sure you have added the symbol with map.addSymbol().` )
511+ } ) ;
512+ }
513+ // value不支持表达式
514+ if ( isMapboxExpression ( value ) ) {
515+ return this . map . fire ( 'error' , {
516+ error : new Error ( 'Symbol value is not supported expressions.' )
517+ } ) ;
518+ }
519+ const paintOrLayout = isPaintKey ( name ) ? 'paint' : 'layout' ;
520+ if ( symbol . length > 0 ) {
521+ const symbolChild = symbol [ symbolIndex ] ;
522+ if ( ! symbolChild ) {
523+ return this . map . fire ( 'error' , {
524+ error : new Error ( `symbol[${ symbolIndex } ] does not exist.` )
525+ } ) ;
526+ }
527+ if ( ! symbolChild [ paintOrLayout ] ) {
528+ symbolChild [ paintOrLayout ] = { } ;
529+ }
530+ Object . assign ( symbolChild [ paintOrLayout ] , { [ name ] : value } ) ;
531+ } else {
532+ if ( ! symbol [ paintOrLayout ] ) {
533+ symbol [ paintOrLayout ] = { } ;
534+ }
535+ Object . assign ( symbol [ paintOrLayout ] , { [ name ] : value } ) ;
536+ }
537+ // 更新symbol
538+ this . symbolManager . addSymbol ( symbolId , symbol ) ;
539+ this . updateLayerSymbol ( symbolId ) ;
540+ }
541+
542+ /**
543+ * 获取symbol的属性值
544+ * @param {string } symbolId
545+ * @param {number } symbolIndex
546+ * @param {string } name
547+ * @returns {any }
548+ */
549+ getSymbolProperty ( symbolId , symbolIndex , name ) {
550+ const symbol = this . symbolManager . getSymbol ( symbolId ) ;
551+ // symbol不存在
552+ if ( ! symbol ) {
553+ this . map . fire ( 'error' , {
554+ error : new Error ( `Symbol "${ symbolId } " could not be loaded. Please make sure you have added the symbol with map.addSymbol().` )
555+ } ) ;
556+ return ;
557+ }
558+ const paintOrLayout = isPaintKey ( name ) ? 'paint' : 'layout' ;
559+ if ( symbol . length > 0 ) {
560+ return symbol [ symbolIndex ] && symbol [ symbolIndex ] [ paintOrLayout ] && symbol [ symbolIndex ] [ paintOrLayout ] [ name ] ;
561+ } else {
562+ return symbol [ paintOrLayout ] && symbol [ paintOrLayout ] [ name ] ;
563+ }
564+ }
461565}
462566
463567export default SymbolHandler ;
0 commit comments