import { HttpClient } from '@angular/common/http' ; import { Injectable } from '@angular/core' ; import { BehaviorSubject } from 'rxjs' ; import { Event } from '../event' ; @ Injectable ( ) export class WaveformService { error : any ; event$ = new BehaviorSubject < any > ( null ) ; irisServiceUrl = 'https://service.iris.edu/fdsnws/event/1/query' ; constructor ( private httpClient ) { } getIrisEvent ( ev ) { const options = { params : this . getSearchParams ( ev ) , responseType : 'text' as 'text' } ; this . httpClient . get ( this . irisServiceUrl , options ) . subscribe ( response => { if ( response ) { this . event$ . next ( this . parseIrisEventId ( response ) ) ; } } ) ; } /**
     * Gets search parameters from the model and creates search object
     */ getSearchParams ( ev ) { let latitude , longitude , search , time ; search = null ; if ( ev ) { latitude = ev . geometry . coordinates [ 1 ] ; longitude = ev . geometry . coordinates [ 0 ] ; time = Number ( ev . properties . time ) ; search = { endtime : new Date ( time + 16000 ) . toISOString ( ) . replace ( 'Z' , '' ) , format : 'text' , latitude : latitude , longitude : longitude , maxradius : '1' , starttime : new Date ( time - 16000 ) . toISOString ( ) . replace ( 'Z' , '' ) } ; } return search ; } param { string } data parseIrisEventId ( data ) { return data . split ( '\n' ) [ 1 ] . split ( '|' ) [ 0 ] ; } }