@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 1.53 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{getMetersPerUnitForSR as e}from"../../../core/unitUtils.js";import t from"../../../geometry/Point.js";import r from"../../../geometry/Polyline.js";import o from"../../../geometry/SpatialReference.js";import{isSupported as n,geodesicLengths as s}from"../../../geometry/support/geodesicUtils.js";import{straightLineDensify as i}from"../../../geometry/support/normalizeUtils.js";import{isValid as m}from"../../../geometry/support/spatialReferenceUtils.js";import{webMercatorToGeographic as p}from"../../../geometry/support/webMercatorUtils.js";import{pixelsPerCell as c}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(c/t,o)):0)}function f(e){const{isGeographic:t,isWebMercator:r}=e;return!t&&!r}function u(c,a,l){const u="number"==typeof c?null:c,y=l??u?.spatialReference;if(null==y||!m(y)||f(y))return e(y);let g=u?.x??c,j=u?.y??a;const h=1/Math.sqrt(2);let M=g+h,x=j+h;const{isWebMercator:R,isGeographic:U}=y;let b=U&&!n(y)?o.WGS84:y;if(R){let e=new t({x:g,y:j,spatialReference:y});p(e,!0,e),g=e.x,j=e.y,e=new t({x:M,y:x,spatialReference:y}),p(e,!0,e),M=e.x,x=e.y,b=o.WGS84}const w=new r({paths:[[[g,j],[M,x]]],spatialReference:b}),G=i(w,10);let W;try{[W]=s([G],"meters")}catch{return e(y)}return W}export{l as getScaleFactor,u as measureMetersPerUnitAtReferencePoint,f as shouldUsePlanar};