import { HttpClient } from '@angular/common/http' ; import { Injectable } from '@angular/core' ; import { takeUntil } from 'rxjs/operators' ; import { CapabilitiesResponseWrapper } from './capabilities-response-wrapper' ; import { HsAddDataService } from '../../components/add-data/add-data.service' ; import { HsCapabilityCacheService } from './capability-cache.service' ; import { HsEventBusService } from '../../components/core/event-bus.service' ; import { HsMapService } from '../../components/map/map.service' ; import { HsUtilsService } from '../../components/utils/utils.service' ; import { IGetCapabilities } from './get-capabilities.interface' ; @ Injectable ( { providedIn : 'root' } ) export class HsWfsGetCapabilitiesService implements IGetCapabilities { service_url : any ; constructor ( private httpClient , public hsEventBusService , public hsMapService , public hsUtilsService , public hsAddDataService , public hsCapabilityCacheService ) { } param str returns getPathFromUrl ( str ) { if ( str . indexOf ( '?' ) > - 1 ) { return str . substring ( 0 , str . indexOf ( '?' ) ) ; } else { return str ; } } param obj returns params2String ( obj ) { return obj ? Object . keys ( obj ) . map ( ( key ) => { const val = obj [ key ] ; if ( Array . isArray ( val ) ) { return val . map ( ( val2 ) => { return ( encodeURIComponent ( key ) + '=' + encodeURIComponent ( val2 ) ) ; } ) . join ( '&' ) ; } return encodeURIComponent ( key ) + '=' + encodeURIComponent ( val ) ; } ) . join ( '&' ) : '' ; } param service_url returns async request ( service_url ) { service_url = service_url . replace ( /&amp;/g , '&' ) ; this . service_url = service_url ; const params = this . hsUtilsService . getParamsFromUrl ( service_url ) ; const path = this . getPathFromUrl ( service_url ) ; if ( params . request == undefined && params . REQUEST == undefined ) { params . request = 'GetCapabilities' ; } else if ( params . request !== undefined ) { params . request = 'GetCapabilities' ; } else if ( params . REQUEST !== undefined ) { params . REQUEST = 'GetCapabilities' ; } if ( params . service == undefined && params . SERVICE == undefined ) { params . service = 'WFS' ; } if ( params . version == undefined && params . VERSION == undefined ) { params . version = '1.1.0' ; } let url = [ path , this . params2String ( params ) ] . join ( '?' ) ; url = this . hsUtilsService . proxify ( url ) ; if ( this . hsCapabilityCacheService . get ( url ) ) { return this . hsCapabilityCacheService . get ( url ) ; } try { const r = await this . httpClient . get ( url , { responseType : 'text' , } ) . pipe ( takeUntil ( this . hsAddDataService . cancelUrlRequest ) ) . toPromise ( ) ; const wrap = { response : r } ; this . hsCapabilityCacheService . set ( url , wrap ) ; return wrap ; } catch ( e ) { return { response : e , error : true } ; } } }