@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 20.3 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{isSome as e}from"../../../core/arrayUtils.js";import t from"../../../core/Error.js";import{createResolver as n}from"../../../core/promiseUtils.js";import{getMetersPerUnitForSR as i}from"../../../core/units.js";import o from"../../../geometry/Extent.js";import{P as r,a as s,g as a,h as l,j as c}from"../../../chunks/pe.js";import f from"../../../geometry/Point.js";import u from"../../../geometry/Polygon.js";import{projectWithoutEngine as x}from"../../../geometry/projectionUtils.js";import m from"../../../geometry/SpatialReference.js";import{getInfo as h}from"../../../geometry/support/spatialReferenceUtils.js";function p(){if(!N)throw new t("rasterprojectionhelper-project","projection operator is not loaded")}const g=(e,t,n,i=0)=>{if(1===n[0])return[0,0];let o=1,r=-1,s=1,a=-1;for(let g=0;g<e.length;g+=2)isNaN(e[g])||(o=o>e[g]?e[g]:o,r=r>e[g]?r:e[g],s=s>e[g+1]?e[g+1]:s,a=a>e[g+1]?a:e[g+1]);const{cols:l,rows:c}=t,f=(r-o)/l/n[0],u=(a-s)/c/n[1],x=2*i;let m=0,h=!1,p=[0,0];for(let g=0;g<l-3;g++){for(let t=0;t<c-3;t++){const n=g*c*2+2*t,i=(e[n]+e[n+4]+e[n+4*c]+e[n+4*c+4])/4,o=(e[n+1]+e[n+5]+e[n+4*c+1]+e[n+4*c+5])/4,r=Math.abs((i-e[n+2*c+2])/f),s=Math.abs((o-e[n+2*c+3])/u);if(r+s>m&&(m=r+s,p=[r,s]),x&&m>x){h=!0;break}}if(h)break}return p},y={3395:20037508.342789244,3410:17334193.943686873,3857:20037508.342788905,3975:17367530.445161372,4087:20037508.342789244,4088:20015108.787169147,6933:17367530.445161372,32662:20037508.342789244,53001:20015086.79602057,53002:10007543.39801029,53003:20015086.79602057,53004:20015086.79602057,53016:14152803.599503474,53017:17333573.624304302,53034:20015086.79602057,53079:20015114.352186374,53080:20015114.352186374,54001:20037508.342789244,54002:10018754.171394624,54003:20037508.342789244,54004:20037508.342789244,54016:14168658.027268292,54017:17367530.44516137,54034:20037508.342789244,54079:20037508.342789244,54080:20037508.342789244,54100:20037508.342789244,54101:20037508.342789244},d=32,w=4,M=w,R=new Map,S=new Map,P=500,b=39.37,G=96;let k,E,T,N=!1;async function j(){return k||(k=n(),E=await import("../../../geometry/operators/projectOperator.js"),T=await import("../../../geometry/operators/support/geographicTransformationUtils.js"),E.isLoaded()||await E.load(),T.isLoaded()||await T.load(),N=!0,k.resolve()),k.promise}function v(e,t,n){if(p(),n){const n=E.execute(e,t);return T.getTransformation(t,e.spatialReference,n)}return T.getTransformation(e.spatialReference,t,e)}function C(e,t,n,i){const r=e.spatialReference;if(!r||!t||r.equals(t))return e;p();const s=n.center,a=new o({xmin:s.x-e.x/2,xmax:s.x+e.x/2,ymin:s.y-e.y/2,ymax:s.y+e.y/2,spatialReference:r}),l=E.execute(a,t,{geographicTransformation:i}),c=$(t);return null==l||null!=c&&l.width>=c?_(e,r,t):{x:l.width,y:l.height}}function _(e,t,n){const o=i(t)/i(n);return{x:e.x*o,y:e.y*o}}function z(e,n,o){const{spatialReference:r}=o;if(!r||!n||r.equals(n))return e;if(r.isGeographic&&n.isGeographic)return _(e,r,n);if(p(),!N)throw new t("raster-projection-helper:project-dataset-resolution","geometry engine is not loaded");let{x:s,y:a}=e;const l=(s+a)/2*i(r);let c=1;l>30&&(c=30/l,s*=c,a*=c);const f=256,x=s*f/2,m=a*f/2,{x:h,y:g}=o.center,y=[];for(let t=0;t<=f;t++)y.push([h-x,g-m+t*a]);for(let t=1;t<=f;t++)y.push([h-x+t*s,g+m]);for(let t=1;t<=f;t++)y.push([h+x,g+m-t*a]);for(let t=1;t<f;t++)y.push([h+x-t*s,g-m]);y.push(y[0]);const d=new u({rings:[y],spatialReference:r}),w=E.execute(d,n);if(!w)return _(e,r,n);const M=w.extent,R=$(n);if(null==M||null!=R&&M.width>=R)return _(e,r,n);const S=pe(w.rings),P=s*a*f*f,b=Math.sqrt(S/P)/c,G={x:M.width/c/f,y:M.height/c/f},k={x:s*b,y:a*b},T=G.x*G.y;return Math.abs(T-k.x*k.y)/T<.1?G:k}function L(e,t){return("number"==typeof e?e:(e.x+e.y)/2)*i(t)*G*b}function W(e,t){const{pixelSize:n,extent:i}=e;return L(z(n,t,i),t)}function I(e,t=.01){return i(e)?t/i(e):0}function O(e,t,n,i=!0){const o=e.spatialReference;if(o.equals(t))return e;p();const r=E.execute(e,t,{geographicTransformation:n});return i&&r?(A([e],[r],o,t),r):r}function A(e,t,n,i){const o=ee(n,!0),r=ee(i,!0),s=I(n,P),a=I(i,P);if(s&&null!=o&&null!=r)for(let l=0;l<e.length;l++){const n=t[l];if(!n)continue;const{x:i}=e[l],{x:c}=n;c>=r[1]-a&&Math.abs(i-o[0])<s?n.x-=r[1]-r[0]:c<=r[0]+a&&Math.abs(i-o[1])<s&&(n.x+=r[1]-r[0])}}function F(e){const{inSR:t,outSR:n,preferPE:i}=e;if(t.equals(n)){const{points:t}=X(e,null);return t}if(t.isWebMercator&&n.isWGS84||t.isWGS84&&n.isWebMercator)return B(e);if(i){if(t.isGeographic)return Y(e);if(null!=U(t))return Y(e)}return q(e)}function q(e){const{points:t}=X(e,null),{inSR:n,outSR:i,datumTransformation:o}=e,r=t.map(e=>new f(e[0],e[1],n)),s=E.executeMany(r,i,{geographicTransformation:o});return o&&A(r,s,n,i),s.map(e=>e?[e.x,e.y]:[NaN,NaN])}function Y(e){const{inSR:t,outSR:n,datumTransformation:i}=e,o=U(t),{points:a,mask:f}=X(e,o);if(!t.isGeographic){const e=t.wkid?r.coordsys(t.wkid):r.fromString(t.isGeographic?s.PE_TYPE_GEOGCS:s.PE_TYPE_PROJCS,t.wkt2||t.wkt);l.projToGeog(e,a.length,a)}if(null!=i&&i.steps.length){let e;const t=179.9955;if(n.isGeographic&&(e=a.map(([e])=>e>t?1:e<-t?-1:0)),i.steps.forEach(e=>{const t=e.wkid?r.geogtran(e.wkid):r.fromString(s.PE_TYPE_GEOGTRAN,e.wkt);c.geogToGeog(t,a.length,a,null,e.isInverse?s.PE_TRANSFORM_2_TO_1:s.PE_TRANSFORM_1_TO_2)}),e)for(let n=0;n<a.length;n++){const i=e[n],o=a[n][0],r=o>t?1:o<-t?-1:0;i&&r&&i!==r&&(a[n][0]=i>0?o+360:o-360)}}if(!n.isGeographic){const e=U(n,!0),t=null!=e&&e.isEnvelope?[e.bbox[1],e.bbox[3]]:[-90,90];K(a,t);const i=n.wkid?r.coordsys(n.wkid):r.fromString(n.isGeographic?s.PE_TYPE_GEOGCS:s.PE_TYPE_PROJCS,n.wkt2||n.wkt);l.geogToProj(i,a.length,a)}let u=a;if(f&&a.length!==f.length){u=[];for(let e=0,t=0;e<f.length;e++)f[e]?u.push(a[t++]):u.push([NaN,NaN])}return u}function B(e){const{cols:t,rows:n,xres:i,yres:o,usePixelCenter:r,inSR:s,outSR:a}=e;let{xmin:l,ymax:c}=e;r&&(l+=i/2,c-=o/2);const u=[],m=[],h=Math.max(t,n);for(let g=0;g<h;g++){const e=l+i*Math.min(t,g),r=c-o*Math.min(n,g),h=x(new f({x:e,y:r,spatialReference:s}),s,a);g<=t&&u.push(h.x),g<=n&&m.push(h.y)}const p=[];for(let f=0;f<t;f++)for(let e=0;e<n;e++)p.push([u[f],m[e]]);return p}function U(e,t=!1){let n=e.wkid||e.wkt2||e.wkt;if(!n||e.isGeographic)return null;if(n=String(n),R.has(n)){const e=R.get(n);return t?e?.gcs:e?.pcs}const i=e.wkid?r.coordsys(e.wkid):r.fromString(e.isGeographic?s.PE_TYPE_GEOGCS:s.PE_TYPE_PROJCS,e.wkt2||e.wkt),o=J(i,I(e,1e-4)),a=J(i,0,!0);return R.set(n,{pcs:o,gcs:a}),t?a:o}function J(e,t=0,n=!1){const i=a.generate(e),o=n?e.horizonGcsGenerate():e.horizonPcsGenerate();if(!i||!o?.length)return null;let r=!1,s=o.find(e=>1===e.getInclusive()&&1===e.getKind());if(!s){if(s=o.find(e=>1===e.getInclusive()&&0===e.getKind()),!s)return null;r=!0}const l=n?0:(2===i.getNorthPoleLocation()?1:0)|(2===i.getSouthPoleLocation()?2:0),c=i.isPannableRectangle(),f=s.getCoord();if(r)return{isEnvelope:r,isPannable:c,vertices:f,coef:null,bbox:[f[0][0]-t,f[0][1]-t,f[1][0]+t,f[1][1]+t],poleLocation:l};let u=0;const x=[];let[m,h]=f[0],[p,g]=f[0];for(let a=0,y=f.length;a<y;a++){u++,u===y&&(u=0);const[e,t]=f[a],[n,i]=f[u];if(i===t)x.push([e,n,t,i,2]);else{const o=(n-e)/(i-t||1e-4),r=e-o*t;t<i?x.push([o,r,t,i,0]):x.push([o,r,i,t,1])}m=m<e?m:e,h=h<t?h:t,p=p>e?p:e,g=g>t?g:t}return{isEnvelope:!1,isPannable:c,vertices:f,coef:x,bbox:[m,h,p,g],poleLocation:l}}function X(e,t){const n=[],{cols:i,rows:o,xres:r,yres:s,usePixelCenter:a}=e;let{xmin:l,ymax:c}=e;if(a&&(l+=r/2,c-=s/2),null==t){for(let e=0;e<i;e++)for(let t=0;t<o;t++)n.push([l+r*e,c-s*t]);return{points:n}}const f=new Uint8Array(i*o);if(t.isEnvelope){const{isPannable:e,bbox:[a,u,x,m]}=t;for(let t=0,h=0;t<i;t++){const i=l+r*t,p=e||i>=a&&i<=x;for(let e=0;e<o;e++,h++){const t=c-s*e;p&&t>=u&&t<=m&&(n.push([i,t]),f[h]=1)}}return{points:n,mask:f}}const u=t.coef,x=[];for(let m=0;m<o;m++){const e=c-s*m,t=[],n=[];for(let o=0;o<u.length;o++){const[i,r,s,a,l]=u[o];if(e===s&&s===a)t.push(i),t.push(r),n.push(2),n.push(2);else if(e>=s&&e<=a){const o=i*e+r;t.push(o),n.push(l)}}let i=t;if(t.length>2){let e=2===n[0]?0:n[0],o=t[0];i=[];for(let r=1;r<n.length;r++)2===n[r]&&r!==n.length-1||(n[r]!==e&&(i.push(0===e?Math.min(o,t[r-1]):Math.max(o,t[r-1])),e=n[r],o=t[r]),r===n.length-1&&i.push(0===n[r]?Math.min(o,t[r]):Math.max(o,t[r])));i.sort((e,t)=>e-t)}else t[0]>t[1]&&(i=[t[1],t[0]]);x.push(i)}for(let m=0,h=0;m<i;m++){const e=l+r*m;for(let t=0;t<o;t++,h++){const i=c-s*t,o=x[t];if(2===o.length)e>=o[0]&&e<=o[1]&&(n.push([e,i]),f[h]=1);else if(o.length>2){let t=!1;for(let n=0;n<o.length;n+=2)if(e>=o[n]&&e<=o[n+1]){t=!0;break}t&&(n.push([e,i]),f[h]=1)}}}return{points:n,mask:f}}function K(e,t){const[n,i]=t;for(let o=0;o<e.length;o++){const t=e[o][1];(t<n||t>i)&&(e[o]=[NaN,NaN])}}function D(e,t){const n=$(e[0].spatialReference);if(e.length<2||null==n)return e[0];if(t=t??I(e[0].spatialReference),1===(e=e.filter(e=>e.width>t)).length)return e[0];let{xmin:i,xmax:r,ymin:s,ymax:a}=e[0];for(let o=1;o<e.length;o++){const t=e[o];r=t.xmax+n*o,s=Math.min(s,t.ymin),a=Math.max(a,t.ymax)}return new o({xmin:i,xmax:r,ymin:s,ymax:a,spatialReference:e[0].spatialReference})}function H(t,n,i=null,r=!0){const s=t.spatialReference;if(s.equals(n)||!n)return t;const a=ne(t),l=$(s,!0),c=$(n);if(0===a||null==l||null==c){const e=Z(t,n,i,r);if(e&&null==l&&null!=c&&Math.abs(e.width-c)<I(n)&&E.isLoaded()){const i=U(s);if(null!=i&&0===i.poleLocation&&t.width<(i.bbox[2]-i.bbox[0])/2)return V(t,n)||e}return e}const f=t.clone().normalize();if(1===f.length&&t.xmax<l&&t.xmax-l/2>I(s)){const{xmin:e,xmax:n}=t;for(let i=0;i<=a;i++){const r=0===i?e:-l/2,c=i===a?n-l*i:l/2;f[i]=new o({xmin:r,xmax:c,ymin:t.ymin,ymax:t.ymax,spatialReference:s})}}const u=f.map(e=>Z(e,n,i,r)).filter(e);return 0===u.length?null:D(u)}function Q(e,t,n){if("extent"===e.type){const{xmin:t,ymin:n,xmax:i,ymax:o,spatialReference:r}=e;e=new u({rings:[[[t,o],[i,o],[i,n],[t,n],[t,o]]],spatialReference:r})}return e.spatialReference.equals(t)?e:(p(),E.execute(e,t,{geographicTransformation:n}))}function V(e,t){const n=$(t);if(null==n)return null;let{xmin:i,ymin:r,xmax:s,ymax:a}=e;const l=e.spatialReference,c=new u({spatialReference:l,rings:[[[i,r],[s,r],[s,a],[i,a],[i,r]]]}),f=E.execute(c,t);if(2!==f.rings.length||!f.rings[0].length||!f.rings[1].length)return null;const{rings:x}=f,m=I(l),h=new o({spatialReference:t});for(let o=0;o<2;o++){i=s=x[o][0][0],r=a=x[o][0][1];for(let e=0;e<x[o].length;e++)i=i>x[o][e][0]?x[o][e][0]:i,s=s<x[o][e][0]?x[o][e][0]:s,r=r>x[o][e][1]?x[o][e][1]:r,a=a<x[o][e][1]?x[o][e][1]:a;if(0===o)h.ymin=r,h.ymax=a,h.xmin=i,h.xmax=s;else if(h.ymin=Math.min(h.ymin,r),h.ymax=Math.max(h.ymax,a),Math.abs(s-n/2)<m)h.xmin=i,h.xmax=h.xmax+n;else{if(!(Math.abs(i+n/2)<m))return null;h.xmax=s+n}}return h}function Z(e,t,n,i=!0,o=!0){const r=e.spatialReference;if(r.equals(t)||!t)return e;p();const s=E.execute(e,t,{geographicTransformation:n});if(o&&t.isWebMercator&&s&&(s.ymax=Math.min(20037508.342787,s.ymax),s.ymin=Math.max(-20037508.342787,s.ymin),s.ymin>=s.ymax))return null;if(!i||!s)return s;const a=ee(r,!0),l=ee(t,!0);if(null==a||null==l)return s;const c=I(r,.001),u=I(r,P),x=I(t,.001);if(Math.abs(s.xmin-l[0])<x&&Math.abs(s.xmax-l[1])<x){const i=Math.abs(e.xmin-a[0]),o=Math.abs(a[1]-e.xmax);if(i<c&&o>u){s.xmin=l[0];const i=[];i.push(new f(e.xmax,e.ymin,r)),i.push(new f(e.xmax,(e.ymin+e.ymax)/2,r)),i.push(new f(e.xmax,e.ymax,r));const o=i.map(e=>O(e,t,n)).filter(e=>!isNaN(e?.x)).map(e=>e.x);s.xmax=Math.max.apply(null,o)}if(o<c&&i>u){s.xmax=l[1];const i=[];i.push(new f(e.xmin,e.ymin,r)),i.push(new f(e.xmin,(e.ymin+e.ymax)/2,r)),i.push(new f(e.xmin,e.ymax,r));const o=i.map(e=>O(e,t,n)).filter(e=>!isNaN(e?.x)).map(e=>e.x);s.xmin=Math.min.apply(null,o)}}else{const e=I(t,.001);Math.abs(s.xmin-l[0])<e&&(s.xmin=l[0]),Math.abs(s.xmax-l[1])<e&&(s.xmax=l[1])}return s}function $(e,t=!1){if(!e)return null;const n=t?20037508.342787:20037508.342788905;return e.isWebMercator?2*n:e.wkid&&e.isGeographic?360:2*y[e.wkid]||null}function ee(e,t=!1){if(e.isGeographic)return[-180,180];const n=$(e,t);return n?[-n/2,n/2]:null}function te(e,t,n,i){let o=(e-t)/n;return o-Math.floor(o)!==0?o=Math.floor(o):i&&(o-=1),o}function ne(e,t=!1){const n=$(e.spatialReference);if(null==n)return 0;const i=t?0:-(n/2),o=I(e.spatialReference),r=!t&&Math.abs(e.xmax-n/2)<o?n/2:e.xmax,s=!t&&Math.abs(e.xmin+n/2)<o?-n/2:e.xmin;return te(r,i,n,!0)-te(s,i,n,!1)}function ie(e){const t=e.storageInfo.origin.x,n=$(e.spatialReference,!0);if(null==n)return{originX:t,halfWorldWidth:null,pyramidsInfo:null};const i=n/2,{nativePixelSize:o,storageInfo:r,extent:s}=e,{maximumPyramidLevel:a,blockWidth:l,pyramidScalingFactor:c}=r;let f=o.x;const u=[],x=null!=e.transform&&"gcs-shift"===e.transform.type,m=t+(x?0:i),h=x?n-t:i-t;for(let p=0;p<=a;p++){const e=(s.xmax-t)/f/l,n=e-Math.floor(e)===0?e:Math.ceil(e),i=h/f/l,o=i-Math.floor(i)===0?i:Math.ceil(i),r=Math.floor(m/f/l),a=Math.round(m/f)%l,x=(l-Math.round(h/f)%l)%l;u.push({resolutionX:f,blockWidth:l,datasetColumnCount:n,worldColumnCountFromOrigin:o,leftMargin:a,rightPadding:x,originColumnOffset:r}),f*=c}return{originX:t,halfWorldWidth:i,pyramidsInfo:u,hasGCSSShiftTransform:x}}function oe(e){if(!e||e.isGeographic)return e;const t=String(e.wkid||e.wkt2||e.wkt);let n;if(S.has(t))n=S.get(t);else{n=(e.wkid?r.coordsys(e.wkid):r.fromString(s.PE_TYPE_PROJCS,e.wkt2||e.wkt)).getGeogcs().getCode(),S.set(t,n)}return new m({wkid:n})}function re(e){const t=e.isAdaptive&&null==e.spacing;let n=e.spacing||[d,d],i=se(e),o={cols:i.size[0]+1,rows:i.size[1]+1};const r=i.outofBoundPointCount>0&&i.outofBoundPointCount<i.offsets.length/2;let s=i.outofBoundPointCount===i.offsets.length/2||t&&r?[0,0]:g(i.offsets,o,n,M);const a=(s[0]+s[1])/2,l=e.projectedExtent.spatialReference,c=e.srcBufferExtent.spatialReference;if(t&&(r||a>M)&&(l.isGeographic||U(l),n=[w,w],i=se({...e,spacing:n}),o={cols:i.size[0]+1,rows:i.size[1]+1},s=g(i.offsets,o,n,M)),i.error=s,n[0]>1&&(i.coefficients=ae(i.offsets,o,r)),e.includeGCSGrid&&!l.isGeographic&&!l.isWebMercator)if(c.isGeographic)i.gcsGrid={offsets:i.offsets,coefficients:i.coefficients,spacing:n};else{const t=U(l);if(null!=t&&!t.isEnvelope){const t=oe(l),s=H(e.projectedExtent,t),{offsets:a}=se({...e,srcBufferExtent:s,spacing:n}),c=ae(a,o,r);i.gcsGrid={offsets:a,coefficients:c,spacing:n}}}return i}function se(e){const{projectedExtent:t,srcBufferExtent:n,pixelSize:i,datumTransformation:o,rasterTransform:r}=e,s=t.spatialReference,a=n.spatialReference;p();const{xmin:l,ymin:c,xmax:u,ymax:x}=t,m=$(a),h=null!=m&&(e.hasWrapAround||"gcs-shift"===r?.type),g=e.spacing||[d,d],y=g[0]*i.x,M=g[1]*i.y,R=1===g[0],S=Math.ceil((u-l)/y-.1/g[0])+(R?0:1),b=Math.ceil((x-c)/M-.1/g[1])+(R?0:1),G=F({cols:S,rows:b,xmin:l,ymax:x,xres:y,yres:M,inSR:s,outSR:a,datumTransformation:o,preferPE:g[0]<=w,usePixelCenter:R}),k=[];let E,T=0;const N=R?-1:NaN,{xmin:j,xmax:v,ymax:C,width:_,height:z}=n,L=I(a,P),W=null!=m&&j>0&&v>m/2,O=U(s),A=null!=O&&O.poleLocation>0;for(let p=0;p<S;p++){const e=[];for(let t=0;t<b;t++){let n=G[p*b+t];if(h&&n[0]>v&&n[0]>m/2-L?n[0]-=m:h&&0===p&&n[0]<0&&W&&!r&&(n[0]+=m),!n||isNaN(n[0])||isNaN(n[1]))k.push(N),k.push(N),e.push(null),T++;else{if(r){const e=r.inverseTransform(new f({x:n[0],y:n[1],spatialReference:a}));n=[e.x,e.y]}e.push(n),p>0&&h&&E[t]&&n[0]<E[t][0]&&(n[0]+=m,A&&n[0]>v&&n[0]>m&&(n[0]-=m)),k.push((n[0]-j)/_),k.push((C-n[1])/z)}}E=e}return{offsets:k,error:null,coefficients:null,outofBoundPointCount:T,spacing:g,size:R?[S,b]:[S-1,b-1]}}function ae(e,t,n){const{cols:i,rows:o}=t,r=new Float32Array((i-1)*(o-1)*2*6),s=new Float32Array([-0,-1,1,-1,1,-0,1,-0,-0]),a=new Float32Array([-1,1,0,0,-1,1,1,0,0]);for(let l=0;l<i-1;l++){for(let t=0;t<o-1;t++){let n=l*o*2+2*t;const c=e[n],f=e[n+1],u=e[n+2],x=e[n+3];n+=2*o;const m=e[n],h=e[n+1],p=e[n+2],g=e[n+3];let y=0,d=12*(t*(i-1)+l);for(let e=0;e<3;e++)r[d++]=s[y++]*c+s[y++]*u+s[y++]*p;y=0;for(let e=0;e<3;e++)r[d++]=s[y++]*f+s[y++]*x+s[y++]*g;y=0;for(let e=0;e<3;e++)r[d++]=a[y++]*c+a[y++]*m+a[y++]*p;y=0;for(let e=0;e<3;e++)r[d++]=a[y++]*f+a[y++]*h+a[y++]*g}if(n)for(let e=0;e<r.length;e++)isNaN(r[e])&&(r[e]=-1)}return r}function le(e,t){const n=e.clone().normalize();return 1===n.length?n[0]:D(n,t)}function ce(e){const{spatialReference:t}=e,n=h(t);if(!n)return e;const[i,r]=n.valid,s=r-i;let a=0;if(e.xmin<i){const t=i-e.xmin;a=Math.ceil(t/s)}else if(e.xmin>r){const t=e.xmin-r;a=-Math.ceil(t/s)}return new o({spatialReference:e.spatialReference,xmin:e.xmin+a*s,ymin:e.ymin,xmax:e.xmax+a*s,ymax:e.ymax})}function fe(e,t,n){const{storageInfo:o,pixelSize:r}=t;let s=0,a=!1;const{pyramidResolutions:l}=o,c="mixed"===o.tileInfo.format?.toLowerCase()?Math.max(1,Math.min(3,o.tileInfo.dpi/96)):1,u=(e.x+e.y)/2/c;if(null!=l&&l.length){const e=l[l.length-1],o=(e.x+e.y)/2,c=(r.x+r.y)/2;if(u<=c)s=0;else if(u>=o)s=l.length,a=u/o>8;else{let e,t=c;for(let i=1;i<=l.length;i++){if(e=(l[i-1].x+l[i-1].y)/2,u<=e){u===e?s=i:"down"===n?(s=i-1,a=u/t>8):s="up"===n||u-t>e-u||u/t>2?i:i-1;break}t=e}}const x=0===s?r:l[s-1];if(a){Math.min(x.x,x.y)*i(t.spatialReference)>19567&&(a=!1)}return{pyramidLevel:s,pyramidResolution:new f({x:x.x,y:x.y,spatialReference:t.spatialReference}),excessiveReading:a}}const x=Math.log(e.x/r.x)/Math.LN2,m=Math.log(e.y/r.y)/Math.LN2,h=t.storageInfo.maximumPyramidLevel||0;s="down"===n?Math.floor(Math.min(x,m)):"up"===n?Math.ceil(Math.max(x,m)):Math.round((x+m)/2),s<0?s=0:s>h&&(a=s>h+3,s=h);const p=2**s;return{pyramidLevel:s,pyramidResolution:new f({x:p*t.nativePixelSize.x,y:p*t.nativePixelSize.y,spatialReference:t.spatialReference}),excessiveReading:a}}function ue(e,t,n=!1){const{pixelSize:i,extent:o}=e,r=v(o,t,!1),s=H(le(o,(i.x+i.y)/16),t,r);return!s||n||0===ne(s)?s:Z(o,t,r)}function xe(e,t,n){const i=n?.tileSize??512,o=n?.alignGlobalDatasetWithAGOL??!0,r=!!n?.limitToSrcResolution,{extent:s,pixelSize:a}=e,l=z(a,t,s);if(null==l)return{projectedPixelSize:null,scales:null,srcResolutions:null,isCustomTilingScheme:!1};const c=(l.x+l.y)/2,f=L(c,t),u=256/i,x=t.isGeographic?295828763.7958547*u:591657527.591555*u,m=(t.isGeographic?.703125:156543.03392800014)*u;let h="vector-magdir"===e.dataType||"vector-uv"===e.dataType;const p=ue(e,t,!0),g=Math.min(Math.ceil(Math.log(Math.min(e.width,e.height)/32)/Math.LN2),Math.ceil(Math.log(x/2/f)/Math.LN2));if(!h&&p&&o&&(t.isGeographic||t.isWebMercator)){const n=$(t);if(h=ne(p)>0||null!=n&&p.width>n/4,!h&&null!=n){let t=-1;if(g<3)t=2**g*c*i;else if(e.storageInfo){const{maximumPyramidLevel:n=0,pyramidScalingFactor:o=2}=e.storageInfo;t=o**n*c*i}const o=Math.ceil(n/t);h=1===o||2===o&&n/2-p.xmax<t}}let y,d=f;const w=1.001,M=Math.min(2,Math.max(1.414,e.storageInfo?.pyramidScalingFactor||2));if(h){d=x;const n=me(e,t);y={x:n.x*m,y:n.y*m}}else{y={x:a.x,y:a.y};let e=0;for(;d<x*(w/2)&&e<g;)e++,d*=M,y.x*=M,y.y*=M;Math.max(d,x)/Math.min(d,x)<=w&&(d=x)}const R=[d],S=[{x:y.x,y:y.y}],P=70.5310735,b=Math.min(P,f)/w;for(;d>=b;)d/=M,y.x/=M,y.y/=M,R.push(d),S.push({x:y.x,y:y.y});if(r){const e=.001*a.x;let t=S.findIndex(t=>t.x>=a.x-e&&t.x<=a.x+e);t>-1?(S.length=t+1,R.length=t+1):(t=S.findIndex(t=>t.x<=a.x+e),t>0&&(S.length=t,R.length=t))}return{projectedPixelSize:l,scales:R,srcResolutions:S,isCustomTilingScheme:!h}}function me(e,t){if(t.isWGS84||t.isWebMercator){const n=t.isGeographic?1341104507446289e-21:.29858214164761665,i=t.isGeographic?4326:3857,o=ue(e,new m({wkid:i}),!0),r=z({x:n,y:n},e.spatialReference,o);return{x:r.x/n,y:r.y/n}}const n=z(e.pixelSize,t,e.extent),i=(n.x+n.y)/2;return{x:e.pixelSize.x/i,y:e.pixelSize.y/i}}function he(e,t){const{spatialReference:n,lods:i}=t,{x:o,y:r}=me(e,n);return i.map(({resolution:e})=>({x:e*o,y:e*r}))}function pe(e){let t=0;for(const n of e){const e=n.length;let i=n[0][0]*(n[1][1]-n[e-2][1]);for(let t=1;t<e-1;t++)i+=n[t][0]*(n[t+1][1]-n[t-1][1]);t+=i/2}return Math.abs(t)}export{xe as computeProjectedScales,me as computeSrcResolutionRatio,he as computeSrcResolutions,d as defaultGridSpacing,M as defaultProjectionToleranceInPixels,v as getDefaultDatumTransformationForDataset,F as getProjectedGridPoints,re as getProjectionOffsetGrid,ie as getRasterDatasetAlignmentInfo,W as getSourceScale,$ as getWorldWidth,ne as getWorldWrapCount,j as load,w as minimumGridSpacing,ue as projectDatasetExtent,z as projectDatasetResolution,H as projectExtent,O as projectPoint,Q as projectPolygon,C as projectResolution,ce as shiftExtent,le as snapExtent,fe as snapPyramid};