import { Component , Input , OnDestroy , OnInit } from '@angular/core' ; import { Subscription } from 'rxjs' ; import { getDimension , getExclusive , getHsLaymanSynchronizing , getPath , } from '../../../common/layer-extensions' ; import { HsConfig } from '../../../config.service' ; import { HsDimensionTimeService } from '../../../common/get-capabilities/dimension-time.service' ; import { HsEventBusService } from '../../core/event-bus.service' ; import { HsLayerDescriptor } from '../layer-descriptor.interface' ; import { HsLayerEditorSublayerService } from '../editor/layer-editor.sub-layer.service' ; import { HsLayerManagerService } from '../layermanager.service' ; import { HsLayerUtilsService } from '../../utils/layer-utils.service' ; import { HsLayoutService } from '../../layout/layout.service' ; import { HsMapService } from '../../map/map.service' ; import { HsUtilsService } from '../../utils/utils.service' ; @ Component ( { selector : 'hs-layermanager-layer-list' , templateUrl : './layerlist.html' , } ) export class HsLayerListComponent implements OnInit , OnDestroy { @ Input ( ) folder : any ; public layer_titles : Array < string > = [ ] ; /**
     * List of layers which belong to folder hierarchy level of directive instance
     */ filtered_layers : Array < HsLayerDescriptor > = [ ] ; getHsLaymanSynchronizing = getHsLaymanSynchronizing ; getExclusive = getExclusive ; layerManagerUpdatesSubscription : Subscription ; constructor ( public HsConfig , public HsLayerManagerService , public hsDimensionTimeService , public HsMapService , public HsUtilsService , public HsLayerEditorSublayerService , public HsLayoutService , public HsEventBusService , public HsLayerUtilsService ) { this . layerManagerUpdatesSubscription = this . HsEventBusService . layerManagerUpdates . subscribe ( ( ) => { this . HsLayerManagerService . updateLayerListPositions ( ) ; this . updateLayers ( ) ; } ) ; } ngOnDestroy ( ) { this . layerManagerUpdatesSubscription . unsubscribe ( ) ; } param layer layerLoaded ( layer ) { return this . HsLayerUtilsService . layerLoaded ( layer ) ; } changeSublayerVisibilityState ( layer , state ) { if ( layer . checkedSubLayers ) { Object . keys ( layer . checkedSubLayers ) . forEach ( ( key ) => { layer . checkedSubLayers [ key ] = state ; } ) ; } if ( layer . withChildren ) { Object . keys ( layer . withChildren ) . forEach ( ( key ) => { layer . withChildren [ key ] = state ; } ) ; } } param layer returns layerValid ( layer ) { return this . HsLayerUtilsService . layerInvalid ( layer ) ; } param layer toggleSublayersVisibility ( layer ) { if ( ! layer . visible ) { if ( this . HsLayerManagerService . currentLayer === layer ) { if ( this . HsLayerEditorSublayerService . hasSubLayers ( ) ) { this . changeSublayerVisibilityState ( layer , this . HsLayerManagerService . currentLayer . visible ) ; } } else { this . changeSublayerVisibilityState ( layer , layer . visible ) ; } } else { if ( layer . checkedSubLayers ) { Object . keys ( layer . checkedSubLayers ) . forEach ( ( key ) => { layer . checkedSubLayers [ key ] = layer . checkedSubLayersTmp [ key ] ; } ) ; } if ( layer . withChildren ) { Object . keys ( layer . withChildren ) . forEach ( ( key ) => { layer . withChildren [ key ] = layer . withChildrenTmp [ key ] ; } ) ; } } } ngOnInit ( ) { this . filtered_layers = this . filterLayers ( ) ; } layerFilter = ( item ) : boolean => { const r = new RegExp ( this . HsLayerManagerService . data . filter , 'i' ) ; return r . test ( item . title ) ; } ; private returns { Array < HsLayerDescriptor > } private filterLayers ( ) { const tmp = [ ] ; for ( const layer of this . HsLayerManagerService . data . layers ) { if ( getPath ( layer . layer ) == this . folder . hsl_path || ( ( getPath ( layer . layer ) == undefined || getPath ( layer . layer ) == '' ) && this . folder . hsl_path == '' ) ) { tmp . push ( layer ) ; } } return tmp ; } /**
     * Generate list of layer titles out of  hs . layermanager . layerlistDirective . Complex layer objects can't be used because DragDropList functionality can handle only simple structures.
     *  public generateLayerTitlesArray ( ) { this . layer_titles = [ ] ; for ( let i = 0 ; i < this . filtered_layers . length ; i ++ ) { this . layer_titles . push ( this . filtered_layers [ i ] . title ) ; } } param layer_container isLayerQueryable ( layer_container ) { return this . HsLayerUtilsService . isLayerQueryable ( layer_container . layer ) ; } showLayerWmsT ( layer ) { return ( this . hsDimensionTimeService . layerIsWmsT ( layer ) && ! getDimension ( layer . layer , 'time' ) ?. onlyInEditor ) ; } private private updateLayers ( ) { this . filtered_layers = this . filterLayers ( ) ; this . generateLayerTitlesArray ( ) ; } }