import * as L from "leaflet" ; import { GeodesicGeometry , Statistics } from "./geodesic-geom" ; import { GeodesicOptions } from "./geodesic-core" ; import { latlngExpressiontoLatLng } from "./types-helper" ; /**
 * Can be used to create a geodesic circle based on L.Polyline
 */ export class GeodesicCircleClass extends L . Polyline { defaultOptions : GeodesicOptions = { wrap : true , steps : 24 , fill : true , noClip : true } ; readonly geom : GeodesicGeometry ; center : L . LatLng ; radius : number ; statistics : Statistics = { } as any ; constructor ( center ? , options ? ) { super ( [ ] , options ) ; L . Util . setOptions ( this , { ... this . defaultOptions , ... options } ) ; const extendedOptions = this . options as GeodesicOptions ; this . radius = ( extendedOptions . radius === undefined ) ? 1000 * 1000 : extendedOptions . radius ; this . center = ( center === undefined ) ? new L . LatLng ( 0 , 0 ) : latlngExpressiontoLatLng ( center ) ; this . geom = new GeodesicGeometry ( this . options ) ; this . update ( ) ; } /**
     * Updates the geometry and re-calculates some statistics
     */ private update ( ) { const circle = this . geom . circle ( this . center , this . radius ) ; this . statistics = this . geom . updateStatistics ( [ [ this . center ] ] , [ circle ] ) ; this . statistics . totalDistance = this . geom . multilineDistance ( [ circle ] ) . reduce ( ( x , y ) => x + y , 0 ) ; if ( ( this . options as GeodesicOptions ) . wrap ) { const split = this . geom . splitCircle ( circle ) ; super . setLatLngs ( split ) ; } else { super . setLatLngs ( circle ) ; } } param latlng return distanceTo ( latlng ) { const dest = latlngExpressiontoLatLng ( latlng ) ; return this . geom . distance ( this . center , dest ) ; } param center param radius setLatLng ( center , radius ? ) { this . center = latlngExpressiontoLatLng ( center ) ; this . radius = radius ? radius : this . radius ; this . update ( ) ; } param radius param center setRadius ( radius , center ? ) { this . radius = radius ; this . center = center ? latlngExpressiontoLatLng ( center ) : this . center ; this . update ( ) ; } }