import * as L from 'leaflet' ; import { catchError } from 'rxjs/operators' ; import { of } from 'rxjs' ; /**
 * Class for asynchronous overlays used with the shared-map component.
 *
 * Notable methods subclasses may want to override:
 * - onEachFeature(feature: any, layer: L.Layer)
 *   called by leaflet's GeoJSON layer.
 *
 * - parse(json|string)
 *   parse returned data and return a GeoJSON Feature or FeatureCollection.
 *   default implementation converts strings to json
 *   if returned data is not already json
 *
 * - style(feature)
 *   called by leaflet's GeoJSON layer.
 */ const AsynchronousGeoJSONOverlay = L . GeoJSON . extend ( { bounds : null , data : null , enabled : true , error : Error , id : 'async-geojson' , legends : [ ] , map : null , styles : { } , title : 'Async GeoJSON' , url : null , /**
     * Init function
     */ initialize : function ( ) { this . httpClient = null ; L . GeoJSON . prototype . initialize . call ( this , [ ] , { onEachFeature : ( feature , layer ) => this . onEachFeature ( feature , layer ) , pointToLayer : ( feature , layer ) => this . pointToLayer ( feature , layer ) , style : feature => this . style ( feature ) } ) ; } , /**
     * Runs after the geoJSON data is successfully added
     */ afterAdd : function ( ) { } , param { Error } return { Observable } handleError : function ( error ) { this . error = error ; this . data = null ; return of ( null ) ; } , /**
     * Fetch data, and ensure it is parsed into geojson
     */ loadData : function ( ) { if ( ! this . url || ! this . httpClient ) { this . data = null ; return ; } if ( this . data !== null ) { return ; } this . data = 'loading' ; this . httpClient . get ( this . url ) . pipe ( catchError ( error => this . handleError ( error ) ) ) . subscribe ( data => { try { data = this . parse ( data ) ; this . data = data ; this . addData ( data ) ; this . afterAdd ( ) ; } catch ( error ) { this . handleError ( error ) ; } } ) ; } , /**
     * Get geoJSON data and add it to the existing layer
     */ onAdd : function ( map ) { this . map = map ; L . GeoJSON . prototype . onAdd . call ( this , map ) ; this . loadData ( ) ; this . afterAdd ( ) ; } , onEachFeature : function ( feature , layer ) { } , pointToLayer : function ( feature , latlng ) { const defaultOptions = { color : '#000' , fillColor : '#ff7800' , fillOpacity : 0.8 , opacity : 1 , radius : 8 , weight : 1 } ; return L . circleMarker ( latlng , defaultOptions ) ; } , param data { Any } return { Any } parse : function ( data ) { data = typeof data === 'string' ? JSON . parse ( data ) : data ; return data ; } , style : function ( feature ) { return { } ; } } ) ; export { AsynchronousGeoJSONOverlay } ;