import{b0 as nn,b1 as Sn,ab as B,b2 as I,aW as O,L as Pn,aI as pn,aH as k,b3 as Gn,b4 as kn,s as Nn,b5 as C,b6 as v,b7 as sn,b8 as En,b9 as Tn,f as vn,ba as an}from"./index-b5c8f851.js";var Z;function gn(n,t,e){return!kn(n,t,e)}function L(n,t,e){const s=gn(n,t,e);if(s&&!nn())throw new Nn("rasterprojectionhelper-project","projection engine is not loaded");return s}(function(n){n[n.None=0]="None",n[n.North=1]="North",n[n.South=2]="South",n[n.Both=3]="Both"})(Z||(Z={}));const rn=(n,t,e,s=0)=>{if(e[0]===1)return[0,0];let a=1,i=-1,o=1,f=-1;for(let u=0;un[u]?n[u]:a,i=i>n[u]?i:n[u],o=o>n[u+1]?n[u+1]:o,f=f>n[u+1]?f:n[u+1]);const{cols:l,rows:r}=t,c=(i-a)/l/e[0],M=(f-o)/r/e[1],y=2*s;let x=0,h=!1,p=[0,0];for(let u=0;ux&&(x=w+b,p=[w,b]),y&&x>y){h=!0;break}}if(h)break}return p},Cn={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},F=32,Y=4,H=Y,U=new Map,V=new Map,q=500;async function Fn(){nn()||await Sn()}function _n(n,t,e){return L(n.spatialReference,t),e?an(t,n.spatialReference,n):an(n.spatialReference,t,n)}function ln(n,t,e,s=null){const a=n.spatialReference;if(a.equals(t))return n;L(a,t,s);const i=e.center,o=new B({xmin:i.x-n.x/2,xmax:i.x+n.x/2,ymin:i.y-n.y/2,ymax:i.y+n.y/2,spatialReference:a}),f=I(o,t,s),l=_(t);let r;if(f==null||l!=null&&f.width>=l){const c=O(a)/O(t);r={x:n.x*c,y:n.y*c}}else r={x:f.width,y:f.height};return r}function N(n,t=.01){return O(n)?t/O(n):0}function cn(n,t,e=null,s=!0){const a=n.spatialReference;if(a.equals(t))return n;L(a,t,e);const i=I(n,t,e);return s&&i&&yn([n],[i],a,t),i}function yn(n,t,e,s){const a=J(e,!0),i=J(s,!0),o=N(e,q),f=N(s,q);if(o&&a!=null&&i!=null)for(let l=0;l=i[1]-f&&Math.abs(c-a[0])new k(f[0],f[1],e)),o=I(i,s,a);return a&&yn(i,o,e,s),o.map(f=>f?[f.x,f.y]:[NaN,NaN])}function fn(n){const{inSR:t,outSR:e,datumTransformation:s}=n,a=$(t),{points:i,mask:o}=tn(n,a);if(!t.isGeographic){const l=t.wkid?C.coordsys(t.wkid):C.fromString(t.isGeographic?v.PE_TYPE_GEOGCS:v.PE_TYPE_PROJCS,t.wkt2||t.wkt);sn.projToGeog(l,i.length,i)}if(s!=null&&s.steps.length){let l;if(e.isGeographic&&(l=i.map(([c])=>c>179.9955?1:c<-179.9955?-1:0)),s.steps.forEach(c=>{const M=c.wkid?C.geogtran(c.wkid):C.fromString(v.PE_TYPE_GEOGTRAN,c.wkt);En.geogToGeog(M,i.length,i,null,c.isInverse?v.PE_TRANSFORM_2_TO_1:v.PE_TRANSFORM_1_TO_2)}),l)for(let c=0;c179.9955?1:y<-179.9955?-1:0;M&&x&&M!==x&&(i[c][0]=M>0?y+360:y-360)}}if(!e.isGeographic){const l=$(e,!0),r=l!=null&&l.isEnvelope?[l.bbox[1],l.bbox[3]]:[-90,90];Ln(i,r);const c=e.wkid?C.coordsys(e.wkid):C.fromString(e.isGeographic?v.PE_TYPE_GEOGCS:v.PE_TYPE_PROJCS,e.wkt2||e.wkt);sn.geogToProj(c,i.length,i)}let f=i;if(o&&i.length!==o.length){f=[];for(let l=0,r=0;lu.getInclusive()===1&&u.getKind()===1);if(!o){if(o=a.find(u=>u.getInclusive()===1&&u.getKind()===0),!o)return null;i=!0}const f=e?0:(s.getNorthPoleLocation()===2?1:0)|(s.getSouthPoleLocation()===2?2:0),l=s.isPannableRectangle(),r=o.getCoord();if(i)return{isEnvelope:i,isPannable:l,vertices:r,coef:null,bbox:[r[0][0]-t,r[0][1]-t,r[1][0]+t,r[1][1]+t],poleLocation:f};let c=0;const M=[];let[y,x]=r[0],[h,p]=r[0];for(let u=0,R=r.length;um?h:m,p=p>g?p:g}return{isEnvelope:!1,isPannable:l,vertices:r,coef:M,bbox:[y,x,h,p],poleLocation:f}}function tn(n,t){const e=[],{cols:s,rows:a,xres:i,yres:o,usePixelCenter:f}=n;let{xmin:l,ymax:r}=n;if(f&&(l+=i/2,r-=o/2),t==null){for(let x=0;x=x&&g<=p;for(let w=0;w=h&&b<=u&&(e.push([g,b]),c[m]=1)}}return{points:e,mask:c}}const M=t.coef,y=[];for(let x=0;x=w&&h<=b){const W=g*h+d;p.push(W),u.push(T)}}let R=p;if(p.length>2){let m=u[0]===2?0:u[0],g=p[0];R=[];for(let d=1;dd-w)}else p[0]>p[1]&&(R=[p[1],p[0]]);y.push(R)}for(let x=0,h=0;x=m[0]&&p<=m[1]&&(e.push([p,R]),c[h]=1);else if(m.length>2){let g=!1;for(let d=0;d=m[d]&&p<=m[d+1]){g=!0;break}g&&(e.push([p,R]),c[h]=1)}}}return{points:e,mask:c}}function Ln(n,t){const[e,s]=t;for(let a=0;as)&&(n[a]=[NaN,NaN])}}function dn(n,t){const e=_(n[0].spatialReference);if(n.length<2||e==null||(t=t??N(n[0].spatialReference),(n=n.filter(f=>f.width>t)).length===1))return n[0];let{xmin:s,xmax:a,ymin:i,ymax:o}=n[0];for(let f=1;fN(a)){const{xmin:r,xmax:c}=n;for(let M=0;M<=i;M++){const y=M===0?r:-o/2,x=M===i?c-o*M:o/2;l[M]=new B({xmin:y,xmax:x,ymin:n.ymin,ymax:n.ymax,spatialReference:a})}}return dn(l.map(r=>xn(r,t,e,s)).filter(Pn))}function Yn(n,t,e){if(n.type==="extent"){const{xmin:s,ymin:a,xmax:i,ymax:o,spatialReference:f}=n;n=new pn({rings:[[[s,o],[i,o],[i,a],[s,a],[s,o]]],spatialReference:f})}return n.spatialReference.equals(t)?n:(L(n.spatialReference,t,e),I(n,t,e))}function Wn(n,t){const e=_(t);if(e==null)return null;let{xmin:s,ymin:a,xmax:i,ymax:o}=n;const f=n.spatialReference,l=new pn({spatialReference:f,rings:[[[s,a],[i,a],[i,o],[s,o],[s,a]]]}),r=I(l,t);if(r.rings.length!==2||!r.rings[0].length||!r.rings[1].length)return null;const{rings:c}=r,M=N(f),y=new B({spatialReference:t});for(let x=0;x<2;x++){s=i=c[x][0][0],a=o=c[x][0][1];for(let h=0;hc[x][h][0]?c[x][h][0]:s,i=ic[x][h][1]?c[x][h][1]:a,o=o=o.ymax))return null;if(!s||!o)return o;const f=J(i,!0),l=J(t,!0);if(f==null||l==null)return o;const r=N(i,.001),c=N(i,q),M=N(t,.001);if(Math.abs(o.xmin-l[0])c){o.xmin=l[0];const h=[];h.push(new k(n.xmax,n.ymin,i)),h.push(new k(n.xmax,(n.ymin+n.ymax)/2,i)),h.push(new k(n.xmax,n.ymax,i));const p=h.map(u=>cn(u,t,e)).filter(u=>!isNaN(u==null?void 0:u.x)).map(u=>u.x);o.xmax=Math.max.apply(null,p)}if(xc){o.xmax=l[1];const h=[];h.push(new k(n.xmin,n.ymin,i)),h.push(new k(n.xmin,(n.ymin+n.ymax)/2,i)),h.push(new k(n.xmin,n.ymax,i));const p=h.map(u=>cn(u,t,e)).filter(u=>!isNaN(u==null?void 0:u.x)).map(u=>u.x);o.xmin=Math.min.apply(null,p)}}else{const y=N(t,.001);Math.abs(o.xmin-l[0])0&&s.outofBoundPointCountH)&&(gn(l,r,n.datumTransformation)&&(l.isGeographic||$(l)),e=[Y,Y],s=Q({...n,spacing:e}),a={cols:s.size[0]+1,rows:s.size[1]+1},o=rn(s.offsets,a,e,H)),s.error=o,e[0]>1&&(s.coefficients=mn(s.offsets,a,i)),n.includeGCSGrid&&!l.isGeographic&&!l.isWebMercator)if(r.isGeographic)s.gcsGrid={offsets:s.offsets,coefficients:s.coefficients,spacing:e};else{const c=$(l);if(c!=null&&!c.isEnvelope){const M=On(l),y=Mn(n.projectedExtent,M),{offsets:x}=Q({...n,srcBufferExtent:y,spacing:e}),h=mn(x,a,i);s.gcsGrid={offsets:x,coefficients:h,spacing:e}}}return s}function Q(n){const{projectedExtent:t,srcBufferExtent:e,pixelSize:s,datumTransformation:a,rasterTransform:i}=n,o=t.spatialReference,f=e.spatialReference,l=L(o,f),{xmin:r,ymin:c,xmax:M,ymax:y}=t,x=_(f),h=x!=null&&(n.hasWrapAround||(i==null?void 0:i.type)==="gcs-shift"),p=n.spacing||[F,F],u=p[0]*s.x,R=p[1]*s.y,m=p[0]===1,g=Math.ceil((M-r)/u-.1/p[0])+(m?0:1),d=Math.ceil((y-c)/R-.1/p[1])+(m?0:1),w=zn({cols:g,rows:d,xmin:r,ymax:y,xres:u,yres:R,inSR:o,outSR:f,datumTransformation:a,preferPE:p[0]<=Y,usePixelCenter:m}),b=[];let T,W=0;const j=m?-1:NaN,{xmin:S,xmax:P,ymax:E,width:K,height:X}=e,Rn=N(f,q),bn=x!=null&&S>0&&P>x/2;let en=!1;if(l){const z=$(o);en=z!=null&&z.poleLocation>0}for(let z=0;zP&&G[0]>x/2-Rn?G[0]-=x:h&&z===0&&G[0]<0&&bn&&!i&&(G[0]+=x),!G||isNaN(G[0])||isNaN(G[1]))b.push(j),b.push(j),D.push(null),W++;else{if(i){const on=i.inverseTransform(new k({x:G[0],y:G[1],spatialReference:f}));G=[on.x,on.y]}D.push(G),z>0&&h&&T[A]&&G[0]P&&G[0]>x&&(G[0]-=x)),b.push((G[0]-S)/K),b.push((E-G[1])/X)}}T=D}return{offsets:b,error:null,coefficients:null,outofBoundPointCount:W,spacing:p,size:m?[g,d]:[g-1,d-1]}}function mn(n,t,e){const{cols:s,rows:a}=t,i=new Float32Array((s-1)*(a-1)*2*6),o=new Float32Array([-0,-1,1,-1,1,-0,1,-0,-0]),f=new Float32Array([-1,1,0,0,-1,1,1,0,0]);for(let l=0;la){const f=n.xmin-a;o=-Math.ceil(f/i)}return new B({spatialReference:n.spatialReference,xmin:n.xmin+o*i,ymin:n.ymin,xmax:n.xmax+o*i,ymax:n.ymax})}function Xn(n,t,e){var h;const{storageInfo:s,pixelSize:a}=t;let i=0,o=!1;const{pyramidResolutions:f}=s,l=((h=s.tileInfo.format)==null?void 0:h.toLowerCase())==="mixed"?Math.max(1,Math.min(3,s.tileInfo.dpi/96)):1,r=(n.x+n.y)/2/l;if(f!=null&&f.length){const p=f[f.length-1],u=(p.x+p.y)/2,R=(a.x+a.y)/2;if(r<=R)i=0;else if(r>=u)i=f.length,o=r/u>8;else{let g,d=R;for(let w=1;w<=f.length;w++){if(g=(f[w-1].x+f[w-1].y)/2,r<=g){r===g?i=w:e==="down"?(i=w-1,o=r/d>8):i=e==="up"||r-d>g-r||r/d>2?w:w-1;break}d=g}}const m=i===0?a:f[i-1];return o&&Math.min(m.x,m.y)*O(t.spatialReference)>19567&&(o=!1),{pyramidLevel:i,pyramidResolution:new k({x:m.x,y:m.y,spatialReference:t.spatialReference}),excessiveReading:o}}const c=Math.log(n.x/a.x)/Math.LN2,M=Math.log(n.y/a.y)/Math.LN2,y=t.storageInfo.maximumPyramidLevel||0;i=e==="down"?Math.floor(Math.min(c,M)):e==="up"?Math.ceil(Math.max(c,M)):Math.round((c+M)/2),i<0?i=0:i>y&&(o=i>y+3,i=y);const x=2**i;return{pyramidLevel:i,pyramidResolution:new k({x:x*t.nativePixelSize.x,y:x*t.nativePixelSize.y,spatialReference:t.spatialReference}),excessiveReading:o}}function An(n,t){const{pixelSize:e,extent:s}=n,a=_n(s,t,!1);return Mn(jn(s,(e.x+e.y)/16),t,a)}function Dn(n,t,e){var j;const s=(e==null?void 0:e.tileSize)??512,a=(e==null?void 0:e.alignGlobalDatasetWithAGOL)??!0,i=!!(e!=null&&e.limitToSrcResolution),{extent:o,spatialReference:f,pixelSize:l}=n,r=ln(new k({x:l.x,y:l.y,spatialReference:f}),t,o);if(r==null)return{projectedPixelSize:null,scales:null,srcResolutions:null,isCustomTilingScheme:!1};const c=(r.x+r.y)/2,M=O(t),y=c*M*96*39.37,x=t.isGeographic?256/s*2958287637958547e-7:256/s*591657527591555e-6;let h=n.dataType==="vector-magdir"||n.dataType==="vector-uv";const p=An(n,t),u=Math.min(Math.ceil(Math.log(Math.min(n.width,n.height)/32)/Math.LN2),Math.ceil(Math.log(x/2/y)/Math.LN2));if(!h&&a&&(t.isGeographic||t.isWebMercator)){const S=_(t);if(h=wn(p)>0||S!=null&&p.width>S/4,!h&&S!=null){let P=-1;if(u<3)P=2**u*c*s;else if(n.storageInfo){const{maximumPyramidLevel:K=0,pyramidScalingFactor:X=2}=n.storageInfo;P=X**K*c*s}const E=Math.ceil(S/P);h=E===1||E===2&&S/2-p.xmax=W;)m/=d,R.x/=d,R.y/=d,w.push(m),b.push({x:R.x,y:R.y});if(i){const S=.001*l.x;let P=b.findIndex(E=>E.x>=l.x-S&&E.x<=l.x+S);P>-1?(b.length=P+1,w.length=P+1):(P=b.findIndex(E=>E.x<=l.x+S),P>0&&(b.length=P,w.length=P))}return{projectedPixelSize:r,scales:w,srcResolutions:b,isCustomTilingScheme:!h}}export{ln as C,_ as D,Mn as J,gn as M,Fn as T,Yn as U,wn as V,qn as Z,Dn as a,Jn as e,cn as j,Kn as o,Xn as r,An as s,_n as v};