import { Injectable } from '@angular/core' ; import { HsAddDataService } from '../add-data.service' ; import { HsAddDataUrlService } from '../url/add-data-url.service' ; import { HsDimensionService } from '../../../common/get-capabilities/dimension.service' ; import { HsEventBusService } from '../../core/event-bus.service' ; import { HsMapService } from '../../map/map.service' ; import { HsToastService } from '../../layout/toast/toast.service' ; @ Injectable ( { providedIn : 'root' } ) export class HsAddDataCommonService { layerToSelect : string ; loadingInfo = false ; showDetails = false ; url : string ; getDimensionValues = this . hsDimensionService . getDimensionValues ; constructor ( public hsMapService , public hsAddDataUrlService , public hsToastService , public hsAddDataService , public hsDimensionService , public hsEventBusService ) { this . hsAddDataService . cancelUrlRequest . subscribe ( ( ) => { this . clearParams ( ) ; } ) ; } clearParams ( ) { this . layerToSelect = '' ; this . loadingInfo = false ; this . showDetails = false ; this . url = '' ; this . hsAddDataUrlService . typeSelected = null ; } setPanelToCatalogue ( ) { this . hsAddDataService . dsSelected = 'catalogue' ; } param url updateUrl ( url ) { this . url = url ; } checkTheSelectedLayer ( services ) { for ( const layer of services ) { const layerName = layer . Name ?. toLowerCase ( ) ?? layer . Title ?. toLowerCase ( ) ; if ( layerName === this . layerToSelect . toLowerCase ( ) ) { layer . checked = true ; } } } displayParsingError ( e ) { if ( e ?. status === 401 ) { this . hsToastService . createToastPopupMessage ( 'ADDLAYERS.capabilitiesParsingProblem' , 'ADDLAYERS.unauthorizedAccess' , { serviceCalledFrom : 'HsAddDataCommonUrlService' } ) ; } else { this . hsAddDataUrlService . addDataCapsParsingError . next ( e ) ; } } throwParsingError ( e ) { this . clearParams ( ) ; this . displayParsingError ( e ) ; } srsChanged ( srs ) { setTimeout ( ( ) => { return ! this . currentProjectionSupported ( [ srs ] ) ; } , 0 ) ; } param srss returns currentProjectionSupported ( srss ) { if ( ! srss || srss . length === 0 ) { return false ; } let found = false ; for ( const val of srss ) { if ( ! val ) { found = false ; } else { if ( this . hsMapService . map . getView ( ) . getProjection ( ) . getCode ( ) . toUpperCase ( ) == val . toUpperCase ( ) ) { found = true ; } } } return found ; } param layerOrLayers param property returns createBasemapName ( layerOrLayers , property ) { let baseName = '' ; if ( Array . isArray ( layerOrLayers ) ) { for ( const layer of layerOrLayers ) { if ( layer . checked ) { baseName = layer [ property ] ; break ; } else { if ( layer . Layer ) { baseName = baseName . concat ( this . createBasemapName ( layer . Layer , property ) ) ; } } } } else { baseName = layerOrLayers [ property ] ; } return baseName ; } param service getSublayerNames ( service ) { if ( service . Layer ) { return service . Layer . map ( ( l ) => { let tmp = [ ] ; if ( l . Name ) { tmp . push ( l . Name ) ; } if ( l . Layer ) { const children = this . getSublayerNames ( l ) ; tmp = tmp . concat ( children ) ; } return tmp . join ( ',' ) ; } ) ; } else { return '' ; } } }