import { Component , OnInit , OnDestroy } from '@angular/core' ; import { Subscription } from 'rxjs' ; import { EventService } from '@core/event.service' ; import { StationService } from '@core/station.service' ; /**
 * Station list component, shows the available stations when selecting the
 * 'station list' tab inside the main shakemap component
 */ @ Component ( { selector : 'shakemap-station-list' , styleUrls : [ './station-list.component.scss' ] , templateUrl : './station-list.component.html' } ) export class StationListComponent implements OnInit , OnDestroy { descending = false ; sortBy = { 'name' : 'distance' , 'display' : 'Distance' } ; sortOptions = [ { 'name' : 'distance' , 'display' : 'Distance' } , { 'name' : 'intensity' , 'display' : 'Intensity' } , { 'name' : 'pga' , 'display' : 'PGA' } , { 'name' : 'pgv' , 'display' : 'PGV' } ] ; stations : any [ ] = [ ] ; subs = new Subscription ( ) ; constructor ( public eventService , public stationService ) { } ngOnDestroy ( ) { this . subs . unsubscribe ( ) ; } ngOnInit ( ) { this . subs . add ( this . stationService . stationsJson$ . subscribe ( stationsJson => { this . onStations ( stationsJson ) ; } ) ) ; this . subs . add ( this . eventService . product$ . subscribe ( product => { this . onProduct ( product ) ; } ) ) ; } param product onProduct ( product ) { this . stationService . getStations ( product ) ; } param stations onStations ( stationsJson ) { if ( ! stationsJson ) { this . stations = [ ] ; return ; } this . stations = stationsJson . features ; } param index param item trackByIndex ( index , item ) { return index ; } }