import { FormatterService } from '@core/formatter.service' ; import { AsynchronousGeoJSONOverlay } from '@shared/map-overlay/asynchronous-geojson-overlay' ; import { RomanPipe } from '@shared/roman.pipe' ; /**
 * DYFI responses overlay for leaflet map
 */ const DyfiResponseOverlay = AsynchronousGeoJSONOverlay . extend ( { id : '' , legends : [ ] , romanPipe : new RomanPipe ( ) , title : '' , unit : null , url : '' , param product initialize : function ( product , unit ) : void { if ( unit === 10 ) { this . id = 'dyfi-responses-10km' ; this . title = 'DYFI Responses 10 km' ; this . unit = 10 ; } else { this . id = 'dyfi-responses-1km' ; this . title = 'DYFI Responses 1 km' ; this . unit = 1 ; } AsynchronousGeoJSONOverlay . prototype . initialize . call ( this ) ; const legend = document . createElement ( 'img' ) ; legend . src = './assets/legend-geocoded-area.png' ; legend . setAttribute ( 'alt' , 'Did You Feel It? Geocoded Area' ) ; this . legends . push ( legend ) ; this . url = this . getUrl ( product ) ; } , param product returns getUrl : function ( product ) : string { if ( product === null ) { return null ; } let url ; if ( this . unit === 1 ) { url = 'dyfi_geo_1km.geojson' ; } else if ( this . unit === 10 ) { url = 'dyfi_geo_10km.geojson' ; } else { return null ; } return product . contents [ url ] . url ; } , param feature param layer onEachFeature : function ( feature , layer ) : void { let formatter = new FormatterService ( ) ; if ( feature . properties ) { layer . setStyle ( { color : '#666' , fillColor : formatter . mmiColor ( feature . properties . cdi ) , fillOpacity : 0.9 , weight : 0.5 } ) ; layer . bindPopup ( this . formatPopup ( feature ) ) ; } formatter = null ; } , param feature return formatPopup : function ( feature ) : string { return this . generatePopupContent ( feature ) ; } , param feature returns generatePopupContent : function ( feature ) { let formatter = new FormatterService ( ) ; let mmi , p , dist , name , nresp ; p = feature . properties ; dist = formatter . distance ( p . dist , 'km' ) ; name = p . name ; mmi = this . romanPipe . transform ( p . cdi ) ; nresp = p . nresp ; const dyfiResponse = `
      <dyfi-response
        dist="${ dist }"
        intensity="${ p . cdi }"
        mmi="${ mmi }"
        name="${ name }"
        nresp="${ nresp }"
      ></dyfi-response>
    ` ; formatter = null ; return dyfiResponse ; } } ) ; export { DyfiResponseOverlay } ;