import{dk as Q,dl as Pt,cA as F,cx as W,t as k,a as b,ci as O,ar as St,a7 as N,dm as bt,g as Gt,dn as v,dp as T,dq as it,dr as Nt,ds as Et,aL as kt,dt as ot}from"./index.6c049565.js";var H;function ht(t,n,i){return!bt(t,n,i)}function $(t,n,i){const r=ht(t,n,i);if(r&&!Q())throw new Gt("rasterprojectionhelper-project","projection engine is not loaded");return r}(function(t){t[t.None=0]="None",t[t.North=1]="North",t[t.South=2]="South",t[t.Both=3]="Both"})(H||(H={}));const st=(t,n,i,r=0)=>{if(i[0]===1)return[0,0];let s=1,e=-1,o=1,u=-1;for(let a=0;at[a]?t[a]:s,e=e>t[a]?e:t[a],o=o>t[a+1]?t[a+1]:o,u=u>t[a+1]?u:t[a+1]);const{cols:f,rows:c}=n,l=(e-s)/f/i[0],d=(u-o)/c/i[1],p=2*r;let x=0,h=!1,m=[0,0];for(let a=0;ax&&(x=R+P,m=[R,P]),p&&x>p){h=!0;break}}if(h)break}return m},Tt={3395:20037508342789244e-9,3410:17334193943686873e-9,3857:20037508342788905e-9,3975:17367530445161372e-9,4087:20037508342789244e-9,4088:20015108787169147e-9,6933:17367530445161372e-9,32662:20037508342789244e-9,53001:2001508679602057e-8,53002:1000754339801029e-8,53003:2001508679602057e-8,53004:2001508679602057e-8,53016:14152803599503474e-9,53017:17333573624304302e-9,53034:2001508679602057e-8,53079:20015114352186374e-9,53080:20015114352186374e-9,54001:20037508342789244e-9,54002:10018754171394624e-9,54003:20037508342789244e-9,54004:20037508342789244e-9,54016:14168658027268292e-9,54017:1736753044516137e-8,54034:20037508342789244e-9,54079:20037508342789244e-9,54080:20037508342789244e-9,54100:20037508342789244e-9,54101:20037508342789244e-9},j=32,I=4,X=I,K=new Map,U=new Map,B=500;async function At(){Q()||await Pt()}function jt(t,n,i){return $(t.spatialReference,n)?i?ot(n,t.spatialReference,t):ot(t.spatialReference,n,t):null}function rt(t,n,i,r=null){const s=t.spatialReference;if(s.equals(n))return t;$(s,n,r);const e=i.center,o=new F({xmin:e.x-t.x/2,xmax:e.x+t.x/2,ymin:e.y-t.y/2,ymax:e.y+t.y/2,spatialReference:s}),u=W(o,n,r),f=C(n);let c;if(k(u)||b(f)&&u.width>=f){const l=O(s)/O(n);c={x:t.x*l,y:t.y*l}}else c={x:u.width,y:u.height};return c}function E(t,n=.01){return O(t)?n/O(t):0}function at(t,n,i=null,r=!0){const s=t.spatialReference;if(s.equals(n))return t;$(s,n,i);const e=W(t,n,i);return r&&e&&mt([t],[e],s,n),e}function mt(t,n,i,r){const s=Y(i,!0),e=Y(r,!0),o=E(i,B),u=E(r,B);if(o&&b(s)&&b(e))for(let f=0;f=e[1]-u&&Math.abs(l-s[0])new N(u[0],u[1],i)),o=W(e,r,s);return s&&mt(e,o,i,r),o.map(u=>u?[u.x,u.y]:[NaN,NaN])}function lt(t){const{inSR:n,outSR:i,datumTransformation:r}=t,s=L(n),{points:e,mask:o}=V(t,s);if(!n.isGeographic){const f=n.wkid?v.coordsys(n.wkid):v.fromString(n.isGeographic?T.PE_TYPE_GEOGCS:T.PE_TYPE_PROJCS,n.wkt);it.projToGeog(f,e.length,e)}if(b(r)&&r.steps.length){let f;if(i.isGeographic&&(f=e.map(([l])=>l>179.9955?1:l<-179.9955?-1:0)),r.steps.forEach(l=>{const d=l.wkid?v.geogtran(l.wkid):v.fromString(T.PE_TYPE_GEOGTRAN,l.wkt);Nt.geogToGeog(d,e.length,e,null,l.isInverse?T.PE_TRANSFORM_2_TO_1:T.PE_TRANSFORM_1_TO_2)}),f)for(let l=0;l179.9955?1:p<-179.9955?-1:0;d&&x&&d!==x&&(e[l][0]=d>0?p+360:p-360)}}if(!i.isGeographic){const f=L(i,!0),c=b(f)&&f.isEnvelope?[f.bbox[1],f.bbox[3]]:[-90,90];zt(e,c);const l=i.wkid?v.coordsys(i.wkid):v.fromString(i.isGeographic?T.PE_TYPE_GEOGCS:T.PE_TYPE_PROJCS,i.wkt);it.geogToProj(l,e.length,e)}let u=e;if(o&&e.length!==o.length){u=[];for(let f=0,c=0;fa.getInclusive()===1&&a.getKind()===1);if(!o){if(o=s.find(a=>a.getInclusive()===1&&a.getKind()===0),!o)return null;e=!0}const u=i?0:(r.getNorthPoleLocation()===2?1:0)|(r.getSouthPoleLocation()===2?2:0),f=r.isPannableRectangle(),c=o.getCoord();if(e)return{isEnvelope:e,isPannable:f,vertices:c,coef:null,bbox:[c[0][0]-n,c[0][1]-n,c[1][0]+n,c[1][1]+n],poleLocation:u};let l=0;const d=[];let[p,x]=c[0],[h,m]=c[0];for(let a=0,w=c.length;ay?h:y,m=m>g?m:g}return{isEnvelope:!1,isPannable:f,vertices:c,coef:d,bbox:[p,x,h,m],poleLocation:u}}function V(t,n){const i=[],{cols:r,rows:s,xres:e,yres:o,usePixelCenter:u}=t;let{xmin:f,ymax:c}=t;if(u&&(f+=e/2,c-=o/2),k(n)){for(let x=0;x=x&&g<=m;for(let R=0;R=h&&P<=a&&(i.push([g,P]),l[y]=1)}}return{points:i,mask:l}}const d=n.coef,p=[];for(let x=0;x=R&&h<=P){const _=g*h+M;m.push(_),a.push(G)}}let w=m;if(m.length>2){let y=a[0]===2?0:a[0],g=m[0];w=[];for(let M=1;MM-R)}else m[0]>m[1]&&(w=[m[1],m[0]]);p.push(w)}for(let x=0,h=0;x=y[0]&&m<=y[1]&&(i.push([m,w]),l[h]=1);else if(y.length>2){let g=!1;for(let M=0;M=y[M]&&m<=y[M+1]){g=!0;break}g&&(i.push([m,w]),l[h]=1)}}}return{points:i,mask:l}}function zt(t,n){const[i,r]=n;for(let s=0;sr)&&(t[s]=[NaN,NaN])}}function pt(t){const n=C(t[0].spatialReference);if(t.length<2||k(n))return t[0];let{xmin:i,xmax:r,ymin:s,ymax:e}=t[0];for(let o=1;oE(s)){const{xmin:c,xmax:l}=t;for(let d=0;d<=e;d++){const p=d===0?c:-o/2,x=d===e?l-o*d:o/2;f[d]=new F({xmin:p,xmax:x,ymin:t.ymin,ymax:t.ymax,spatialReference:s})}}return pt(f.map(c=>ft(c,n,i,r)).filter(b))}function Lt(t,n){const i=C(n);if(k(i))return null;let{xmin:r,ymin:s,xmax:e,ymax:o}=t;const u=t.spatialReference,f=new St({spatialReference:u,rings:[[[r,s],[e,s],[e,o],[r,o],[r,s]]]}),c=W(f,n);if(c.rings.length!==2||!c.rings[0].length||!c.rings[1].length)return null;const{rings:l}=c,d=E(u),p=new F({spatialReference:n});for(let x=0;x<2;x++){r=e=l[x][0][0],s=o=l[x][0][1];for(let h=0;hl[x][h][0]?l[x][h][0]:r,e=el[x][h][1]?l[x][h][1]:s,o=o=o.ymax))return null;if(!r||!o)return o;const u=Y(e,!0),f=Y(n,!0);if(k(u)||k(f))return o;const c=E(e,.001),l=E(e,B),d=E(n,.001);if(Math.abs(o.xmin-f[0])l){o.xmin=f[0];const h=[];h.push(new N(t.xmax,t.ymin,e)),h.push(new N(t.xmax,(t.ymin+t.ymax)/2,e)),h.push(new N(t.xmax,t.ymax,e));const m=h.map(a=>at(a,n,i)).filter(a=>!isNaN(a==null?void 0:a.x)).map(a=>a.x);o.xmax=Math.max.apply(null,m)}if(xl){o.xmax=f[1];const h=[];h.push(new N(t.xmin,t.ymin,e)),h.push(new N(t.xmin,(t.ymin+t.ymax)/2,e)),h.push(new N(t.xmin,t.ymax,e));const m=h.map(a=>at(a,n,i)).filter(a=>!isNaN(a==null?void 0:a.x)).map(a=>a.x);o.xmin=Math.min.apply(null,m)}}else{const p=E(n,.001);Math.abs(o.xmin-f[0])0&&r.outofBoundPointCountX)&&(ht(f,c,t.datumTransformation)&&(f.isGeographic||b(L(f))),i=[I,I],r=D({...t,spacing:i}),s={cols:r.size[0]+1,rows:r.size[1]+1},o=st(r.offsets,s,i,X)),r.error=o,i[0]>1&&(r.coefficients=xt(r.offsets,s,e)),t.includeGCSGrid&&!f.isGeographic&&!f.isWebMercator)if(c.isGeographic)r.gcsGrid={offsets:r.offsets,coefficients:r.coefficients,spacing:i};else{const l=L(f);if(b(l)&&!l.isEnvelope){const d=Wt(f),p=gt(t.projectedExtent,d),{offsets:x}=D({...t,srcBufferExtent:p,spacing:i}),h=xt(x,s,e);r.gcsGrid={offsets:x,coefficients:h,spacing:i}}}return r}function D(t){const{projectedExtent:n,srcBufferExtent:i,pixelSize:r,datumTransformation:s,rasterTransform:e}=t,o=n.spatialReference,u=i.spatialReference,f=$(o,u),{xmin:c,ymin:l,xmax:d,ymax:p}=n,x=C(u),h=b(x)&&(t.hasWrapAround||(e==null?void 0:e.type)==="gcs-shift"),m=t.spacing||[j,j],a=m[0]*r.x,w=m[1]*r.y,y=m[0]===1,g=Math.ceil((d-c)/a-.1/m[0])+(y?0:1),M=Math.ceil((p-l)/w-.1/m[1])+(y?0:1),R=vt({cols:g,rows:M,xmin:c,ymax:p,xres:a,yres:w,inSR:o,outSR:u,datumTransformation:s,preferPE:m[0]<=I,usePixelCenter:y}),P=[];let G,_=0;const Z=y?-1:NaN,{xmin:tt,xmax:q,ymax:yt,width:dt,height:Mt}=i,wt=E(u,B),Rt=b(x)&&tt>0&&q>x/2;let nt=!1;if(f){const z=L(o);nt=b(z)&&z.poleLocation>0}for(let z=0;zq&&S[0]>x/2-wt?S[0]-=x:h&&z===0&&S[0]<0&&Rt&&!e&&(S[0]+=x),!S||isNaN(S[0])||isNaN(S[1]))P.push(Z),P.push(Z),J.push(null),_++;else{if(e){const et=e.inverseTransform(new N({x:S[0],y:S[1],spatialReference:u}));S=[et.x,et.y]}J.push(S),z>0&&h&&G[A]&&S[0]q&&S[0]>x&&(S[0]-=x)),P.push((S[0]-tt)/dt),P.push((yt-S[1])/Mt)}}G=J}return{offsets:P,error:null,coefficients:null,outofBoundPointCount:_,spacing:m,size:y?[g,M]:[g-1,M-1]}}function xt(t,n,i){const{cols:r,rows:s}=n,e=new Float32Array((r-1)*(s-1)*2*6),o=new Float32Array([-0,-1,1,-1,1,-0,1,-0,-0]),u=new Float32Array([-1,1,0,0,-1,1,1,0,0]);for(let f=0;f=h)e=u.length,o=p/h>8;else{let w,y=m;for(let g=1;g<=u.length;g++){if(w=(u[g-1].x+u[g-1].y)/2,p<=w){p===w?e=g:i==="down"?(e=g-1,o=p/y>8):e=i==="up"||p-y>w-p||p/y>2?g:g-1;break}y=w}}const a=e===0?s:u[e-1];return o&&Math.min(a.x,a.y)*O(n.spatialReference)>19567&&(o=!1),{pyramidLevel:e,pyramidResolution:new N({x:a.x,y:a.y,spatialReference:n.spatialReference}),excessiveReading:o}}const f=Math.log(t.x/s.x)/Math.LN2,c=Math.log(t.y/s.y)/Math.LN2,l=n.storageInfo.maximumPyramidLevel||0;e=i==="down"?Math.floor(Math.min(f,c)):i==="up"?Math.ceil(Math.max(f,c)):Math.round((f+c)/2),e<0?e=0:e>l&&(o=e>l+3,e=l);const d=2**e;return{pyramidLevel:e,pyramidResolution:new N({x:d*n.nativePixelSize.x,y:d*n.nativePixelSize.y,spatialReference:n.spatialReference}),excessiveReading:o}}function qt(t,n,i=512,r=!0){const{extent:s,spatialReference:e,pixelSize:o}=t,u=rt(new N({x:o.x,y:o.y,spatialReference:e}),n,s);if(u==null)return{projectedPixelSize:null,scales:null,srcResolutions:null,isCustomTilingScheme:!1};const f=(u.x+u.y)/2,c=O(n),l=f*c*96*39.37,d=n.isGeographic?256/i*2958287637958547e-7:256/i*591657527591555e-6;let p=t.dataType==="vector-magdir"||t.dataType==="vector-uv";const x=gt(s,n),h=Math.min(Math.ceil(Math.log(Math.min(t.width,t.height)/32)/Math.LN2),Math.ceil(Math.log(d/2/l)/Math.LN2));if(!p&&r&&(n.isGeographic||n.isWebMercator)&&(p=x.xmin*x.xmax<0,!p&&h<3)){const P=C(n);if(b(P)){const G=2**h*f*i,_=Math.ceil(P/G);p=_===1||_===2&&P/2-x.xmax=R;)a/=2,m.x/=2,m.y/=2,y.push(a),g.push({x:m.x,y:m.y});return{projectedPixelSize:u,scales:y,srcResolutions:g,isCustomTilingScheme:!p}}export{Bt as $,rt as C,gt as J,ht as M,Ot as Q,At as T,C as U,It as V,qt as i,at as j,Yt as n,Ft as o,jt as v};