@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 1.21 kB
JavaScript
import"../../../geometry.js";import e from"../../../core/Error.js";import{getMetersPerUnitForSR as r}from"../../../core/unitUtils.js";import{getReferenceEllipsoid as t}from"../../../geometry/ellipsoidUtils.js";import{getGeometryServiceURL as o}from"../../../portal/support/geometryServiceUtils.js";import{project as i}from"../../../rest/geometryService/project.js";import s from"../../../rest/support/ProjectParameters.js";import m from"../../../geometry/Point.js";import p from"../../../geometry/SpatialReference.js";class a{constructor(i,s){this.spatialReference=s,this.unitInMeters=r(this.spatialReference,t(this.spatialReference).metersPerDegree),this._geometryServiceURLPromise=o(i&&i.get("portalItem")).catch((()=>{throw new e("mapcoordshelper:missing-geometry-service","Must specify geometryService in esri/config")}))}async toGeographic(e){const r=await this._geometryServiceURLPromise;let t,o=!0;Array.isArray(e[0])&&"number"!=typeof e[0]?t=e:(t=[e],o=!1);const a=t.map((e=>e instanceof m?e:new m(e,this.spatialReference))),c=new s({geometries:a,outSpatialReference:p.WGS84}),n=(await i(r,c)).map((e=>"point"===e.type?[e.x,e.y]:void 0)).filter((e=>!!e));return o?n:n[0]}}export{a as MapCoordsHelper};