@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.38 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import n from"../core/Error.js";import{i as e,b as t,l as o,c as r,d as i,e as l,f as a,P as s,a as c}from"../chunks/pe.js";import u from"./Point.js";import d from"./SpatialReference.js";import{parseNumber as f}from"../intl/number.js";function _(){return e()}function S(){return t()}function w(){return o()}function E(n,e){const t=[];n=(n=(n=n.replaceAll(/[\u00B0\u00BA]/g,"^")).replaceAll("′","'")).replaceAll("″",'"');const o=R(e);return r.dmsToGeog(o,1,[n],t)?new u(t[0][0],t[0][1],e||d.WGS84):null}function g(n){return n&&_()?f(n)??E(`0° 0' 0" N | ${n}`)?.longitude??E(`0 | ${n}`)?.longitude??null:null}function m(n){return n&&_()?f(n)??E(`${n} | 0° 0' 0" E`)?.latitude??E(`${n} | 0`)?.latitude??null:null}function T(n,e,t){const o=[],r=b(t);if(-1===r)return console.warn(`invalid conversionMode: ${t}`),null;const l=R(e);return i.mgrsToGeogExtended(l,1,[n],r,o)?new u(o[0][0],o[0][1],e||d.WGS84):null}function P(n,e){const t=[];!e&&/\(.+27/.test(n)&&(e=d.GCS_NAD_1927);const o=R(e);return l.usngToGeog(o,1,[n],t)?new u(t[0][0],t[0][1],e||d.WGS84):null}function G(n,e,t){const o=[],r=A(t);if(-1===r)return console.warn(`invalid conversionMode: ${t}`),null;const i=R(e);return a.utmToGeog(i,1,[n],r,o)?new u(o[0][0],o[0][1],e||d.WGS84):null}function k(n,e,t=0){const o=[[n.x,n.y]],i=[],l=R(n.spatialReference);let a=0;switch(e){case"dd":a=r.geogToDd(l,1,o,t,i);break;case"ddm":a=r.geogToDdm(l,1,o,t,i);break;case"dms":a=r.geogToDms(l,1,o,t,i);break;default:return console.warn(`invalid format: ${e}`),null}return a?i[0]:null}function p(n,e,t=0,o=!1){const r=[[n.x,n.y]],l=[],a=R(n.spatialReference);let s=b(e);if(-1===s)return console.warn(`invalid conversionMode: ${e}`),null;o&&(s|=i.PE_MGRS_ADD_SPACES);return i.geogToMgrsExtended(a,1,r,t,!1,s,l)?l[0]:null}function M(n,e=0,t=!1){const o=[[n.x,n.y]],r=[],i=R(n.spatialReference);return l.geogToUsng(i,1,o,e,!1,t,r)?r[0]:null}function v(n,e,t=!1){const o=[[n.x,n.y]],r=[],i=R(n.spatialReference);let l=A(e);if(-1===l)return console.warn(`invalid conversionMode: ${e}`),null;t&&(l|=a.PE_UTM_OPTS_ADD_SPACES);return a.geogToUtm(i,1,o,l,r)?r[0]:null}function R(e){let t=null;if(e||(e=d.WGS84),e.wkid){if(t=s.geogcs(e.wkid),!t)throw new n("coordinate-formatter:invalid-spatial-reference","wkid is not valid")}else{if(!e.wkt2&&!e.wkt)throw new n("coordinate-formatter:invalid-spatial-reference","wkid and wkt are missing");if(t=s.fromString(c.PE_TYPE_GEOGCS,e.wkt2||e.wkt),!t)throw new n("coordinate-formatter:invalid-spatial-reference","wkt is not valid")}return t}function b(n){let e=-1;switch(n){case"automatic":e=i.PE_MGRS_STYLE_AUTO;break;case"new-180-in-zone-01":e=i.PE_MGRS_STYLE_NEW|i.PE_MGRS_180_ZONE_1_PLUS;break;case"new-180-in-zone-60":e=i.PE_MGRS_STYLE_NEW;break;case"old-180-in-zone-01":e=i.PE_MGRS_STYLE_OLD|i.PE_MGRS_180_ZONE_1_PLUS;break;case"old-180-in-zone-60":e=i.PE_MGRS_STYLE_OLD}return e}function A(n){let e=-1;switch(n){case"latitude-band-indicators":e=a.PE_UTM_OPTS_NONE;break;case"north-south-indicators":e=a.PE_UTM_OPTS_NS}return e}export{m as fromLatitude,E as fromLatitudeLongitude,g as fromLongitude,T as fromMgrs,P as fromUsng,G as fromUtm,_ as isLoaded,S as isSupported,w as load,k as toLatitudeLongitude,p as toMgrs,M as toUsng,v as toUtm};