@@ -384,30 +384,6 @@ 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 . _getFilterByCatalog ( 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- }
411387 _getPopupInfos ( _mapResourceInfo = this . _mapResourceInfo ) {
412388 const { catalogs = [ ] } = _mapResourceInfo ;
413389 const res = [ ] ;
@@ -431,8 +407,7 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
431407 } ;
432408 if ( this . _relatedInfo . projectInfo ) {
433409 this . _mapResourceInfo = JSON . parse ( this . _relatedInfo . projectInfo ) ;
434- const catalogFilters = this . _getFiltersByCatalog ( ) ;
435- this . _changeMapInfoFilter ( catalogFilters ) ;
410+ this . _changeMapInfoFilter ( ) ;
436411 }
437412 this . _createMapRelatedInfo ( ) ;
438413 this . _addLayersToMap ( ) ;
@@ -445,8 +420,7 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
445420 description : relatedInfo . description
446421 } ;
447422 this . _mapResourceInfo = JSON . parse ( relatedInfo . projectInfo ) ;
448- const catalogFilters = this . _getFiltersByCatalog ( ) ;
449- this . _changeMapInfoFilter ( catalogFilters ) ;
423+ this . _changeMapInfoFilter ( ) ;
450424 this . _createMapRelatedInfo ( ) ;
451425 this . _addLayersToMap ( ) ;
452426 } )
@@ -460,73 +434,19 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
460434 * @function WebMapV3.prototype._changeMapInfoFilter
461435 * @description 更新地图图层的过滤器, 将filter的内容 ['==', 'Ctype', '']转换为['==', ['get', 'Ctype'], 'label']
462436 */
463- _changeMapInfoFilter ( catalogFilters = { } ) {
464- const { layers = [ ] } = this . _mapInfo ;
465- layers . forEach ( layer => {
466- if ( layer . filter && catalogFilters [ layer . id ] ) {
467- const catalogFilter = catalogFilters [ layer . id ] ;
468- const matchKeys = this . _collectMatchKeys ( catalogFilter ) ;
469- const filter = this . _transformFilterByMatchKeys ( layer . filter , matchKeys ) ;
470- layer . filter = filter ;
437+ _changeMapInfoFilter ( ) {
438+ if ( mapRepo && mapRepo . convertFilter ) {
439+ const { layers = [ ] } = this . _mapInfo ;
440+ layers . forEach ( ( layer ) => {
441+ if ( layer . filter ) {
442+ layer . filter = mapRepo . convertFilter ( layer . filter ) ;
471443 }
472- } )
473- this . _mapInfo = {
444+ } ) ;
445+ this . _mapInfo = {
474446 ...this . _mapInfo ,
475447 layers
476- }
477- }
478-
479- _collectMatchKeys ( filter ) {
480- const keys = [ ] ;
481- const excludeKeys = [ '$type' , '$id' , '$layer' ] ;
482- if ( ! Array . isArray ( filter ) ) { return keys ; }
483- const traverse = ( arr ) => {
484- for ( const item of arr ) {
485- if ( ! Array . isArray ( item ) ) { continue ; }
486- if ( item . length >= 3 && this . _isComparisonOperator ( item [ 0 ] ) ) {
487- const prop = this . _getPropertyKey ( item [ 1 ] ) ;
488- if ( prop && ! excludeKeys . includes ( prop ) ) {
489- keys . push ( prop ) ;
490- continue ;
491- }
492- if ( typeof item [ 1 ] === 'string' && ! excludeKeys . includes ( item [ 1 ] ) ) {
493- keys . push ( item [ 1 ] ) ;
494- }
495- } else {
496- traverse ( item ) ;
497- }
498- }
499- } ;
500- traverse ( filter ) ;
501- return [ ...new Set ( keys ) ] ;
502- }
503-
504- _getPropertyKey ( item ) {
505- if ( Array . isArray ( item ) && item . length === 2 && item [ 0 ] === 'get' && typeof item [ 1 ] === 'string' ) {
506- return item [ 1 ] ;
507- }
508- return null ;
509- }
510-
511- _transformFilterByMatchKeys ( filter , matchKeys ) {
512- if ( ! Array . isArray ( filter ) ) {
513- return filter ;
514- }
515- if ( filter . length >= 3 && typeof filter [ 1 ] === 'string' && this . _isComparisonOperator ( filter [ 0 ] ) ) {
516- if ( matchKeys . includes ( filter [ 1 ] ) ) {
517- return [ filter [ 0 ] , [ 'get' , filter [ 1 ] ] , ...filter . slice ( 2 ) ] ;
518- }
519- return filter ;
520- }
521- if ( filter . length >= 2 && typeof filter [ 1 ] !== 'string' && this . _isComparisonOperator ( filter [ 0 ] ) ) {
522- const operands = filter . slice ( 1 ) . map ( item => this . _transformFilterByMatchKeys ( item , matchKeys ) ) ;
523- return [ filter [ 0 ] , ...operands ] ;
448+ } ;
524449 }
525- return filter . map ( item => this . _transformFilterByMatchKeys ( item , matchKeys ) ) ;
526- }
527-
528- _isComparisonOperator ( op ) {
529- return [ '==' , '!=' , '>' , '<' , '>=' , '<=' , 'in' , '!in' , 'all' , 'any' , 'none' ] . includes ( op ) ;
530450 }
531451
532452 /**
0 commit comments