@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.59 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{isSome as s}from"../../../core/arrayUtils.js";import{createResolver as t}from"../../../core/promiseUtils.js";import{initializeProjection as e,projectMany as n}from"../../../geometry/projectionUtils.js";import{jsonAdapter as r}from"../../../geometry/geometryAdapters/json.js";import{isValid as i,equals as o,isWebMercator as a}from"../../../geometry/support/spatialReferenceUtils.js";import{canProject as m,lngLatToXY as u,xyToLngLat as l}from"../../../geometry/support/webMercatorUtils.js";const p=[0,0];function c(s,t){if(!t)return null;if("x"in t){const e={x:0,y:0};return[e.x,e.y]=s(t.x,t.y,p),null!=t.z&&(e.z=t.z),null!=t.m&&(e.m=t.m),e}if("xmin"in t){const e={xmin:0,ymin:0,xmax:0,ymax:0};return[e.xmin,e.ymin]=s(t.xmin,t.ymin,p),[e.xmax,e.ymax]=s(t.xmax,t.ymax,p),t.hasZ&&(e.zmin=t.zmin,e.zmax=t.zmax,e.hasZ=!0),t.hasM&&(e.mmin=t.mmin,e.mmax=t.mmax,e.hasM=!0),e}return"rings"in t?{rings:h(t.rings,s),hasM:t.hasM,hasZ:t.hasZ}:"paths"in t?{paths:h(t.paths,s),hasM:t.hasM,hasZ:t.hasZ}:"points"in t?{points:f(t.points,s),hasM:t.hasM,hasZ:t.hasZ}:null}function h(s,t){const e=[];for(const n of s)e.push(f(n,t));return e}function f(s,t){const e=[];for(const n of s){const s=t(n[0],n[1],[0,0]);e.push(s),n.length>2&&s.push(n[2]),n.length>3&&s.push(n[3])}return e}async function x(t,n){if(!t||!n)return;const r=Array.isArray(t)?t.map((s=>null!=s.geometry?s.geometry.spatialReference:null)).filter(s):[t];await e(r.map((s=>({source:s,dest:n}))))}const y=c.bind(null,u),g=c.bind(null,l);function j(s,t,e,u){if(!s)return null;if(e||(e=t,t=s.spatialReference),!i(t)||!i(e)||o(t,e))return s;if(m(t,e)){const t=a(e)?y(s):g(s);return t.spatialReference=e,t}return n(r,[s],t,e,null,u)[0]}class _{constructor(){this._jobs=[],this._timer=null,this._process=this._process.bind(this)}async push(s,e,n,r){if(!s?.length||!e||!n||o(e,n))return s;const i={geometries:s,inSpatialReference:e,outSpatialReference:n,geographicTransformation:r,resolve:t()};return this._jobs.push(i),this._timer??=setTimeout(this._process,10),i.resolve.promise}_process(){this._timer=null;const s=this._jobs.shift();if(!s)return;const{geometries:t,inSpatialReference:e,outSpatialReference:i,resolve:o,geographicTransformation:u}=s;m(e,i)?a(i)?o(t.map(y)):o(t.map(g)):o(n(r,t,e,i,u,null)),this._jobs.length>0&&(this._timer=setTimeout(this._process,10))}}const M=new _;function b(s,t,e,n){return M.push(s,t,e,n)}export{x as checkProjectionSupport,j as project,b as projectMany};