'use strict' ; import type { GeoJSON , GeoJSONFeature , TopoJSON } from '../Maps/GeoJSON' ; import type MapPointOptions from '../Series/Map/MapPointOptions' ; import type MapPointPointOptions from '../Series/MapPoint/MapPointPointOptions' ; import type { ProjectedXY } from '../Maps/MapViewOptions' ; import type Series from '../Core/Series/Series' ; import type SVGPath from '../Core/Renderer/SVG/SVGPath' ; import Chart from '../Core/Chart/Chart.js' ; import F from '../Core/FormatUtilities.js' ; const { format } = F ; import H from '../Core/Globals.js' ; const { win } = H ; import MU from '../Maps/MapUtilities.js' ; const { pointInPolygon } = MU ; import U from '../Core/Utilities.js' ; const { error , extend , merge , wrap } = U ; declare module '../Core/Chart/ChartLike' { interface ChartLike { requires mapCredits ? : string ; requires mapCreditsFull ? : string ; requires mapTransforms ? : any ; requires fromLatLonToPoint ( latLon ) : ProjectedXY | undefined ; requires fromPointToLatLon ( point ) : ( Highcharts . MapLatLonObject | undefined ) ; requires transformFromLatLon ( latLon , transform ) : ProjectedXY | undefined ; requires transformToLatLon ( point , transform ) : ( Highcharts . MapLatLonObject | undefined ) ; } } declare module '../Core/Chart/ChartOptions' { interface ChartOptions { requires proj4 ? : any ; } } private declare global { namespace Highcharts { interface MapPathObject { name ? : string ; path ? : SVGPath ; properties ? : object ; } interface MapLatLonObject { lat : number ; lon : number ; } requires function geojson ( geojson , hType ? , series ? ) ; } interface Window { d3 : any ; proj4 : any ; } } interface name type { string | undefined } name type { string | undefined } name type { Highcharts . Dictionary < any > | undefined } name type { Array < Highcharts . GeoJSONFeature > } name type { Highcharts . Dictionary < Highcharts . GeoJSONTranslation > | undefined } name type { string | undefined } name type { string | undefined } name type { string | undefined } interface extends Highcharts . Dictionary < * > name type { string } interface name type { string } name type { Highcharts . Dictionary < * > | undefined } name type { number | undefined } name type { number | undefined } name type { number | undefined } name type { number | undefined } name type { number | undefined } name type { number | undefined } name type { number | undefined } name type { number | undefined } name type { number | undefined } interface name type { number } name type { number } interface name type { number } name type { number } typedef { Array < number > } Highcharts . LonLatArray typedef { Object } Highcharts . TopoJSON '' ; requires sample function param { Highcharts . MapLatLonObject } latLon param { * } transform The transform definition to use as explained in the
 *         https .
 *
 *  return { ProjectedXY } Chart . prototype . transformFromLatLon = function ( latLon , transform ) : ProjectedXY | undefined { type { Function } product apioption const proj4 = this . options . chart . proj4 || win . proj4 ; if ( ! proj4 ) { error ( 21 , false , this ) ; return ; } const { jsonmarginX = 0 , jsonmarginY = 0 , jsonres = 1 , scale = 1 , xoffset = 0 , xpan = 0 , yoffset = 0 , ypan = 0 } = transform ; const projected = proj4 ( transform . crs , [ latLon . lon , latLon . lat ] ) , cosAngle = transform . cosAngle || ( transform . rotation && Math . cos ( transform . rotation ) ) , sinAngle = transform . sinAngle || ( transform . rotation && Math . sin ( transform . rotation ) ) , rotated = transform . rotation ? [ projected [ 0 ] * cosAngle + projected [ 1 ] * sinAngle , - projected [ 0 ] * sinAngle + projected [ 1 ] * cosAngle ] : projected ; return { x : ( ( rotated [ 0 ] - xoffset ) * scale + xpan ) * jsonres + jsonmarginX , y : - ( ( ( yoffset - rotated [ 1 ] ) * scale + ypan ) * jsonres - jsonmarginY ) } ; } ; requires sample function param { Highcharts . Point | Highcharts . ProjectedXY } point param { * } transform The transform definition to use as explained in the
 *         https .
 *
 *  return { Highcharts . MapLatLonObject | undefined } Chart . prototype . transformToLatLon = function ( point , transform ) : ( Highcharts . MapLatLonObject | undefined ) { const proj4 = this . options . chart . proj4 || win . proj4 ; if ( ! proj4 ) { error ( 21 , false , this ) ; return ; } if ( point . y === null ) { return ; } const { jsonmarginX = 0 , jsonmarginY = 0 , jsonres = 1 , scale = 1 , xoffset = 0 , xpan = 0 , yoffset = 0 , ypan = 0 } = transform ; const normalized = { x : ( ( point . x - jsonmarginX ) / jsonres - xpan ) / scale + xoffset , y : ( ( point . y - jsonmarginY ) / jsonres + ypan ) / scale + yoffset } , cosAngle = transform . cosAngle || ( transform . rotation && Math . cos ( transform . rotation ) ) , sinAngle = transform . sinAngle || ( transform . rotation && Math . sin ( transform . rotation ) ) , projected = win . proj4 ( transform . crs , 'WGS84' , transform . rotation ? { x : normalized . x * cosAngle + normalized . y * - sinAngle , y : normalized . x * sinAngle + normalized . y * cosAngle } : normalized ) ; return { lat : projected . y , lon : projected . x } ; } ; requires sample function param { Highcharts . Point | Highcharts . ProjectedXY } point return { Highcharts . MapLatLonObject | undefined } Chart . prototype . fromPointToLatLon = function ( point ) : ( Highcharts . MapLatLonObject | undefined ) { const transforms = this . mapTransforms ; if ( transforms ) { for ( const transform in transforms ) { if ( Object . hasOwnProperty . call ( transforms , transform ) && transforms [ transform ] . hitZone && pointInPolygon ( point , transforms [ transform ] . hitZone . coordinates [ 0 ] ) ) { return this . transformToLatLon ( point , transforms [ transform ] ) ; } } return this . transformToLatLon ( point , transforms [ 'default' ] ) ; } const mapView = this . mapView ; if ( mapView && typeof point . y === 'number' ) { const pxPoint = mapView . projectedUnitsToPixels ( point ) ; for ( const inset of mapView . insets ) { if ( inset . hitZone && pointInPolygon ( pxPoint , inset . hitZone . coordinates [ 0 ] ) ) { const insetProjectedPoint = inset . pixelsToProjectedUnits ( pxPoint ) , coordinates = inset . projection . inverse ( [ insetProjectedPoint . x , insetProjectedPoint . y ] ) ; return { lon : coordinates [ 0 ] , lat : coordinates [ 1 ] } ; } } const coordinates = mapView . projection . inverse ( [ point . x , point . y ] ) ; return { lon : coordinates [ 0 ] , lat : coordinates [ 1 ] } ; } } ; requires sample function param { Highcharts . MapLatLonObject } latLon return { Highcharts . ProjectedXY } Chart . prototype . fromLatLonToPoint = function ( latLon ) : ProjectedXY | undefined { let transforms = this . mapTransforms , transform , coords ; if ( transforms ) { for ( transform in transforms ) { if ( Object . hasOwnProperty . call ( transforms , transform ) && transforms [ transform ] . hitZone ) { coords = this . transformFromLatLon ( latLon , transforms [ transform ] ) ; if ( coords && pointInPolygon ( coords , transforms [ transform ] . hitZone . coordinates [ 0 ] ) ) { return coords ; } } } return this . transformFromLatLon ( latLon , transforms [ 'default' ] ) ; } const mapView = this . mapView ; if ( mapView ) { for ( const inset of mapView . insets ) { if ( inset . options . geoBounds && pointInPolygon ( { x : latLon . lon , y : latLon . lat } , inset . options . geoBounds . coordinates [ 0 ] ) ) { const insetProjectedPoint = inset . projection . forward ( [ latLon . lon , latLon . lat ] ) , pxPoint = inset . projectedUnitsToPixels ( { x : insetProjectedPoint [ 0 ] , y : insetProjectedPoint [ 1 ] } ) , mapViewProjectedPoint = mapView . pixelsToProjectedUnits ( pxPoint ) ; return mapViewProjectedPoint ; } } const point = mapView . projection . forward ( [ latLon . lon , latLon . lat ] ) ; return { x : point [ 0 ] , y : point [ 1 ] } ; } } ; function topo2geo ( topology , objectName ? ) { if ( ! objectName ) { objectName = Object . keys ( topology . objects ) [ 0 ] ; } const object = topology . objects [ objectName ] ; if ( object [ 'hc-decoded-geojson' ] ) { return object [ 'hc-decoded-geojson' ] ; } let arcsArray = topology . arcs as any [ ] ; if ( topology . transform ) { const { scale , translate } = topology . transform ; arcsArray = topology . arcs . map ( ( arc ) : any => { let x = 0 , y = 0 ; return arc . map ( ( position ) : number [ ] => { position = position . slice ( ) ; position [ 0 ] = ( x += position [ 0 ] ) * scale [ 0 ] + translate [ 0 ] ; position [ 1 ] = ( y += position [ 1 ] ) * scale [ 1 ] + translate [ 1 ] ; return position ; } ) ; } ) ; } const arcsToCoordinates = ( arcs ) : number [ ] => { if ( typeof arcs [ 0 ] === 'number' ) { return arcs . reduce ( ( coordinates , arcNo , i ) : number [ ] => { let arc = arcNo < 0 ? arcsArray [ ~ arcNo ] : arcsArray [ arcNo ] ; if ( arcNo < 0 ) { arc = arc . slice ( 0 , i === 0 ? arc . length : arc . length - 1 ) ; arc . reverse ( ) ; } else if ( i ) { arc = arc . slice ( 1 ) ; } return coordinates . concat ( arc ) ; } , [ ] ) ; } return arcs . map ( arcsToCoordinates ) ; } ; const features = object . geometries . map ( ( geometry ) : GeoJSONFeature => ( { type : 'Feature' , properties : geometry . properties , geometry : { type : geometry . type , coordinates : geometry . coordinates || arcsToCoordinates ( geometry . arcs ) } as any } ) ) ; const geojson = { type : 'FeatureCollection' , copyright : topology . copyright , copyrightShort : topology . copyrightShort , copyrightUrl : topology . copyrightUrl , features , 'hc-recommended-mapview' : object [ 'hc-recommended-mapview' ] , bbox : topology . bbox } ; object [ 'hc-decoded-geojson' ] = geojson ; return geojson ; } /**
 * Highcharts Maps only. Restructure a GeoJSON or TopoJSON object in preparation
 * to be read directly by the
 *  https * option. The object will be broken down to fit a specific Highcharts type,
 * either `map`, `mapline` or `mappoint`. Meta data in GeoJSON's properties
 * object will be copied directly over to  Point . properties in Highcharts
 * Maps.
 *
 *  requires sample sample sample function param { Highcharts . GeoJSON | Highcharts . TopoJSON } json param { string } hType return { Array < * > } function geojson ( json , hType = 'map' , series ? ) { const mapData = [ ] ; const geojson = json . type === 'Topology' ? topo2geo ( json ) : json ; geojson . features . forEach ( function ( feature ) : void { const geometry = feature . geometry || { } , type = geometry . type as any , coordinates = geometry . coordinates as any , properties = feature . properties ; let pointOptions ; if ( ( hType === 'map' || hType === 'mapbubble' ) && ( type === 'Polygon' || type === 'MultiPolygon' ) ) { if ( coordinates . length ) { pointOptions = { geometry : { coordinates , type } } ; } } else if ( hType === 'mapline' && ( type === 'LineString' || type === 'MultiLineString' ) ) { if ( coordinates . length ) { pointOptions = { geometry : { coordinates , type } } ; } } else if ( hType === 'mappoint' && type === 'Point' ) { if ( coordinates . length ) { pointOptions = { geometry : { coordinates , type } } ; } } if ( pointOptions ) { const name = properties && ( properties . name || properties . NAME ) ; mapData . push ( extend ( pointOptions , { name : typeof name === 'string' ? name : void 0 , requires name type { * } properties } ) ) ; } } ) ; if ( series && geojson . copyrightShort ) { series . chart . mapCredits = format ( ( series . chart . options . credits as any ) . mapText , { geojson : geojson } ) ; series . chart . mapCreditsFull = format ( ( series . chart . options . credits as any ) . mapTextFull , { geojson : geojson } ) ; } return mapData ; } wrap ( Chart . prototype , 'addCredits' , function ( this , proceed , credits ) : void { credits = merge ( true , this . options . credits , credits ) ; if ( this . mapCredits ) { credits . href = null as any ; } proceed . call ( this , credits ) ; if ( this . credits && this . mapCreditsFull ) { this . credits . attr ( { title : this . mapCreditsFull } ) ; } } ) ; H . geojson = geojson ; const GeoJSONModule = { geojson , topo2geo } ; export default GeoJSONModule ;