import { Component , OnDestroy } from '@angular/core' ; import Feature from 'ol/Feature' ; import { Geometry } from 'ol/geom' ; import { Subject } from 'rxjs' ; import { takeUntil } from 'rxjs/operators' ; import { HsEventBusService } from '../core/event-bus.service' ; import { HsSearchService } from './search.service' ; import { setHighlighted } from '../../common/feature-extensions' ; /**
 * Add search results template to page
 */ @ Component ( { selector : 'hs-search-results' , templateUrl : './partials/search-results.component.html' , } ) export class HsSearchResultsComponent implements OnDestroy { searchResultsVisible : boolean ; data : any = { } ; fcode_zoom_map : any ; private ngUnsubscribe = new Subject < void > ( ) ; constructor ( private hsEventBusService , private hsSearchService ) { this . hsEventBusService . searchResultsReceived . pipe ( takeUntil ( this . ngUnsubscribe ) ) . subscribe ( ( _ ) => { this . searchResultsReceived ( ) ; } ) ; this . hsEventBusService . clearSearchResults . pipe ( takeUntil ( this . ngUnsubscribe ) ) . subscribe ( ( _ ) => { this . clear ( ) ; } ) ; } ngOnDestroy ( ) { this . ngUnsubscribe . next ( ) ; this . ngUnsubscribe . complete ( ) ; } /**
     * Handler for receiving results of search request, sends results to correct parser
     */ searchResultsReceived ( ) { this . data = this . hsSearchService . data ; this . searchResultsVisible = true ; this . hsSearchService . showResultsLayer ( ) ; } clear ( ) { this . searchResultsVisible = false ; } param featureId findFeature ( featureId ) { return this . hsSearchService . searchResultsLayer . getSource ( ) . getFeatureById ( featureId ) ; } param result param highlight highlightResult ( result , highlight ) { const found = this . findFeature ( result . featureId ) ; if ( found ) { setHighlighted ( found , highlight ) ; } } param result zoomTo ( result ) { this . fcode_zoom_map = { 'PPLA' : 12 , 'PPL' : 15 , 'PPLC' : 10 , 'ADM1' : 9 , 'FRM' : 15 , 'PPLF' : 13 , 'LCTY' : 13 , 'RSTN' : 15 , 'PPLA3' : 9 , 'AIRP' : 13 , 'AIRF' : 13 , 'HTL' : 17 , 'STM' : 14 , 'LK' : 13 , } ; let zoom_level = 10 ; if ( result . fcode !== undefined && this . fcode_zoom_map [ result . fcode ] !== undefined ) { zoom_level = this . fcode_zoom_map [ result . fcode ] ; } this . hsSearchService . selectResult ( result , zoom_level ) ; } }