@@ -384,6 +384,30 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
384384 }
385385 }
386386 }
387+ _getFilterByCatalog ( catalog , res = { } ) {
388+ const { catalogType, children } = catalog ;
389+ if ( catalogType === 'group' && children ) {
390+ children . forEach ( child => {
391+ this . _getFiltersByCatalog ( child , res ) ;
392+ } )
393+ }
394+ if ( catalogType === 'layer' ) {
395+ const { filter, layersContent = [ ] } = catalog ;
396+ if ( filter ) {
397+ layersContent . forEach ( layerId => {
398+ res [ layerId ] = filter ;
399+ } )
400+ }
401+ }
402+ }
403+ _getFiltersByCatalog ( _mapResourceInfo = this . _mapResourceInfo ) {
404+ const { catalogs = [ ] } = _mapResourceInfo ;
405+ const res = [ ] ;
406+ catalogs . forEach ( ( item ) => {
407+ this . _getFilterByCatalog ( item , res ) ;
408+ } )
409+ return res ;
410+ }
387411 _getPopupInfos ( _mapResourceInfo = this . _mapResourceInfo ) {
388412 const { catalogs = [ ] } = _mapResourceInfo ;
389413 const res = [ ] ;
@@ -419,6 +443,8 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
419443 description : relatedInfo . description
420444 } ;
421445 this . _mapResourceInfo = JSON . parse ( relatedInfo . projectInfo ) ;
446+ const catalogFilters = this . _getFiltersByCatalog ( ) ;
447+ this . _changeMapInfoFilter ( catalogFilters ) ;
422448 this . _createMapRelatedInfo ( ) ;
423449 this . _addLayersToMap ( ) ;
424450 } )
@@ -427,6 +453,79 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
427453 console . error ( error ) ;
428454 } ) ;
429455 }
456+ /**
457+ * @private
458+ * @function WebMapV3.prototype._changeMapInfoFilter
459+ * @description 更新地图图层的过滤器, 将filter的内容 ['==', 'Ctype', '']转换为['==', ['get', 'Ctype'], 'label']
460+ */
461+ _changeMapInfoFilter ( catalogFilters = { } ) {
462+ const { layers = [ ] } = this . _mapInfo ;
463+ layers . forEach ( layer => {
464+ if ( layer . filter && catalogFilters [ layer . id ] ) {
465+ const catalogFilter = catalogFilters [ layer . id ] ;
466+ const matchKeys = this . _collectMatchKeys ( catalogFilter ) ;
467+ const filter = this . _transformFilterByMatchKeys ( layer . filter , matchKeys ) ;
468+ layer . filter = filter ;
469+ }
470+ } )
471+ this . _mapInfo = {
472+ ...this . _mapInfo ,
473+ layers
474+ }
475+ }
476+
477+ _collectMatchKeys ( filter ) {
478+ const keys = [ ] ;
479+ const excludeKeys = [ '$type' , '$id' , '$layer' ] ;
480+ if ( ! Array . isArray ( filter ) ) { return keys ; }
481+ const traverse = ( arr ) => {
482+ for ( const item of arr ) {
483+ if ( ! Array . isArray ( item ) ) { continue ; }
484+ if ( item . length >= 3 && this . _isComparisonOperator ( item [ 0 ] ) ) {
485+ const prop = this . _getPropertyKey ( item [ 1 ] ) ;
486+ if ( prop && ! excludeKeys . includes ( prop ) ) {
487+ keys . push ( prop ) ;
488+ continue ;
489+ }
490+ if ( typeof item [ 1 ] === 'string' && ! excludeKeys . includes ( item [ 1 ] ) ) {
491+ keys . push ( item [ 1 ] ) ;
492+ }
493+ } else {
494+ traverse ( item ) ;
495+ }
496+ }
497+ } ;
498+ traverse ( filter ) ;
499+ return [ ...new Set ( keys ) ] ;
500+ }
501+
502+ _getPropertyKey ( item ) {
503+ if ( Array . isArray ( item ) && item . length === 2 && item [ 0 ] === 'get' && typeof item [ 1 ] === 'string' ) {
504+ return item [ 1 ] ;
505+ }
506+ return null ;
507+ }
508+
509+ _transformFilterByMatchKeys ( filter , matchKeys ) {
510+ if ( ! Array . isArray ( filter ) ) {
511+ return filter ;
512+ }
513+ if ( filter . length >= 3 && typeof filter [ 1 ] === 'string' && this . _isComparisonOperator ( filter [ 0 ] ) ) {
514+ if ( matchKeys . includes ( filter [ 1 ] ) ) {
515+ return [ filter [ 0 ] , [ 'get' , filter [ 1 ] ] , ...filter . slice ( 2 ) ] ;
516+ }
517+ return filter ;
518+ }
519+ if ( filter . length >= 2 && typeof filter [ 1 ] !== 'string' && this . _isComparisonOperator ( filter [ 0 ] ) ) {
520+ const operands = filter . slice ( 1 ) . map ( item => this . _transformFilterByMatchKeys ( item , matchKeys ) ) ;
521+ return [ filter [ 0 ] , ...operands ] ;
522+ }
523+ return filter . map ( item => this . _transformFilterByMatchKeys ( item , matchKeys ) ) ;
524+ }
525+
526+ _isComparisonOperator ( op ) {
527+ return [ '==' , '!=' , '>' , '<' , '>=' , '<=' , 'in' , '!in' , 'all' , 'any' , 'none' ] . includes ( op ) ;
528+ }
430529
431530 /**
432531 * @private
0 commit comments