@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.5 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{Cyclical as t}from"../../../../core/Cyclical.js";import{formatArea as n,formatLength as e,formatRelativeLength as r,formatVerticalLength as i,formatRelativeVerticalLength as o,formatAngle as l}from"../../../../core/quantityFormatUtils.js";import{toUnit as u,createScalar as a,createAngle as c}from"../../../../core/quantityUtils.js";import{isLoaded as s,fromLatitudeLongitude as f,fromLongitude as g,fromLatitude as m}from"../../../../geometry/coordinateFormatter.js";import{formatNumber as p,parseNumber as d}from"../../../../intl/number.js";import{getDegreesGeographic as h}from"../../../support/angularMeasurementUtils.js";const v=1,y=6;function D(t,l){return{angleRelative:x,direction:j,directionRelative:R,directionRelativeBilateral:$,latitudeDecimalDegrees:L,longitudeDecimalDegrees:F,area:(e,r)=>n(t,e,r??l.area),length:(n,r,i)=>e(t,n,r??l.length,i),lengthRelative:(n,e)=>r(t,n,e??l.length),totalLength:(n,r)=>e(t,n,r??l.length),verticalLength:(n,e)=>i(t,n,e??l.verticalLength),verticalLengthRelative:(n,e)=>o(t,n,e??l.verticalLength),percentage:z,scalar:Z,scale:T}}function x(t){return p(t,{signDisplay:"exceptZero",...b(v)})}function j(t){return l(t,t.rotationType,v)}function R(t){const n=h(t);return p(n,{style:"unit",unitDisplay:"narrow",unit:"degree",signDisplay:n>0?"never":"exceptZero",...b(v)})}function $(t){return l(t,t.rotationType,v)}function F(t){return U(t,N)}function L(t){return U(t,O)}function w(t){return q(t,N)}function A(t){return q(t,O)}function U(t,n){const e=!1,r="geographic";return l(u(t,"degrees"),r,y,n,e)}function q(t,n){const e=!1,r=n.normalize(u(t,"degrees").value,void 0,e);return Z(a(r),y)}function z(t){return p(t.value,{style:"percent"})}function T(t){return p(t,{style:"percent",maximumFractionDigits:0})}function Z(t,n){return p(t.value,b(n))}function b(t){return{minimumFractionDigits:t,maximumFractionDigits:t}}function B({createQuantity:t,sanitize:n}){return(e,r)=>{if(null==e)return null;n&&(e=n(e));const i=d(e);return null==i?null:t(i,r)}}function C(t){return t.replaceAll(/[*^~°º]/g,"")}const E=t=>{let n=`[-+]?[0-9${t.thousands}]+`;return""!==t.decimal&&(n+=`${t.decimal}[0-9]+`),new RegExp(`^(${n}\\s*)${t.separator}(\\s*${n})$`,"i")},I=" ",M=[];for(const P of[",","\\|","\\s+"])for(const t of["\\.",",",""])for(const n of["",",","\\.",I,"\\s+"])P!==t&&P!==n&&t!==n&&M.push({separator:P,decimal:t,thousands:n,pattern:E({decimal:t,thousands:n,separator:P})});function Q(t){for(const{decimal:n,thousands:e,pattern:r}of M){r.lastIndex=0;const i=t.match(r);if(!i)continue;const o=d(k(i[1],n,e)),l=d(k(i[2],n,e));if(null!=o&&null!=l)return{x:a(o),y:a(l)}}return null}function k(t,n,e){let r=t.replaceAll(/[\s+]/g,"");return""!==e&&(r=r.replaceAll(e,"")),""!==n&&(r=r.replaceAll(n,".")),r}function G(t){if(!t||null!=d(t)||!s())return null;const n=f(t),e=K(n?.latitude),r=K(n?.longitude);return null!=r&&null!=e?{latitude:e,longitude:r}:null}function H(t){return K(g(t))}function J(t){return K(m(t))}function K(t){return null!=t?c(t,"degrees","geographic"):null}const N=new t(-180,180),O=new t(-90,90);export{k as cleanNumber,K as createGeographicCoordinate,A as formatLatitudeDecimalDegreesForInputMode,w as formatLongitudeDecimalDegreesForInputMode,D as getFormatters,B as makeQuantityParser,J as parseLatitude,G as parseLatitudeLongitude,H as parseLongitude,Q as parseXY,C as sanitizeAngle};