import { Bbox , BboxWithZoom , Point } from 'facilmap-types' ; import L , { LatLng , LatLngBounds , Map , TooltipOptions } from 'leaflet' ; export const tooltipOptions = { direction : "right" } ; export function leafletToFmBbox ( bbox ) ; export function leafletToFmBbox ( bbox , zoom ) ; export function leafletToFmBbox ( bbox , zoom ? ) { const ret = { top : bbox . getNorth ( ) , left : Math . max ( - 180 , bbox . getWest ( ) ) , right : Math . min ( 180 , bbox . getEast ( ) ) , bottom : bbox . getSouth ( ) } ; if ( zoom != null ) ret . zoom = zoom ; return ret ; } export function fmToLeafletBbox ( bbox ) { return L . latLngBounds ( L . latLng ( bbox . bottom , bbox . left ) , L . latLng ( bbox . top , bbox . right ) ) ; } param trackPoints { Array < L . LatLng > } param bounds { L . LatLngBounds } return { Array < Array < L . LatLng > > } export function disconnectSegmentsOutsideViewport ( trackPoints , bounds ) { const ret = [ [ ] ] ; let lastOneIn = true ; let currentIdx = 0 ; for ( const trackPoint of trackPoints ) { if ( bounds . contains ( trackPoint ) ) { lastOneIn = true ; ret [ currentIdx ] . push ( trackPoint ) ; } else if ( lastOneIn ) { lastOneIn = false ; ret [ currentIdx ] . push ( trackPoint ) ; } else { if ( ret [ currentIdx ] . length > 1 ) currentIdx ++ ; ret [ currentIdx ] = [ trackPoint ] ; } } if ( ret [ currentIdx ] . length <= 1 ) ret . pop ( ) ; return ret ; } param latLng1 { L . LatLng } param latLng2 { L . LatLng } param map { L . Map } param zoom { Number ? } returns { boolean } export function pointsEqual ( latLng1 , latLng2 , map , zoom ? ) { latLng1 = L . latLng ( latLng1 ) ; latLng2 = L . latLng ( latLng2 ) ; return map . project ( latLng1 , zoom ) . distanceTo ( map . project ( latLng2 , zoom ) ) < 1 ; } export interface BasicTrackPoints { [ idx ] : Point & { ele ? : number ; } ; length : number ; } export function trackPointsToLatLngArray ( trackPoints ) { const result = [ ] ; if ( trackPoints ) { for ( let i = 0 ; i < trackPoints . length ; i ++ ) { if ( trackPoints [ i ] ) { result . push ( new LatLng ( trackPoints [ i ] ! . lat , trackPoints [ i ] ! . lon , trackPoints [ i ] ! . ele ) ) ; } } } return result ; }