import { Injectable } from '@angular/core' ; import { Subject } from 'rxjs' ; import { AddDataUrlType } from './types/url.type' ; import { HsDialogContainerService } from '../../layout/dialogs/dialog-container.service' ; import { HsGetCapabilitiesErrorComponent } from './../common/capabilities-error-dialog/capabilities-error-dialog.component' ; import { HsLanguageService } from '../../language/language.service' ; import { HsLayoutService } from '../../layout/layout.service' ; import { HsLogService } from '../../../common/log/log.service' ; @ Injectable ( { providedIn : 'root' , } ) export class HsAddDataUrlService { addDataCapsParsingError : Subject < { e : any ; context : any ; } > = new Subject ( ) ; hasAnyChecked : boolean ; typeSelected : AddDataUrlType ; connectFromParams = true ; constructor ( public hsLog , public hsLanguageService , public hsDialogContainerService , public hsLayoutService ) { this . addDataCapsParsingError . subscribe ( ( e ) => { this . hsLog . warn ( e ) ; let error = e . toString ( ) ; if ( error . includes ( 'property' ) ) { error = this . hsLanguageService . getTranslationIgnoreNonExisting ( 'ADDLAYERS' , 'serviceTypeNotMatching' ) ; } this . hsDialogContainerService . create ( HsGetCapabilitiesErrorComponent , error ) ; } ) ; } param services param layerToSelect param selector selectLayerByName ( layerToSelect , services , selector ) { if ( ! layerToSelect ) { return ; } let selectedLayer ; if ( Array . isArray ( services ) ) { for ( const serviceLayer of services ) { selectedLayer = this . selectSubLayerByName ( layerToSelect , serviceLayer , selector ) ; } } else { selectedLayer = this . selectSubLayerByName ( layerToSelect , services , selector ) ; } return selectedLayer ; } /**
     * Helper function for selectLayerByName()
     */ private selectSubLayerByName ( layerToSelect , serviceLayer , selector ) { let selectedLayer ; if ( serviceLayer . Layer && serviceLayer . Name != layerToSelect ) { selectedLayer = this . selectLayerByName ( layerToSelect , serviceLayer . Layer , selector ) ; } else { selectedLayer = this . setLayerCheckedTrue ( layerToSelect , serviceLayer , selector ) ; } return selectedLayer ; } /**
     * Helper function for selectLayerByName()
     * Does the actual selection (checked = true)
     */ private setLayerCheckedTrue ( layerToSelect , serviceLayer , selector ) { if ( serviceLayer [ selector ] == layerToSelect ) { serviceLayer . checked = true ; this . scrollToLayer ( serviceLayer [ selector ] ) ; } return serviceLayer ; } scrollToLayer ( name ) { setTimeout ( ( ) => { const id = `#hs-add-layer-${ name }` ; const el = this . hsLayoutService . contentWrapper . querySelector ( id ) ; if ( el ) { el . scrollIntoView ( ) ; } } , 1000 ) ; } searchForChecked ( services ) { this . hasAnyChecked = services . some ( ( service ) => service . checked ) ; } }