import { IRequestOptions , request } from "@esri/arcgis-rest-request" ; import { getProp } from "@esri/hub-common" ; /**
 * Wrapper for geometry service functions
 */ const geometryService = { AGO_GEOMETRY_SERVICE : "https://utility.arcgisonline.com/arcgis/rest/services/Geometry/GeometryServer" , param portal getUrl ( portal ? ) { let url = this . AGO_GEOMETRY_SERVICE ; if ( portal ) { const portalService = getProp ( portal , "helperServices.geometry.url" ) ; if ( portalService ) { url = portalService ; } } return url ; } , param { string } url returns { boolean } shouldAddTokenToCall ( url ) { let result = true ; if ( url . indexOf ( "arcgisonline" ) > - 1 ) { result = false ; } return result ; } , param { string } serviceUrl param { * } inSR param { * } outSR param { string } geometryType param { [ any ] } geometries param { IRequestOptions } requestOptions returns { Promise < any > } project ( serviceUrl , inSR , outSR , geometryType , geometries , requestOptions ) { const url = `${ serviceUrl }/project` ; const opts = { ... requestOptions } as IRequestOptions ; opts . params = { geometries : { geometryType , geometries } , transformForward : false , transformation : "" , inSR , outSR , f : "json" } ; if ( ! this . shouldAddTokenToCall ( url ) && opts . authentication ) { delete opts . authentication ; } return request ( url , opts ) ; } } ; export default geometryService ;