import * as L from 'leaflet' ; import { AsynchronousGeoJSONOverlay } from './asynchronous-geojson-overlay' ; import { EpicenterOverlay } from './epicenter-overlay' ; /**
 * Shakemaop intensity overlay for leaflet map
 */ const ShakeAlertOverlay = AsynchronousGeoJSONOverlay . extend ( { bounds : null , data : null , id : 'shakealert' , legends : [ ] , title : 'ShakeAlert' , param product initialize : function ( product ) { AsynchronousGeoJSONOverlay . prototype . initialize . call ( this ) ; if ( product . features ) { this . data = product ; this . addData ( this . data ) ; } } , param layer addCircleTooltip : function ( layer ) { if ( ! layer || ! layer . getBounds ( ) ) { return ; } const bounds = layer . getBounds ( ) ; const latlng = { lat : bounds . _southWest . lat , lng : layer . feature . geometry . coordinates [ 0 ] } ; const marker = this . createMarkerPlaceholder ( latlng ) ; this . bindLayerTooltip ( marker , layer . feature . properties . name ) ; } , param layer addPolygonTooltip : function ( layer ) { if ( ! layer ) { return ; } const coordinates = layer . feature . geometry . coordinates ; const latlng = { lat : coordinates [ 0 ] [ 0 ] [ 1 ] , lng : coordinates [ 0 ] [ 0 ] [ 0 ] } ; const marker = this . createMarkerPlaceholder ( latlng ) ; this . bindLayerTooltip ( marker , layer . feature . properties . name ) ; } , /**
     * Overrides AsynchronousGeoJSONOverlay.afterAdd(), called by L.Layer.onAdd()
     *
     * After the layers are added to the map bind tooltips.
     * This is done after the layers are added to the map because
     * we need to know the bounds of the circle features in order to bind
     * the tooltip to the edge of the circle.
     */ afterAdd : function ( ) { this . bounds = this . getBounds ( ) ; setTimeout ( ( ) => { this . map . fitBounds ( this . bounds , { padding : [ 30 , 30 ] } ) ; } , 0 ) ; this . map . eachLayer ( layer => { try { this . addTooltipToLayer ( layer ) ; } catch ( e ) { console . log ( e ) ; } } ) ; } , param layer addTooltipToLayer : function ( layer ) { if ( ! layer || ! layer . feature || ! layer . feature . properties || ! layer . feature . properties . name || ! layer . feature . geometry ) { throw new Error ( 'Leaflet feature is missing a tooltip or geometry' ) ; } if ( layer . feature . geometry . type === 'Point' && layer . feature . properties . radius ) { this . addCircleTooltip ( layer ) ; } else if ( layer . feature . geometry . type === 'Polygon' ) { this . addPolygonTooltip ( layer ) ; } else { this . bindLayerTooltip ( layer , layer . feature . properties . name ) ; } } , param layer bindLayerTooltip : function ( layer , text , options = { } ) { layer . bindTooltip ( text , Object . assign ( { className : 'permanent-label' , direction : 'top' , permanent : true } , options ) ) ; } , param latlng createMarkerPlaceholder : function ( latlng ) { const icon = L . icon ( { iconSize : [ 0 , 0 ] , iconUrl : 'empty' } ) ; return L . marker ( latlng , { icon : icon } ) . addTo ( this . map ) ; } , param feature param layer pointToLayer : function ( feature , latlng ) { if ( ! feature || ! feature . properties ) { return ; } const properties = feature . properties ; if ( properties . radius ) { return L . circle ( latlng , properties ) ; } else if ( properties . icon && properties . icon . toUpperCase ( ) === 'EPICENTER' ) { return new EpicenterOverlay ( { properties : { latitude : latlng . lat , longitude : latlng . lng } } ) ; } else { const defaultOptions = { color : '#000' , fillColor : '#ff7800' , fillOpacity : 0.8 , opacity : 1 , radius : 8 , weight : 1 } ; return L . circleMarker ( latlng , defaultOptions ) ; } } , param geojsonProperties translateGeojsonStyles : function ( properties ) { const mapping = { fill : 'fillColor' , 'fill-opacity' : 'fillOpacity' , stroke : 'color' , 'stroke-dasharray' : 'dashArray' , 'stroke-dashoffset' : 'dashOffset' , 'stroke-opacity' : 'opacity' , 'stroke-width' : 'weight' } ; const results = { } ; if ( ! properties ) { return { } ; } for ( const key of Object . keys ( properties ) ) { const property = mapping [ key ] ; if ( property ) { results [ property ] = properties [ key ] ; } } return results ; } , param feature style : function ( feature ) { return this . translateGeojsonStyles ( feature . properties ) ; } } ) ; export { ShakeAlertOverlay } ;