UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 1.43 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{getMetersPerUnitForSR as e}from"../../../core/units.js";import{isSupported as t,geodesicLengths as r}from"../../../geometry/geodesicUtils.js";import o from"../../../geometry/Point.js";import n from"../../../geometry/Polyline.js";import s from"../../../geometry/SpatialReference.js";import{straightLineDensify as i}from"../../../geometry/support/normalizeUtils.js";import{isValid as m}from"../../../geometry/support/spatialReferenceUtils.js";import{webMercatorToGeographic as c}from"../../../geometry/support/webMercatorUtils.js";import{pixelsPerCell as p}from"./constants.js";function a(e,t){return Math.log(e)/Math.log(t)}function l(e,t,r){const o=1===e?10:e;return o**(r?Math.round(a(p/t,o)):0)}function f(e){const{isGeographic:t,isWebMercator:r}=e;return!t&&!r}function u(p,a,l){const u="number"==typeof p?null:p,y=l??u?.spatialReference;if(null==y||!m(y)||f(y))return e(y);let g=u?.x??p,j=u?.y??a;const h=1/Math.sqrt(2);let M=g+h,x=j+h;const{isWebMercator:R,isGeographic:b}=y;let w=b&&!t(y)?s.WGS84:y;if(R){let e=new o({x:g,y:j,spatialReference:y});c(e,!0,e),g=e.x,j=e.y,e=new o({x:M,y:x,spatialReference:y}),c(e,!0,e),M=e.x,x=e.y,w=s.WGS84}const G=new n({paths:[[[g,j],[M,x]]],spatialReference:w}),U=i(G,10);let W;try{[W]=r([U],"meters")}catch{return e(y)}return W}export{l as getScaleFactor,u as measureMetersPerUnitAtReferencePoint,f as shouldUsePlanar};