2 lines
40 KiB
JavaScript
2 lines
40 KiB
JavaScript
import{A as W,B as z,ea as Vt,C as _t,a6 as Dt,s as Lt,bb as Rt,z as Q,a1 as Nt,Y as nt,aC as Et,b3 as jt,ab as Gt,ij as Ut,ik as Ot}from"./index-b5c8f851.js";let gt=class{constructor(e=null,n=null,o=null){this.minValue=e,this.maxValue=n,this.noDataValue=o}};const qt=9999999e31,Wt=2e-7,Xt={u1:[0,1],u2:[0,3],u4:[0,15],u8:[0,255],s8:[-128,127],u16:[0,65535],s16:[-32768,32767],u32:[0,4294967295],s32:[-2147483648,2147483647],f32:[-34028234663852886e22,34028234663852886e22],f64:[-Number.MAX_VALUE,Number.MAX_VALUE],unknown:void 0,c64:void 0,c128:void 0};function ht(t){return Xt[t]??[-34028234663852886e22,34028234663852886e22]}function xe(t,e,n){var p,u;if(t.depthCount&&t.depthCount>1)return;const{pixels:o,statistics:h,pixelType:i}=t,r=o[0].length,f=t.bandMasks??[],a=t.mask??new Uint8Array(r).fill(255),l=i==="f32"||i==="f64",s=ht(i);let c=!1;for(let d=0;d<o.length;d++){const m=typeof e=="number"?e:e[d];if(m==null)continue;const x=((p=h==null?void 0:h[d])==null?void 0:p.minValue)??s[0],w=((u=h==null?void 0:h[d])==null?void 0:u.maxValue)??s[1];if(x>m+Number.EPSILON||w<m-Number.EPSILON)continue;const A=f[d]||a.slice(),k=o[d],M=n==null?void 0:n.customFloatTolerance;if(l&&M!==0){let g=M;g||(g=Math.abs(m)>=qt?Wt*Math.abs(m):i==="f32"?2**-23:Number.EPSILON);for(let y=0;y<k.length;y++)A[y]&&Math.abs(k[y]-m)<g&&(k[y]=0,A[y]=0,a[y]=0,c=!0)}else for(let g=0;g<k.length;g++)A[g]&&k[g]===m&&(k[g]=0,A[g]=0,a[g]=0,c=!0);f[d]=A}c&&(t.bandMasks=t.bandMasks||t.pixels.length>1?f:null,t.mask=a),c&&"updateStatistics"in t&&t.updateStatistics()}var Z;let G=Z=class extends Dt{static createEmptyBand(t,e){return new(Z.getPixelArrayConstructor(t))(e)}static getPixelArrayConstructor(t){let e;switch(t){case"u1":case"u2":case"u4":case"u8":e=Uint8Array;break;case"u16":e=Uint16Array;break;case"u32":e=Uint32Array;break;case"s8":e=Int8Array;break;case"s16":e=Int16Array;break;case"s32":e=Int32Array;break;case"f32":case"c64":case"c128":case"unknown":e=Float32Array;break;case"f64":e=Float64Array}return e}constructor(t){super(t),this.width=null,this.height=null,this.pixelType="f32",this.validPixelCount=null,this.mask=null,this.maskIsAlpha=!1,this.premultiplyAlpha=!1,this.statistics=null,this.depthCount=1}castPixelType(t){if(!t)return"f32";let e=t.toLowerCase();return["u1","u2","u4"].includes(e)?e="u8":["unknown","u8","s8","u16","s16","u32","s32","f32","f64"].includes(e)||(e="f32"),e}getPlaneCount(){var t;return(t=this.pixels)==null?void 0:t.length}addData(t){if(!t.pixels||t.pixels.length!==this.width*this.height)throw new Lt("pixelblock:invalid-or-missing-pixels","add data requires valid pixels array that has same length defined by pixel block width * height");this.pixels||(this.pixels=[]),this.statistics||(this.statistics=[]),this.pixels.push(t.pixels),this.statistics.push(t.statistics??new gt)}getAsRGBA(){const t=new ArrayBuffer(this.width*this.height*4);switch(this.pixelType){case"s8":case"s16":case"u16":case"s32":case"u32":case"f32":case"f64":this._fillFromNon8Bit(t);break;default:this._fillFrom8Bit(t)}return new Uint8ClampedArray(t)}getAsRGBAFloat(){const t=new Float32Array(this.width*this.height*4);return this._fillFrom32Bit(t),t}updateStatistics(){if(!this.pixels)return;this.statistics=this.pixels.map(n=>this._calculateBandStatistics(n,this.mask));const t=this.mask;let e=0;if(t!=null)for(let n=0;n<t.length;n++)t[n]&&e++;else e=this.width*this.height;this.validPixelCount=e}clamp(t){if(!t||t==="f64"||t==="f32"||!this.pixels)return;const[e,n]=ht(t),o=this.pixels,h=this.width*this.height,i=o.length;let r,f,a;const l=[];for(let s=0;s<i;s++){a=Z.createEmptyBand(t,h),r=o[s];for(let c=0;c<h;c++)f=r[c],a[c]=f>n?n:f<e?e:f;l.push(a)}this.pixels=l,this.pixelType=t}extractBands(t){var c;const{pixels:e,statistics:n}=this;if(t==null||t.length===0||!e||e.length===0)return this;const o=e.length,h=t.some(p=>p>=e.length),i=o===t.length&&!t.some((p,u)=>p!==u);if(h||i)return this;const r=((c=this.bandMasks)==null?void 0:c.length)===o?t.map(p=>this.bandMasks[p]):void 0;let{mask:f,validPixelCount:a}=this;const{width:l,height:s}=this;if(r){if(r.length===1)f=r[0];else{const p=l*s;f=new Uint8Array(p).fill(255);for(let u=0;u<r.length;u++){const d=r[u];for(let m=0;m<p;m++)d[m]||(f[m]=0)}}a=f.filter(p=>!!p).length}return new Z({pixelType:this.pixelType,width:l,height:s,mask:f,bandMasks:r,validPixelCount:a,maskIsAlpha:this.maskIsAlpha,pixels:t.map(p=>e[p]),statistics:n&&t.map(p=>n[p])})}clone(){const t=new Z({width:this.width,height:this.height,pixelType:this.pixelType,maskIsAlpha:this.maskIsAlpha,validPixelCount:this.validPixelCount});let e;this.mask!=null&&(this.mask instanceof Uint8Array?t.mask=new Uint8Array(this.mask):t.mask=this.mask.slice(0)),this.bandMasks&&(t.bandMasks=this.bandMasks.map(o=>new Uint8Array(o)));const n=Z.getPixelArrayConstructor(this.pixelType);if(this.pixels&&this.pixels.length>0){t.pixels=[];const o=!!this.pixels[0].slice;for(e=0;e<this.pixels.length;e++)t.pixels[e]=o?this.pixels[e].slice(0,this.pixels[e].length):new n(this.pixels[e])}if(this.statistics)for(t.statistics=[],e=0;e<this.statistics.length;e++)t.statistics[e]=Rt(this.statistics[e]);return t.premultiplyAlpha=this.premultiplyAlpha,t}_fillFrom8Bit(t){const{mask:e,maskIsAlpha:n,premultiplyAlpha:o,pixels:h}=this;if(!t||!(h!=null&&h.length))return void Q.getLogger(this).error("getAsRGBA()","Unable to convert to RGBA. The input pixel block is empty.");let i,r,f,a;i=r=f=h[0],h.length>=3?(r=h[1],f=h[2]):h.length===2&&(r=h[1]);const l=new Uint32Array(t),s=this.width*this.height;if(i.length===s)if(e!=null&&e.length===s)if(n)for(a=0;a<s;a++){const c=e[a];if(c){const p=c/255;l[a]=o?c<<24|f[a]*p<<16|r[a]*p<<8|i[a]*p:c<<24|f[a]<<16|r[a]<<8|i[a]}}else for(a=0;a<s;a++)e[a]&&(l[a]=255<<24|f[a]<<16|r[a]<<8|i[a]);else for(a=0;a<s;a++)l[a]=255<<24|f[a]<<16|r[a]<<8|i[a];else Q.getLogger(this).error("getAsRGBA()","Unable to convert to RGBA. The pixelblock is invalid.")}_fillFromNon8Bit(t){const{pixels:e,mask:n,statistics:o}=this;if(!t||!(e!=null&&e.length))return void Q.getLogger(this).error("getAsRGBA()","Unable to convert to RGBA. The input pixel block is empty.");const h=this.pixelType;let i=1,r=0,f=1;if(o&&o.length>0){for(const m of o)if(m.minValue!=null&&(r=Math.min(r,m.minValue)),m.maxValue!=null&&m.minValue!=null){const x=m.maxValue-m.minValue;f=Math.max(f,x)}i=255/f}else{let m=255;h==="s8"?(r=-128,m=127):h==="u16"?m=65535:h==="s16"?(r=-32768,m=32767):h==="u32"?m=4294967295:h==="s32"?(r=-2147483648,m=2147483647):h==="f32"?(r=-34e38,m=34e38):h==="f64"&&(r=-Number.MAX_VALUE,m=Number.MAX_VALUE),i=255/(m-r)}const a=new Uint32Array(t),l=this.width*this.height;let s,c,p,u,d;if(s=c=p=e[0],s.length!==l)return Q.getLogger(this).error("getAsRGBA()","Unable to convert to RGBA. The pixelblock is invalid.");if(e.length>=2)if(c=e[1],e.length>=3&&(p=e[2]),n!=null&&n.length===l)for(u=0;u<l;u++)n[u]&&(a[u]=255<<24|(p[u]-r)*i<<16|(c[u]-r)*i<<8|(s[u]-r)*i);else for(u=0;u<l;u++)a[u]=255<<24|(p[u]-r)*i<<16|(c[u]-r)*i<<8|(s[u]-r)*i;else if(n!=null&&n.length===l)for(u=0;u<l;u++)d=(s[u]-r)*i,n[u]&&(a[u]=255<<24|d<<16|d<<8|d);else for(u=0;u<l;u++)d=(s[u]-r)*i,a[u]=255<<24|d<<16|d<<8|d}_fillFrom32Bit(t){const{pixels:e,mask:n}=this;if(!t||!(e!=null&&e.length))return Q.getLogger(this).error("getAsRGBAFloat()","Unable to convert to RGBA. The input pixel block is empty.");let o,h,i,r;o=h=i=e[0],e.length>=3?(h=e[1],i=e[2]):e.length===2&&(h=e[1]);const f=this.width*this.height;if(o.length!==f)return Q.getLogger(this).error("getAsRGBAFloat()","Unable to convert to RGBA. The pixelblock is invalid.");let a=0;if(n!=null&&n.length===f)for(r=0;r<f;r++)t[a++]=o[r],t[a++]=h[r],t[a++]=i[r],t[a++]=1&n[r];else for(r=0;r<f;r++)t[a++]=o[r],t[a++]=h[r],t[a++]=i[r],t[a++]=1}_calculateBandStatistics(t,e){let n=1/0,o=-1/0;const h=t.length;let i,r=0;if(e!=null)for(i=0;i<h;i++)e[i]&&(r=t[i],n=r<n?r:n,o=r>o?r:o);else for(i=0;i<h;i++)r=t[i],n=r<n?r:n,o=r>o?r:o;return new gt(n,o)}};W([z({json:{write:!0}})],G.prototype,"width",void 0),W([z({json:{write:!0}})],G.prototype,"height",void 0),W([z({json:{write:!0}})],G.prototype,"pixelType",void 0),W([Vt("pixelType")],G.prototype,"castPixelType",null),W([z({json:{write:!0}})],G.prototype,"validPixelCount",void 0),W([z({json:{write:!0}})],G.prototype,"mask",void 0),W([z({json:{write:!0}})],G.prototype,"maskIsAlpha",void 0),W([z({json:{write:!0}})],G.prototype,"pixels",void 0),W([z()],G.prototype,"premultiplyAlpha",void 0),W([z({json:{write:!0}})],G.prototype,"statistics",void 0),W([z({json:{write:!0}})],G.prototype,"depthCount",void 0),W([z({json:{write:!0}})],G.prototype,"noDataValues",void 0),W([z({json:{write:!0}})],G.prototype,"bandMasks",void 0),G=Z=W([_t("esri.layers.support.PixelBlock")],G);const _=G;var xt,wt;(function(t){t[t.matchAny=0]="matchAny",t[t.matchAll=1]="matchAll"})(xt||(xt={})),function(t){t[t.bestMatch=0]="bestMatch",t[t.fail=1]="fail"}(wt||(wt={}));const we=6;function L(t){return t!=null&&t.declaredClass==="esri.layers.support.PixelBlock"&&t.pixels&&t.pixels.length>0}function ye(t){var s;if(!(t!=null&&t.length)||t.some(c=>!L(c)))return null;if(t.length===1)return((s=t[0])==null?void 0:s.clone())??null;const e=t,{width:n,height:o,pixelType:h}=e[0];if(e.some(c=>c.width!==n||c.height!==o))return null;const i=e.map(({mask:c})=>c).filter(c=>c!=null);let r=null;i.length&&(r=new Uint8Array(n*o),r.set(i[0]),i.length>1&&Tt(i.slice(1),r));const f=[];e.forEach(({pixels:c})=>f.push(...c));const a=e.map(({statistics:c})=>c).filter(c=>c==null?void 0:c.length),l=[];return a.forEach(c=>l.push(...c)),new _({pixelType:h,width:n,height:o,mask:r,pixels:f,statistics:l.length?l:null})}function ke(t){if(!t)return;const e=t.colormap;if(!e||e.length===0)return;const n=e.sort((c,p)=>c[0]-p[0]);let o=0;n[0][0]<0&&(o=n[0][0]);const h=Math.max(256,n[n.length-1][0]-o+1),i=new Uint8Array(4*h),r=[];let f,a=0,l=0;const s=n[0].length===5;if(h>65536)return n.forEach(c=>{r[c[0]-o]=s?c.slice(1):c.slice(1).concat([255])}),{indexed2DColormap:r,offset:o,alphaSpecified:s};if(t.fillUnspecified)for(f=n[l],a=f[0]-o;a<h;a++)i[4*a]=f[1],i[4*a+1]=f[2],i[4*a+2]=f[3],i[4*a+3]=s?f[4]:255,a===f[0]-o&&(f=l===n.length-1?f:n[++l]);else for(a=0;a<n.length;a++)f=n[a],l=4*(f[0]-o),i[l]=f[1],i[l+1]=f[2],i[l+2]=f[3],i[l+3]=s?f[4]:255;return{indexedColormap:i,offset:o,alphaSpecified:s}}function Me(t,e){if(!L(t)||!e||!e.indexedColormap&&!e.indexed2DColormap)return t;const n=t.clone(),o=n.pixels;let h=n.mask;const i=n.width*n.height;if(o.length!==1)return t;const{indexedColormap:r,indexed2DColormap:f,offset:a,alphaSpecified:l}=e;let s=0;const c=o[0],p=new Uint8Array(c.length),u=new Uint8Array(c.length),d=new Uint8Array(c.length);let m,x=0;if(r){const w=r.length-1;if(h!=null)for(s=0;s<i;s++)h[s]&&(x=4*(c[s]-a),x<a||x>w?h[s]=0:(p[s]=r[x],u[s]=r[x+1],d[s]=r[x+2],h[s]=r[x+3]));else{for(h=new Uint8Array(i),s=0;s<i;s++)x=4*(c[s]-a),x<a||x>w?h[s]=0:(p[s]=r[x],u[s]=r[x+1],d[s]=r[x+2],h[s]=r[x+3]);n.mask=h}}else if(f)if(h!=null)for(s=0;s<i;s++)h[s]&&(m=f[c[s]],p[s]=m[0],u[s]=m[1],d[s]=m[2],h[s]=m[3]);else{for(h=new Uint8Array(i),s=0;s<i;s++)m=f[c[s]],p[s]=m[0],u[s]=m[1],d[s]=m[2],h[s]=m[3];n.mask=h}return n.pixels=[p,u,d],n.statistics=null,n.pixelType="u8",n.maskIsAlpha=l,n}function Ae(t,e){if(!L(t))return null;const{pixels:n,mask:o}=t,h=n.length;let i=e.lut;const{offset:r}=e;i&&i[0].length===1&&(i=n.map(()=>i));const f=[],a=e.outputPixelType||"u8";for(let s=0;s<h;s++){const c=Pt(n[s],o,i[s],r||0,a);f.push(c)}const l=new _({width:t.width,height:t.height,pixels:f,mask:o,pixelType:a});return l.updateStatistics(),l}function Pt(t,e,n,o,h){const i=t.length,r=_.createEmptyBand(h,i);if(e)for(let f=0;f<i;f++)e[f]&&(r[f]=n[t[f]-o]);else for(let f=0;f<i;f++)r[f]=n[t[f]-o];return r}function be(t,e){if(!L(t))return null;const n=t.clone(),{pixels:o}=n,h=n.width*n.height,i=e.length,r=Math.floor(i/2),f=e[Math.floor(r)],a=o[0];let l,s,c,p,u,d,m=!1;const x=new Uint8Array(h),w=new Uint8Array(h),A=new Uint8Array(h);let k=n.mask;const M=e[0].mappedColor.length===4;for(k||(k=new Uint8Array(h),k.fill(M?255:1),n.mask=k),u=0;u<h;u++)if(k[u]){for(l=a[u],m=!1,d=r,s=f,c=0,p=i-1;p-c>1;){if(l===s.value){m=!0;break}l>s.value?c=d:p=d,d=Math.floor((c+p)/2),s=e[Math.floor(d)]}m||(l===e[c].value?(s=e[c],m=!0):l===e[p].value?(s=e[p],m=!0):l<e[c].value?(m=!1,s=null):l>e[c].value&&(l<e[p].value?(s=e[c],m=!0):p===i-1?(m=!1,s=null):(s=e[p],m=!0))),m?(x[u]=s.mappedColor[0],w[u]=s.mappedColor[1],A[u]=s.mappedColor[2],k[u]=s.mappedColor[3]):x[u]=w[u]=A[u]=k[u]=0}return n.pixels=[x,w,A],n.mask=k,n.pixelType="u8",n.maskIsAlpha=M,n}function ve(t,e){if(!L(t))return null;const{width:n,height:o}=t,{inputRanges:h,outputValues:i,outputPixelType:r,noDataRanges:f,allowUnmatched:a,isLastInputRangeInclusive:l}=e,s=t.pixels[0],c=_.createEmptyBand(r,s.length),p=t.mask,u=new Uint8Array(n*o);p?u.set(p):u.fill(255);const d=t.pixelType.startsWith("f")?1e-6:0,m=h.map(M=>M-d);m[0]=h[0],m[m.length-1]=h[h.length-1]+(l?1e-6:0);const x=h.length/2,[w,A]=ht(r);for(let M=0;M<o;M++)for(let g=0;g<n;g++){const y=M*n+g;if(u[y]){const v=s[y];let b=!1;for(let T=x-1;T>=0;T--)if(v===m[2*T]||v>m[2*T]&&v<m[2*T+1]){c[y]=i[T],b=!0;break}b||(a?c[y]=v>A?A:v<w?w:v:u[y]=0)}}const k=f==null?void 0:f.length;if(k)for(let M=0;M<o;M++)for(let g=0;g<n;g++){const y=M*n+g;if(!p||p[y]){const v=s[y];for(let b=0;b<k;b+=2)if(v>=f[b]&&v<=f[b+1]){c[y]=0,u[y]=0;break}}}return new _({width:n,height:o,pixelType:r,pixels:[c],mask:u})}function yt(t,e,n,o){const h=n!=null&&n.length>=2?new Set(n):null,i=(n==null?void 0:n.length)===1?n[0]:null,r=!!(e!=null&&e.length);for(let f=0;f<t.length;f++)if(o[f]){const a=t[f];if(r){let l=!1;for(let s=0;s<e.length;s+=2)if(a>=e[s]&&a<=e[s+1]){l=!0;break}l||(o[f]=0)}o[f]&&(a===i||h!=null&&h.has(a))&&(o[f]=0)}}function kt(t,e){const n=t[0].length;for(let o=0;o<n;o++)if(e[o]){let h=!1;for(let i=0;i<t.length;i++)if(t[i][o]){h=!0;break}h||(e[o]=0)}}function Tt(t,e){const n=t[0].length;for(let o=0;o<n;o++)if(e[o]){let h=!1;for(let i=0;i<t.length;i++)if(t[i][o]===0){h=!0;break}h&&(e[o]=0)}}function Ue(t,e){if(!L(t))return null;const{width:n,height:o,pixels:h}=t,i=n*o,r=new Uint8Array(i);t.mask?r.set(t.mask):r.fill(255);const f=h.length,{includedRanges:a,noDataValues:l,outputPixelType:s,matchAll:c,lookups:p}=e;if(p){const u=[];for(let d=0;d<f;d++){const m=p[d],x=Pt(h[d],r,m.lut,m.offset||0,"u8");u.push(x)}u.length===1?r.set(u[0]):c?kt(u,r):Tt(u,r)}else if(c){const u=[];for(let d=0;d<f;d++){const m=new Uint8Array(i);m.set(r),yt(h[d],a==null?void 0:a.slice(2*d,2*d+2),l==null?void 0:l[d],m),u.push(m)}u.length===1?r.set(u[0]):kt(u,r)}else for(let u=0;u<f;u++)yt(h[u],a==null?void 0:a.slice(2*u,2*u+2),l==null?void 0:l[u],r);return new _({width:n,height:o,pixelType:s,pixels:h,mask:r})}function Pe(t){const{srcPixelType:e,inputRanges:n,outputValues:o,allowUnmatched:h,noDataRanges:i,isLastInputRangeInclusive:r,outputPixelType:f}=t;if(e!=="u8"&&e!=="s8"&&e!=="u16"&&e!=="s16")return null;const a=e.includes("16")?65536:256,l=e.includes("s")?-a/2:0,s=_.createEmptyBand(f,a),c=new Uint8Array(a);h&&c.fill(255);const[p,u]=ht(f);if(n!=null&&n.length&&(o!=null&&o.length)){const m=n.map(x=>x-1e-6);m[0]=n[0],r&&(m[m.length-1]=n[n.length-1]);for(let x=0;x<m.length;x++){const w=o[x]>u?u:o[x]<p?p:o[x],A=Math.ceil(m[2*x]-l),k=Math.floor(m[2*x+1]-l);for(let M=A;M<=k;M++)s[M]=w,c[M]=255}}if(i!=null&&i.length)for(let d=0;d<i.length;d++){const m=Math.ceil(i[2*d]-l),x=Math.floor(i[2*d+1]-l);for(let w=m;w<=x;w++)c[w]=0}return{lut:s,offset:l,mask:c}}function Te(t,e,n){if(t!=="u8"&&t!=="s8"&&t!=="u16"&&t!=="s16")return null;const o=t.includes("16")?65536:256,h=t.includes("s")?-o/2:0,i=new Uint8Array(o);if(e)for(let r=0;r<e.length;r++){const f=Math.ceil(e[2*r]-h),a=Math.floor(e[2*r+1]-h);for(let l=f;l<=a;l++)i[l]=255}else i.fill(255);if(n)for(let r=0;r<n.length;r++)i[n[r]-h]=0;return{lut:i,offset:h}}function zt(t,e,n,o,h,i,r,f){return{xmin:h<=n*t?0:h<n*t+t?h-n*t:t,ymin:i<=o*e?0:i<o*e+e?i-o*e:e,xmax:h+r<=n*t?0:h+r<n*t+t?h+r-n*t:t,ymax:i+f<=o*e?0:i+f<o*e+e?i+f-o*e:e}}function $e(t,e){if(!t||t.length===0)return null;const n=t.find(d=>d.pixelBlock);if((n==null?void 0:n.pixelBlock)==null)return null;const o=(n.extent.xmax-n.extent.xmin)/n.pixelBlock.width,h=(n.extent.ymax-n.extent.ymin)/n.pixelBlock.height,i=.01*Math.min(o,h),r=t.sort((d,m)=>Math.abs(d.extent.ymax-m.extent.ymax)>i?m.extent.ymax-d.extent.ymax:Math.abs(d.extent.xmin-m.extent.xmin)>i?d.extent.xmin-m.extent.xmin:0),f=Math.min.apply(null,r.map(d=>d.extent.xmin)),a=Math.min.apply(null,r.map(d=>d.extent.ymin)),l=Math.max.apply(null,r.map(d=>d.extent.xmax)),s=Math.max.apply(null,r.map(d=>d.extent.ymax)),c={x:Math.round((e.xmin-f)/o),y:Math.round((s-e.ymax)/h)},p={width:Math.round((l-f)/o),height:Math.round((s-a)/h)},u={width:Math.round((e.xmax-e.xmin)/o),height:Math.round((e.ymax-e.ymin)/h)};return Math.round(p.width/n.pixelBlock.width)*Math.round(p.height/n.pixelBlock.height)!==r.length||c.x<0||c.y<0||p.width<u.width||p.height<u.height?null:{extent:e,pixelBlock:Jt(r.map(d=>d.pixelBlock),p,{clipOffset:c,clipSize:u})}}function ft(t,e,n,o,h,i){const{width:r,height:f}=n.block,{x:a,y:l}=n.offset,{width:s,height:c}=n.mosaic,p=zt(r,f,o,h,a,l,s,c);let u=0,d=0;if(i){const m=i.hasGCSSShiftTransform?360:i.halfWorldWidth??0,x=r*i.resolutionX,w=i.startX+o*x;w<m&&w+x>m?d=i.rightPadding:w>=m&&(u=i.leftMargin-i.rightPadding,d=0)}if(p.xmax-=d,typeof e!="number")for(let m=p.ymin;m<p.ymax;m++){const x=(h*f+m-l)*s+(o*r-a)+u,w=m*r;for(let A=p.xmin;A<p.xmax;A++)t[x+A]=e[w+A]}else for(let m=p.ymin;m<p.ymax;m++){const x=(h*f+m-l)*s+(o*r-a)+u;for(let w=p.xmin;w<p.xmax;w++)t[x+w]=e}}function Jt(t,e,n={}){var $;const{clipOffset:o,clipSize:h,alignmentInfo:i,blockWidths:r}=n;if(r)return Ht(t,e,{blockWidths:r});const f=t.find(P=>L(P));if(f==null)return null;const a=h?h.width:e.width,l=h?h.height:e.height,s=f.width,c=f.height,p=e.width/s,u=e.height/c,d={offset:o||{x:0,y:0},mosaic:h||e,block:{width:s,height:c}},m=f.pixelType,x=_.getPixelArrayConstructor(m),w=f.pixels.length,A=[];let k,M;for(let P=0;P<w;P++){M=new x(a*l);for(let U=0;U<u;U++)for(let I=0;I<p;I++){const C=t[U*p+I];L(C)&&(k=C.pixels[P],ft(M,k,d,I,U,i))}A.push(M)}const g=t.some(P=>P==null||P.mask!=null&&P.mask.length>0),y=t.some(P=>(P==null?void 0:P.bandMasks)&&P.bandMasks.length>1),v=g?new Uint8Array(a*l):void 0,b=y?[]:void 0;if(v){for(let P=0;P<u;P++)for(let U=0;U<p;U++){const I=t[P*p+U],C=I!=null?I.mask:null;ft(v,C??(I?255:0),d,U,P,i)}if(b)for(let P=0;P<w;P++){const U=new Uint8Array(a*l);for(let I=0;I<u;I++)for(let C=0;C<p;C++){const S=t[I*p+C],B=(($=S==null?void 0:S.bandMasks)==null?void 0:$[P])??(S==null?void 0:S.mask);ft(U,B??(S?255:0),d,C,I,i)}b.push(U)}}const T=new _({width:a,height:l,pixels:A,pixelType:m,bandMasks:b,mask:v});return T.updateStatistics(),T}function Ht(t,e,n){var x;const o=t.find(w=>w!=null);if(o==null)return null;const h=t.some(w=>w==null||!!w.mask),{width:i,height:r}=e,f=h?new Uint8Array(i*r):null,{blockWidths:a}=n,l=[],s=o.getPlaneCount(),c=_.getPixelArrayConstructor(o.pixelType);if(h)for(let w=0,A=0;w<t.length;A+=a[w],w++){const k=t[w];if(!L(k))continue;const M=k.mask;for(let g=0;g<r;g++)for(let y=0;y<a[w];y++)f[g*i+y+A]=M==null?255:M[g*k.width+y]}const p=t.some(w=>(w==null?void 0:w.bandMasks)&&w.bandMasks.length>1),u=p?[]:void 0,d=i*r;for(let w=0;w<s;w++){const A=new c(d),k=p?new Uint8Array(d):void 0;for(let M=0,g=0;M<t.length;g+=a[M],M++){const y=t[M];if(!L(y))continue;const v=y.pixels[w];if(v!=null){for(let b=0;b<r;b++)for(let T=0;T<a[M];T++)A[b*i+T+g]=v[b*y.width+T];if(k){const b=((x=y.bandMasks)==null?void 0:x[w])??y.mask;for(let T=0;T<r;T++)for(let $=0;$<a[M];$++)k[T*i+$+g]=b?b[T*y.width+$]:255}}}l.push(A),u&&k&&u.push(k)}const m=new _({width:i,height:r,mask:f,bandMasks:u,pixels:l,pixelType:o.pixelType});return m.updateStatistics(),m}function Ie(t,e,n){if(!L(t))return null;const{width:o,height:h}=t,i=e.x,r=e.y,f=n.width+i,a=n.height+r;if(i<0||r<0||f>o||a>h||i===0&&r===0&&f===o&&a===h)return t;t.mask||(t.mask=new Uint8Array(o*h));const l=t.mask;for(let s=0;s<h;s++){const c=s*o;for(let p=0;p<o;p++)l[c+p]=s<r||s>=a||p<i||p>=f?0:1}return t.updateStatistics(),t}function Kt(t){if(!L(t))return null;const e=t.clone(),{width:n,height:o,pixels:h}=t,i=h[0],r=e.pixels[0],f=t.mask;for(let a=2;a<o-1;a++){const l=new Map;for(let c=a-2;c<a+2;c++)for(let p=0;p<4;p++){const u=c*n+p;lt(l,i[u],f?f[u]:1)}r[a*n]=Mt(l),r[a*n+1]=r[a*n+2]=r[a*n];let s=3;for(;s<n-1;s++){let c=(a-2)*n+s+1;lt(l,i[c],f?f[c]:1),c=(a-1)*n+s+1,lt(l,i[c],f?f[c]:1),c=a*n+s+1,lt(l,i[c],f?f[c]:1),c=(a+1)*n+s+1,lt(l,i[c],f?f[c]:1),c=(a-2)*n+s-3,rt(l,i[c],f?f[c]:1),c=(a-1)*n+s-3,rt(l,i[c],f?f[c]:1),c=a*n+s-3,rt(l,i[c],f?f[c]:1),c=(a+1)*n+s-3,rt(l,i[c],f?f[c]:1),r[a*n+s]=Mt(l)}r[a*n+s+1]=r[a*n+s]}for(let a=0;a<n;a++)r[a]=r[n+a]=r[2*n+a],r[(o-1)*n+a]=r[(o-2)*n+a];return e.updateStatistics(),e}function Mt(t){if(t.size===0)return 0;let e=0,n=-1,o=0;const h=t.keys();let i=h.next();for(;!i.done;)o=t.get(i.value),o>e&&(n=i.value,e=o),i=h.next();return n}function rt(t,e,n){if(n===0)return;const o=t.get(e);o===1?t.delete(e):t.set(e,o-1)}function lt(t,e,n){n!==0&&t.set(e,t.has(e)?t.get(e)+1:1)}function Yt(t,e,n){let{x:o,y:h}=e;const{width:i,height:r}=n;if(o===0&&h===0&&r===t.height&&i===t.width)return t;const{width:f,height:a}=t,l=Math.max(0,h),s=Math.max(0,o),c=Math.min(o+i,f),p=Math.min(h+r,a);if(c<0||p<0||!L(t))return null;o=Math.max(0,-o),h=Math.max(0,-h);const{pixels:u}=t,d=i*r,m=u.length,x=[];for(let M=0;M<m;M++){const g=u[M],y=_.createEmptyBand(t.pixelType,d);for(let v=l;v<p;v++){const b=v*f;let T=(v+h-l)*i+o;for(let $=s;$<c;$++)y[T++]=g[b+$]}x.push(y)}const w=new Uint8Array(d),A=t.mask;for(let M=l;M<p;M++){const g=M*f;let y=(M+h-l)*i+o;for(let v=s;v<c;v++)w[y++]=A?A[g+v]:1}const k=new _({width:n.width,height:n.height,pixelType:t.pixelType,pixels:x,mask:w});return k.updateStatistics(),k}function Qt(t,e=!0){if(!L(t))return null;const{pixels:n,width:o,height:h,mask:i,pixelType:r}=t,f=[],a=Math.round(o/2),l=Math.round(h/2),s=h-1,c=o-1;for(let u=0;u<n.length;u++){const d=n[u],m=_.createEmptyBand(r,a*l);let x=0;for(let w=0;w<h;w+=2)for(let A=0;A<o;A+=2){const k=d[w*o+A];if(e){const M=A===c?k:d[w*o+A+1],g=w===s?k:d[w*o+A+o],y=A===c?g:w===s?M:d[w*o+A+o+1];m[x++]=(k+M+g+y)/4}else m[x++]=k}f.push(m)}let p=null;if(i!=null){p=new Uint8Array(a*l);let u=0;for(let d=0;d<h;d+=2)for(let m=0;m<o;m+=2){const x=i[d*o+m];if(e){const w=m===c?x:i[d*o+m+1],A=d===s?x:i[d*o+m+o],k=m===c?A:d===s?w:i[d*o+m+o+1];p[u++]=x*w*A*k?1:0}else p[u++]=x}}return new _({width:a,height:l,pixelType:r,pixels:f,mask:p})}function Be(t,e,n){if(!L(t))return null;const{width:o,height:h}=e;let{width:i,height:r}=t;const f=new Map,a={x:0,y:0},l=n==null?1:1+n;let s=t;for(let c=0;c<l;c++){const p=Math.ceil(i/o),u=Math.ceil(r/h);for(let d=0;d<u;d++){a.y=d*h;for(let m=0;m<p;m++){a.x=m*o;const x=Yt(s,a,e);f.set(`${c}/${d}/${m}`,x)}}c<l-1&&(s=Qt(s)),i=Math.round(i/2),r=Math.round(r/2)}return f}function $t(t,e,n,o,h=0){const{width:i,height:r}=t,{width:f,height:a}=e,l=o.cols,s=o.rows,c=Math.ceil(f/l-.1/l),p=Math.ceil(a/s-.1/s);let u,d,m,x,w,A,k;const M=c*l,g=M*p*s,y=new Float32Array(g),v=new Float32Array(g),b=new Uint32Array(g),T=new Uint32Array(g);let $,P,U=0;for(let I=0;I<p;I++)for(let C=0;C<c;C++){u=12*(I*c+C),d=n[u],m=n[u+1],x=n[u+2],w=n[u+3],A=n[u+4],k=n[u+5];for(let S=0;S<s;S++){U=(I*s+S)*M+C*l,P=(S+.5)/s;for(let B=0;B<S;B++)$=(B+.5)/l,y[U+B]=(d*$+m*P+x)*i+h,v[U+B]=(w*$+A*P+k)*r+h,b[U+B]=Math.floor(y[U+B]),T[U+B]=Math.floor(v[U+B])}u+=6,d=n[u],m=n[u+1],x=n[u+2],w=n[u+3],A=n[u+4],k=n[u+5];for(let S=0;S<s;S++){U=(I*s+S)*M+C*l,P=(S+.5)/s;for(let B=S;B<l;B++)$=(B+.5)/l,y[U+B]=(d*$+m*P+x)*i+h,v[U+B]=(w*$+A*P+k)*r+h,b[U+B]=Math.floor(y[U+B]),T[U+B]=Math.floor(v[U+B])}}return{offsets_x:y,offsets_y:v,offsets_xi:b,offsets_yi:T,gridWidth:M}}function Se(t,e){const{coefficients:n,spacing:o}=e,{offsets_x:h,offsets_y:i,gridWidth:r}=$t(t,t,n,{rows:o[0],cols:o[1]}),{width:f,height:a}=t,l=new Float32Array(f*a),s=180/Math.PI;for(let c=0;c<a;c++)for(let p=0;p<f;p++){const u=c*r+p,d=c===0?u:u-r,m=c===a-1?u:u+r,x=h[d]-h[m],w=i[m]-i[d];if(isNaN(x)||isNaN(w))l[c*f+p]=90;else{let A=Math.atan2(w,x)*s;A=(360+A)%360,l[c*f+p]=A}}return l}function Ce(t,e,n,o,h="nearest"){if(!L(t))return null;h==="majority"&&(t=Kt(t));const{pixels:i,mask:r,bandMasks:f,pixelType:a}=t,l=t.width,s=t.height,c=_.getPixelArrayConstructor(a),p=i.length,{width:u,height:d}=e;let m=!1;for(let U=0;U<n.length;U+=3)n[U]===-1&&n[U+1]===-1&&n[U+2]===-1&&(m=!0);const{offsets_x:x,offsets_y:w,offsets_xi:A,offsets_yi:k,gridWidth:M}=$t({width:l,height:s},e,n,o,h==="majority"?.5:0);let g;const y=(U,I,C,S)=>{const B=U instanceof Float32Array||U instanceof Float64Array?0:.5;for(let F=0;F<d;F++){g=F*M;for(let V=0;V<u;V++){if(x[g]<0||w[g]<0)U[F*u+V]=0;else if(S)U[F*u+V]=I[A[g]+k[g]*l];else{const E=Math.floor(x[g]),q=Math.floor(w[g]),R=Math.ceil(x[g]),O=Math.ceil(w[g]),X=x[g]-E,H=w[g]-q;if(!C||C[E+q*l]&&C[R+q*l]&&C[E+O*l]&&C[R+O*l]){const et=(1-X)*I[E+q*l]+X*I[R+q*l],K=(1-X)*I[E+O*l]+X*I[R+O*l];U[F*u+V]=(1-H)*et+H*K+B}else U[F*u+V]=I[A[g]+k[g]*l]}g++}}},v=[];let b;const T=(f==null?void 0:f.length)===p,$=[];for(let U=0;U<p;U++){if(T){const I=new Uint8Array(u*d);y(I,f[U],f[U],!0),$.push(I)}b=new c(u*d),y(b,i[U],T?f[U]:r,h==="nearest"||h==="majority"),v.push(b)}const P=new _({width:u,height:d,pixelType:a,pixels:v,bandMasks:T?$:void 0});if(r!=null)P.mask=new Uint8Array(u*d),y(P.mask,r,r,!0);else if(m){P.mask=new Uint8Array(u*d);for(let U=0;U<u*d;U++)P.mask[U]=x[U]<0||w[U]<0?0:1}return P.updateStatistics(),P}const tt=new Map;tt.set("meter-per-second",1),tt.set("kilometer-per-hour",.277778),tt.set("knots",.514444),tt.set("feet-per-second",.3048),tt.set("mile-per-hour",.44704);const pt=180/Math.PI,dt=5,at=new Nt({esriMetersPerSecond:"meter-per-second",esriKilometersPerHour:"kilometer-per-hour",esriKnots:"knots",esriFeetPerSecond:"feet-per-second",esriMilesPerHour:"mile-per-hour"});function mt(t,e){return tt.get(t)/tt.get(e)||1}function It(t){return(450-t)%360}function Bt(t,e="geographic"){const[n,o]=t,h=Math.sqrt(n*n+o*o);let i=Math.atan2(o,n)*pt;return i=(360+i)%360,e==="geographic"&&(i=It(i)),[h,i]}function St(t,e="geographic"){let n=t[1];e==="geographic"&&(n=It(n)),n%=360;const o=t[0];return[o*Math.cos(n/pt),o*Math.sin(n/pt)]}function Fe(t,e,n,o="geographic"){if(!L(t)||n==null)return t;const h=e==="vector-magdir"?t.clone():At(t,e),i=h.pixels[1];for(let r=0;r<i.length;r++)i[r]=o==="geographic"?(i[r]+n[r]+270)%360:(i[r]+360-n[r])%360;return e==="vector-magdir"?h:At(h,"vector-magdir")}function At(t,e,n="geographic",o=1){if(!L(t))return t;const{pixels:h,width:i,height:r}=t,f=i*r,a=h[0],l=h[1],s=t.pixelType.startsWith("f")?t.pixelType:"f32",c=_.createEmptyBand(s,f),p=_.createEmptyBand(s,f);let u=0;for(let m=0;m<r;m++)for(let x=0;x<i;x++)e==="vector-uv"?([c[u],p[u]]=Bt([a[u],l[u]],n),c[u]*=o):([c[u],p[u]]=St([a[u],l[u]],n),c[u]*=o,p[u]*=o),u++;const d=new _({pixelType:s,width:t.width,height:t.height,mask:t.mask,validPixelCount:t.validPixelCount,maskIsAlpha:t.maskIsAlpha,pixels:[c,p]});return d.updateStatistics(),d}function Ve(t,e,n=1){if(n===1||!L(t))return t;const o=t.clone(),{pixels:h,width:i,height:r}=o,f=h[0],a=h[1];let l=0;for(let s=0;s<r;s++)for(let c=0;c<i;c++)e==="vector-uv"?(f[l]*=n,a[l]*=n):f[l]*=n,l++;return o.updateStatistics(),o}function _e(t,e,n,o,h){if(h==null||!h.spatialReference.equals(t.spatialReference))return{extent:t,width:Math.round(e/o),height:Math.round(n/o),resolution:t.width/e};const i=h.xmin,r=h.ymax,f=(t.xmax-t.xmin)/e*o,a=(t.ymax-t.ymin)/n*o,l=(f+a)/2;return t.xmin=i+Math.floor((t.xmin-i)/f)*f,t.xmax=i+Math.ceil((t.xmax-i)/f)*f,t.ymin=r+Math.floor((t.ymin-r)/a)*a,t.ymax=r+Math.ceil((t.ymax-r)/a)*a,{extent:t,width:Math.round(t.width/f),height:Math.round(t.height/a),resolution:l}}const Zt=Ct(0,0,0);function Ct(t=0,e=0,n=Math.PI,o=!0){o&&(n=(2*Math.PI-n)%(2*Math.PI));const h=o?-1:1,i=13*h,r=-7*h,f=-2*h,a=-16*h,l=21.75,[s,c]=j(0,e+i,n,l),[p,u]=j(t-5.5,e+r,n,l),[d,m]=j(t+5.5,e+r,n,l),[x,w]=j(t-1.5,e+f,n,l),[A,k]=j(t+1.5,e+f,n,l),[M,g]=j(t-1.5,e+a,n,l),[y,v]=j(t+1.5,e+a,n,l);return[s,c,p,u,x,w,A,k,d,m,M,g,y,v]}function te(t=0,e=Math.PI,n=!0){n&&(e=(2*Math.PI-e)%(2*Math.PI));const o=10,h=n?-1:1,i=5*h,r=20*h,f=25*h,a=45,l=0,s=0,c=2,p=0,u=c*h,d=n?1:-1,m=o/2*d;let[x,w]=[l+m,s-r],[A,k]=[x+c*d,w],[M,g]=[A-p*d,k+u],[y,v]=[l-m,s-f],[b,T]=[y+p*d,v-u],$=Math.ceil(t/dt),P=Math.floor($/10);$-=8*P;const U=[],I=[];for(let X=0;X<$/2;X++,P--){P<=0&&$%2==1&&X===($-1)/2&&(y=l,b=y+p*d,v=(v+w)/2,T=v-u);const[H,et]=j(y,v,e,a);if(P>0){const[K,it]=j(A,v,e,a),[st,D]=j(x,w,e,a);U.push(K),U.push(it),U.push(H),U.push(et),U.push(st),U.push(D)}else{const[K,it]=j(A,k,e,a),[st,D]=j(M,g,e,a),[N,ct]=j(b,T,e,a);I.push(H),I.push(et),I.push(N),I.push(ct),I.push(st),I.push(D),I.push(K),I.push(it)}v+=i,w+=i,k+=i,g+=i,T+=i}const[C,S]=j(l+m,s+r,e,a),B=(o/2+c)*d,[F,V]=j(l+B,s+r,e,a),[E,q]=j(l+m,s-f,e,a),[R,O]=j(l+B,s-f,e,a);return{pennants:U,barbs:I,shaft:[C,S,F,V,E,q,R,O]}}function j(t,e,n,o=1){const h=Math.sqrt(t*t+e*e)/o,i=(2*Math.PI+Math.atan2(e,t))%(2*Math.PI);return[h,(2*Math.PI+i-n)%(2*Math.PI)]}const ot=[0,1,3,6,10,16,21,27,33,40,47,55,63],ee=[0,.5,1,1.5,2],ne=[0,.25,.5,1,1.5,2,2.5,3,3.5,4];function Y(t,e,n,o){const h=mt(o||"knots",n);let i;for(i=1;i<e.length;i++)if(i===e.length-1){if(t<e[i]*h)break}else if(t<=e[i]*h)break;return Math.min(i-1,e.length-2)}function ie(t,e,n,o,h){let i=0;switch(e){case"beaufort_kn":i=Y(t,ot,"knots",n);break;case"beaufort_km":i=Y(t,ot,"kilometer-per-hour",n);break;case"beaufort_ft":i=Y(t,ot,"feet-per-second",n);break;case"beaufort_m":i=Y(t,ot,"meter-per-second",n);break;case"classified_arrow":i=Y(t,h??[],o,n);break;case"ocean_current_m":i=Y(t,ee,"meter-per-second",n);break;case"ocean_current_kn":i=Y(t,ne,"knots",n)}return i}function se(t,e){const{style:n,inputUnit:o,outputUnit:h,breakValues:i}=e,r=at.fromJSON(o),f=at.fromJSON(h),a=7*6,l=15;let s=0,c=0;const{width:p,height:u,mask:d}=t,m=t.pixels[0],x=t.pixels[1],w=d!=null?d.filter(g=>g>0).length:p*u,A=new Float32Array(w*a),k=new Uint32Array(l*w),M=e.invertDirection?Ct(0,0,0,!1):Zt;for(let g=0;g<u;g++)for(let y=0;y<p;y++){const v=g*p+y;if(!d||d[g*p+y]){const b=(x[v]+360)%360/180*Math.PI,T=ie(m[v],n,r,f,i);for(let P=0;P<M.length;P+=2)A[s++]=(y+.5)/p,A[s++]=(g+.5)/u,A[s++]=M[P],A[s++]=M[P+1]+b,A[s++]=T,A[s++]=m[v];const $=7*(s/a-1);k[c++]=$,k[c++]=$+1,k[c++]=$+2,k[c++]=$+0,k[c++]=$+4,k[c++]=$+3,k[c++]=$+0,k[c++]=$+2,k[c++]=$+3,k[c++]=$+2,k[c++]=$+5,k[c++]=$+3,k[c++]=$+5,k[c++]=$+6,k[c++]=$+3}}return{vertexData:A,indexData:k}}const ut=[];function le(t,e){if(ut.length===0)for(let u=0;u<30;u++)ut.push(te(5*u,0,!e.invertDirection));const n=mt(at.fromJSON(e.inputUnit),"knots"),{width:o,height:h,mask:i}=t,r=t.pixels[0],f=t.pixels[1],a=6,l=[],s=[];let c=0,p=0;for(let u=0;u<h;u++)for(let d=0;d<o;d++){const m=u*o+d,x=r[m]*n;if((!i||i[u*o+d])&&x>=dt){const w=(f[m]+360)%360/180*Math.PI,{pennants:A,barbs:k,shaft:M}=ut[Math.min(Math.floor(x/5),29)];if(A.length+k.length===0)continue;let g=l.length/a;const y=(d+.5)/o,v=(u+.5)/h;for(let b=0;b<A.length;b+=2)l[c++]=y,l[c++]=v,l[c++]=A[b],l[c++]=A[b+1]+w,l[c++]=0,l[c++]=x;for(let b=0;b<k.length;b+=2)l[c++]=y,l[c++]=v,l[c++]=k[b],l[c++]=k[b+1]+w,l[c++]=0,l[c++]=x;for(let b=0;b<M.length;b+=2)l[c++]=y,l[c++]=v,l[c++]=M[b],l[c++]=M[b+1]+w,l[c++]=0,l[c++]=x;for(let b=0;b<A.length/6;b++)s[p++]=g,s[p++]=g+1,s[p++]=g+2,g+=3;for(let b=0;b<k.length/8;b++)s[p++]=g,s[p++]=g+1,s[p++]=g+2,s[p++]=g+1,s[p++]=g+2,s[p++]=g+3,g+=4;s[p++]=g+0,s[p++]=g+1,s[p++]=g+2,s[p++]=g+1,s[p++]=g+3,s[p++]=g+2,g+=4}}return{vertexData:new Float32Array(l),indexData:new Uint32Array(s)}}function re(t,e){let o=0,h=0;const{width:i,height:r,mask:f}=t,a=t.pixels[0],l=[],s=[],c=mt(at.fromJSON(e.inputUnit),"knots"),p=e.style==="wind_speed"?dt:Number.MAX_VALUE;for(let u=0;u<r;u++)for(let d=0;d<i;d++){const m=a[u*i+d]*c;if((!f||f[u*i+d])&&m<p){for(let w=0;w<4;w++)l[o++]=(d+.5)/i,l[o++]=(u+.5)/r,l[o++]=w<2?-.5:.5,l[o++]=w%2==0?-.5:.5,l[o++]=0,l[o++]=m;const x=4*(o/24-1);s[h++]=x,s[h++]=x+1,s[h++]=x+2,s[h++]=x+1,s[h++]=x+2,s[h++]=x+3}}return{vertexData:new Float32Array(l),indexData:new Uint32Array(s)}}function De(t,e){return e.style==="simple_scalar"?re(t,e):e.style==="wind_speed"?le(t,e):se(t,e)}function Le(t,e,n,o=[0,0],h=.5){const{width:i,height:r,mask:f}=t,[a,l]=t.pixels,[s,c]=o,p=Math.round((i-s)/n),u=Math.round((r-c)/n),d=p*u,m=new Float32Array(d),x=new Float32Array(d),w=new Uint8Array(d),A=e==="vector-uv";for(let M=0;M<u;M++)for(let g=0;g<p;g++){let y=0;const v=M*p+g,b=Math.max(0,M*n+c),T=Math.max(0,g*n+s),$=Math.min(r,b+n),P=Math.min(i,T+n);for(let U=b;U<$;U++)for(let I=T;I<P;I++){const C=U*i+I;if(!f||f[C]){y++;const S=A?[a[C],l[C]]:[a[C],(360+l[C])%360],[B,F]=A?S:St(S);m[v]+=B,x[v]+=F}}if(y>=($-b)*(P-T)*(1-h)){w[v]=1;const[U,I]=Bt([m[v]/y,x[v]/y]);m[v]=U,x[v]=I}else w[v]=0,m[v]=0,x[v]=0}const k=new _({width:p,height:u,pixels:[m,x],mask:w});return k.updateStatistics(),k}const J=Q.getLogger("esri.views.2d.engine.flow.dataUtils"),oe=10;async function Re(t,e,n,o){const h=performance.now(),i=ae(e,n),r=performance.now(),f=ce(e,i,n.width,n.height),a=performance.now(),l=ue(f,!0),s=performance.now(),c=t==="Streamlines"?pe(l,oe):de(l),p=performance.now();return nt("esri-2d-profiler")&&(J.info("I.1","_createFlowFieldFromData (ms)",Math.round(r-h)),J.info("I.2","_getStreamlines (ms)",Math.round(a-r)),J.info("I.3","createAnimatedLinesData (ms)",Math.round(s-a)),J.info("I.4","create{Streamlines|Particles}Mesh (ms)",Math.round(p-s)),J.info("I.5","createFlowMesh (ms)",Math.round(p-h)),J.info("I.6","Mesh size (bytes)",c.vertexData.buffer.byteLength+c.indexData.buffer.byteLength)),await Promise.resolve(),Et(o),c}function ae(t,e){const n=fe(e.data,e.width,e.height,t.smoothing);return t.interpolate?(o,h)=>{const i=Math.floor(o),r=Math.floor(h);if(i<0||i>=e.width)return[0,0];if(r<0||r>=e.height)return[0,0];const f=o-i,a=h-r,l=i,s=r,c=i<e.width-1?i+1:i,p=r<e.height-1?r+1:r,u=n[2*(s*e.width+l)],d=n[2*(s*e.width+c)],m=n[2*(p*e.width+l)],x=n[2*(p*e.width+c)],w=n[2*(s*e.width+l)+1],A=n[2*(s*e.width+c)+1];return[(u*(1-a)+m*a)*(1-f)+(d*(1-a)+x*a)*f,(w*(1-a)+n[2*(p*e.width+l)+1]*a)*(1-f)+(A*(1-a)+n[2*(p*e.width+c)+1]*a)*f]}:(o,h)=>{const i=Math.round(o),r=Math.round(h);return i<0||i>=e.width||r<0||r>=e.height?[0,0]:[n[2*(r*e.width+i)],n[2*(r*e.width+i)+1]]}}function he(t,e,n,o,h,i,r,f,a){const l=[];let s=n,c=o,p=0,[u,d]=e(s,c);u*=t.velocityScale,d*=t.velocityScale;const m=Math.sqrt(u*u+d*d);let x,w;l.push({x:s,y:c,t:p,speed:m});for(let A=0;A<t.verticesPerLine;A++){let[k,M]=e(s,c);k*=t.velocityScale,M*=t.velocityScale;const g=Math.sqrt(k*k+M*M);if(g<t.minSpeedThreshold)return l;const y=k/g,v=M/g;if(s+=y*t.segmentLength,c+=v*t.segmentLength,p+=t.segmentLength/g,Math.acos(y*x+v*w)>t.maxTurnAngle)return l;if(t.collisions){const b=Math.round(s*a),T=Math.round(c*a);if(b<0||b>r-1||T<0||T>f-1)return l;const $=i[T*r+b];if($!==-1&&$!==h)return l;i[T*r+b]=h}l.push({x:s,y:c,t:p,speed:g}),x=y,w=v}return l}function ce(t,e,n,o){const h=[],i=new Ut,r=1/Math.max(t.lineCollisionWidth,1),f=Math.round(n*r),a=Math.round(o*r),l=new Int32Array(f*a);for(let c=0;c<l.length;c++)l[c]=-1;const s=[];for(let c=0;c<o;c+=t.lineSpacing)for(let p=0;p<n;p+=t.lineSpacing)s.push({x:p,y:c,sort:i.getFloat()});s.sort((c,p)=>c.sort-p.sort);for(const{x:c,y:p}of s)if(i.getFloat()<t.density){const u=he(t,e,c,p,h.length,l,f,a,r);if(u.length<2)continue;h.push(u)}return h}function fe(t,e,n,o){if(o===0)return t;const h=Math.round(3*o),i=new Array(2*h+1);let r=0;for(let l=-h;l<=h;l++){const s=Math.exp(-l*l/(o*o));i[l+h]=s,r+=s}for(let l=-h;l<=h;l++)i[l+h]/=r;const f=new Float32Array(t.length);for(let l=0;l<n;l++)for(let s=0;s<e;s++){let c=0,p=0;for(let u=-h;u<=h;u++){if(s+u<0||s+u>=e)continue;const d=i[u+h];c+=d*t[2*(l*e+(s+u))],p+=d*t[2*(l*e+(s+u))+1]}f[2*(l*e+s)]=c,f[2*(l*e+s)+1]=p}const a=new Float32Array(t.length);for(let l=0;l<e;l++)for(let s=0;s<n;s++){let c=0,p=0;for(let u=-h;u<=h;u++){if(s+u<0||s+u>=n)continue;const d=i[u+h];c+=d*f[2*((s+u)*e+l)],p+=d*f[2*((s+u)*e+l)+1]}a[2*(s*e+l)]=c,a[2*(s*e+l)+1]=p}return a}function ue(t,e){const n=new Ut,o=t.reduce((a,l)=>a+l.length,0),h=new Float32Array(4*o),i=new Array(t.length);let r=0,f=0;for(const a of t){const l=r;for(const s of a)h[4*r]=s.x,h[4*r+1]=s.y,h[4*r+2]=s.t,h[4*r+3]=s.speed,r++;i[f++]={startVertex:l,numberOfVertices:a.length,totalTime:a[a.length-1].t,timeSeed:e?n.getFloat():0}}return{lineVertices:h,lineDescriptors:i}}function pe(t,e){const{lineVertices:o,lineDescriptors:h}=t;let i=0,r=0;for(const u of h)i+=2*u.numberOfVertices,r+=6*(u.numberOfVertices-1);const f=new Float32Array(i*9),a=new Uint32Array(r);let l=0,s=0;function c(){a[s++]=l-2,a[s++]=l,a[s++]=l-1,a[s++]=l,a[s++]=l+1,a[s++]=l-1}function p(u,d,m,x,w,A,k,M){const g=l*9;let y=0;f[g+y++]=u,f[g+y++]=d,f[g+y++]=1,f[g+y++]=m,f[g+y++]=A,f[g+y++]=k,f[g+y++]=x/2,f[g+y++]=w/2,f[g+y++]=M,l++,f[g+y++]=u,f[g+y++]=d,f[g+y++]=-1,f[g+y++]=m,f[g+y++]=A,f[g+y++]=k,f[g+y++]=-x/2,f[g+y++]=-w/2,f[g+y++]=M,l++}for(const u of h){const{totalTime:d,timeSeed:m}=u;let x=null,w=null,A=null,k=null,M=null,g=null;for(let y=0;y<u.numberOfVertices;y++){const v=o[4*(u.startVertex+y)],b=o[4*(u.startVertex+y)+1],T=o[4*(u.startVertex+y)+2],$=o[4*(u.startVertex+y)+3];let P=null,U=null,I=null,C=null;if(y>0){P=v-x,U=b-w;const S=Math.sqrt(P*P+U*U);if(P/=S,U/=S,y>1){let B=P+M,F=U+g;const V=Math.sqrt(B*B+F*F);B/=V,F/=V;const E=Math.min(1/(B*P+F*U),e);B*=E,F*=E,I=-F,C=B}else I=-U,C=P;I!==null&&C!==null&&(p(x,w,A,I,C,d,m,$),c())}x=v,w=b,A=T,M=P,g=U,k=$}p(x,w,A,-g,M,d,m,k)}return{vertexData:f,indexData:a}}function de(t){const{lineVertices:h,lineDescriptors:i}=t;let r=0,f=0;for(const S of i){const B=S.numberOfVertices-1;r+=4*B*2,f+=6*B*2}const a=new Float32Array(r*16),l=new Uint32Array(f);let s,c,p,u,d,m,x,w,A,k,M,g,y,v,b=0,T=0;function $(){l[T++]=b-8,l[T++]=b-7,l[T++]=b-6,l[T++]=b-7,l[T++]=b-5,l[T++]=b-6,l[T++]=b-4,l[T++]=b-3,l[T++]=b-2,l[T++]=b-3,l[T++]=b-1,l[T++]=b-2}function P(S,B,F,V,E,q,R,O,X,H,et,K,it,st){const D=b*16;let N=0;for(const ct of[1,2])for(const Ft of[1,2,3,4])a[D+N++]=S,a[D+N++]=B,a[D+N++]=F,a[D+N++]=V,a[D+N++]=R,a[D+N++]=O,a[D+N++]=X,a[D+N++]=H,a[D+N++]=ct,a[D+N++]=Ft,a[D+N++]=it,a[D+N++]=st,a[D+N++]=E/2,a[D+N++]=q/2,a[D+N++]=et/2,a[D+N++]=K/2,b++}function U(S,B){let F=A+M,V=k+g;const E=Math.sqrt(F*F+V*V);F/=E,V/=E;const q=A*F+k*V;F/=q,V/=q;let R=M+y,O=g+v;const X=Math.sqrt(R*R+O*O);R/=X,O/=X;const H=M*R+g*O;R/=H,O/=H,P(s,c,p,u,-V,F,d,m,x,w,-O,R,S,B),$()}function I(S,B,F,V,E,q){if(A=M,k=g,M=y,g=v,A==null&&k==null&&(A=M,k=g),d!=null&&m!=null){y=S-d,v=B-m;const R=Math.sqrt(y*y+v*v);y/=R,v/=R}A!=null&&k!=null&&U(E,q),s=d,c=m,p=x,u=w,d=S,m=B,x=F,w=V}function C(S,B){A=M,k=g,M=y,g=v,A==null&&k==null&&(A=M,k=g),A!=null&&k!=null&&U(S,B)}for(const S of i){s=null,c=null,p=null,u=null,d=null,m=null,x=null,w=null,A=null,k=null,M=null,g=null,y=null,v=null;const{totalTime:B,timeSeed:F}=S;for(let V=0;V<S.numberOfVertices;V++)I(h[4*(S.startVertex+V)],h[4*(S.startVertex+V)+1],h[4*(S.startVertex+V)+2],h[4*(S.startVertex+V)+3],B,F);C(B,F)}return{vertexData:a,indexData:l}}function bt(t,e){const n=e.pixels,{width:o,height:h}=e,i=new Float32Array(o*h*2),r=e.mask||new Uint8Array(o*h*2);if(e.mask||r.fill(255),t==="vector-uv")for(let f=0;f<o*h;f++)i[2*f]=n[0][f],i[2*f+1]=-n[1][f];else if(t==="vector-magdir")for(let f=0;f<o*h;f++){const a=n[0][f],l=Ot(n[1][f]),s=Math.cos(l-Math.PI/2),c=Math.sin(l-Math.PI/2);i[2*f]=s*a,i[2*f+1]=c*a}return{data:i,mask:r,width:o,height:h}}async function Ne(t,e,n,o,h,i){const r=performance.now(),f=jt(e.spatialReference);if(!f){const M=await vt(t,e,n,o,h,i);return nt("esri-2d-profiler")&&J.info("I.7","loadImagery, early exit (ms)",Math.round(performance.now()-r)),nt("esri-2d-profiler")&&J.info("I.9","Number of parts",1),M}const[a,l]=f.valid,s=l-a,c=Math.ceil(e.width/s),p=e.width/c,u=Math.round(n/c);let d=e.xmin;const m=[],x=performance.now();for(let M=0;M<c;M++){const g=new Gt({xmin:d,xmax:d+p,ymin:e.ymin,ymax:e.ymax,spatialReference:e.spatialReference});m.push(vt(t,g,u,o,h,i)),d+=p}const w=await Promise.all(m);nt("esri-2d-profiler")&&J.info("I.8","All calls to _fetchPart (ms)",Math.round(performance.now()-x)),nt("esri-2d-profiler")&&J.info("I.9","Number of parts",w.length);const A={data:new Float32Array(n*o*2),mask:new Uint8Array(n*o),width:n,height:o};let k=0;for(const M of w){for(let g=0;g<M.height;g++)for(let y=0;y<M.width;y++)k+y>=n||(A.data[2*(g*n+k+y)]=M.data[2*(g*M.width+y)],A.data[2*(g*n+k+y)+1]=M.data[2*(g*M.width+y)+1],A.mask[g*n+k+y]=M.mask[g*M.width+y]);k+=M.width}return nt("esri-2d-profiler")&&J.info("I.10","loadImagery, general exit (ms)",Math.round(performance.now()-r)),A}async function vt(t,e,n,o,h,i){var l;const r={requestProjectedLocalDirections:!0,signal:i};if(h!=null&&(r.timeExtent=h),t.type==="imagery"){await t.load({signal:i});const s=t.rasterInfo.dataType,c=await t.fetchImage(e,n,o,r);return((l=c==null?void 0:c.pixelData)==null?void 0:l.pixelBlock)==null?{data:new Float32Array(n*o*2),mask:new Uint8Array(n*o),width:n,height:o}:bt(s,c.pixelData.pixelBlock)}await t.load({signal:i});const f=t.rasterInfo.dataType,a=await t.fetchPixels(e,n,o,r);return(a==null?void 0:a.pixelBlock)==null?{data:new Float32Array(n*o*2),mask:new Uint8Array(n*o),width:n,height:o}:bt(f,a.pixelBlock)}export{ve as A,Se as I,$e as M,Ce as R,Le as S,Ie as T,Jt as U,Be as W,re as _,Fe as a,De as b,xe as c,at as d,mt as e,At as f,Ne as g,ht as h,Me as i,be as j,Ae as k,Bt as l,_e as m,ke as n,L as o,Ve as p,wt as q,ye as r,Re as s,xt as t,_ as u,we as v,Te as w,Ue as x,Pe as y,Pt as z};
|