UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) • 7.76 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{JSONMap as t}from"../../../core/jsonMap.js";import{isValidPixelBlock as e}from"./pixelUtils.js";import n from"../../support/PixelBlock.js";const r=new Map;r.set("meter-per-second",1),r.set("kilometer-per-hour",.277778),r.set("knots",.514444),r.set("feet-per-second",.3048),r.set("mile-per-hour",.44704);const o=180/Math.PI,i=5,s=new t({esriMetersPerSecond:"meter-per-second",esriKilometersPerHour:"kilometer-per-hour",esriKnots:"knots",esriFeetPerSecond:"feet-per-second",esriMilesPerHour:"mile-per-hour"});function a(t,e){return r.get(t)/r.get(e)||1}function h(t){return(450-t)%360}function l(t,e="geographic"){const[n,r]=t,i=Math.sqrt(n*n+r*r);let s=Math.atan2(r,n)*o;return s=(360+s)%360,"geographic"===e&&(s=h(s)),[i,s]}function c(t,e="geographic"){let n=t[1];"geographic"===e&&(n=h(n)),n%=360;const r=t[0];return[r*Math.cos(n/o),r*Math.sin(n/o)]}function u(t,n,r,o="geographic"){if(!e(t)||null==r)return t;const i="vector-magdir"===n?t.clone():f(t,n),s=i.pixels[1];for(let e=0;e<s.length;e++)s[e]="geographic"===o?(s[e]+r[e]+270)%360:(s[e]+360-r[e])%360;return"vector-magdir"===n?i:f(i,"vector-magdir")}function f(t,r,o="geographic",i=1){if(!e(t))return t;const{pixels:s,width:a,height:h}=t,u=a*h,f=s[0],p=s[1],m=t.pixelType.startsWith("f")?t.pixelType:"f32",d=n.createEmptyBand(m,u),g=n.createEmptyBand(m,u);let x=0;for(let e=0;e<h;e++)for(let t=0;t<a;t++)"vector-uv"===r?([d[x],g[x]]=l([f[x],p[x]],o),d[x]*=i):([d[x],g[x]]=c([f[x],p[x]],o),d[x]*=i,g[x]*=i),x++;const M=new n({pixelType:m,width:t.width,height:t.height,mask:t.mask,validPixelCount:t.validPixelCount,maskIsAlpha:t.maskIsAlpha,pixels:[d,g]});return M.updateStatistics(),M}function p(t,n,r=1){if(1===r||!e(t))return t;const o=t.clone(),{pixels:i,width:s,height:a}=o,h=i[0],l=i[1];let c=0;for(let e=0;e<a;e++)for(let t=0;t<s;t++)"vector-uv"===n?(h[c]*=r,l[c]*=r):h[c]*=r,c++;return o.updateStatistics(),o}function m(t,e,n,r,o){if(null==o||!o.spatialReference.equals(t.spatialReference))return{extent:t,width:Math.round(e/r),height:Math.round(n/r),resolution:t.width/e};const i=o.xmin,s=o.ymax,a=(t.xmax-t.xmin)/e*r,h=(t.ymax-t.ymin)/n*r,l=(a+h)/2;return t.xmin=i+Math.floor((t.xmin-i)/a)*a,t.xmax=i+Math.ceil((t.xmax-i)/a)*a,t.ymin=s+Math.floor((t.ymin-s)/h)*h,t.ymax=s+Math.ceil((t.ymax-s)/h)*h,{extent:t,width:Math.round(t.width/a),height:Math.round(t.height/h),resolution:l}}const d=g(0,0,0);function g(t=0,e=0,n=Math.PI,r=!0){r&&(n=(2*Math.PI-n)%(2*Math.PI));const o=r?-1:1,i=13*o,s=-7*o,a=-2*o,h=-16*o,l=21.75,[c,u]=M(0,e+i,n,l),[f,p]=M(t-5.5,e+s,n,l),[m,d]=M(t+5.5,e+s,n,l),[g,x]=M(t-1.5,e+a,n,l),[k,w]=M(t+1.5,e+a,n,l),[y,P]=M(t-1.5,e+h,n,l),[b,v]=M(t+1.5,e+h,n,l);return[c,u,f,p,g,x,k,w,m,d,y,P,b,v]}function x(t=0,e=Math.PI,n=!0){n&&(e=(2*Math.PI-e)%(2*Math.PI));const r=10,o=n?-1:1,s=5*o,a=20*o,h=25*o,l=45,c=0,u=0,f=2,p=0,m=f*o,d=n?1:-1,g=r/2*d;let[x,k]=[c+g,u-a],[w,y]=[x+f*d,k],[P,b]=[w-p*d,y+m],[v,I]=[c-g,u-h],[A,_]=[v+p*d,I-m],U=Math.ceil(t/i),S=Math.floor(U/10);U-=8*S;const D=[],F=[];for(let i=0;i<U/2;i++,S--){S<=0&&U%2==1&&i===(U-1)/2&&(v=c,A=v+p*d,I=(I+k)/2,_=I-m);const[t,n]=M(v,I,e,l);if(S>0){const[r,o]=M(w,I,e,l),[i,s]=M(x,k,e,l);D.push(r),D.push(o),D.push(t),D.push(n),D.push(i),D.push(s)}else{const[r,o]=M(w,y,e,l),[i,s]=M(P,b,e,l),[a,h]=M(A,_,e,l);F.push(t),F.push(n),F.push(a),F.push(h),F.push(i),F.push(s),F.push(r),F.push(o)}I+=s,k+=s,y+=s,b+=s,_+=s}const[N,j]=M(c+g,u+a,e,l),J=(r/2+f)*d,[O,q]=M(c+J,u+a,e,l),[B,E]=M(c+g,u-h,e,l),[T,C]=M(c+J,u-h,e,l);return{pennants:D,barbs:F,shaft:[N,j,O,q,B,E,T,C]}}function M(t,e,n,r=1){const o=Math.sqrt(t*t+e*e)/r,i=(2*Math.PI+Math.atan2(e,t))%(2*Math.PI);return[o,(2*Math.PI+i-n)%(2*Math.PI)]}const k=[0,1,3,6,10,16,21,27,33,40,47,55,63],w=[0,.5,1,1.5,2],y=[0,.25,.5,1,1.5,2,2.5,3,3.5,4];function P(t,e,n,r){const o=a(r||"knots",n);let i;for(i=1;i<e.length;i++)if(i===e.length-1){if(t<e[i]*o)break}else if(t<=e[i]*o)break;return Math.min(i-1,e.length-2)}function b(t,e,n,r,o){let i=0;switch(e){case"beaufort_kn":i=P(t,k,"knots",n);break;case"beaufort_km":i=P(t,k,"kilometer-per-hour",n);break;case"beaufort_ft":i=P(t,k,"feet-per-second",n);break;case"beaufort_m":i=P(t,k,"meter-per-second",n);break;case"classified_arrow":i=P(t,o??[],r,n);break;case"ocean_current_m":i=P(t,w,"meter-per-second",n);break;case"ocean_current_kn":i=P(t,y,"knots",n)}return i}function v(t,e){const{style:n,inputUnit:r,outputUnit:o,breakValues:i}=e,a=s.fromJSON(r),h=s.fromJSON(o),l=7*6,c=15;let u=0,f=0;const{width:p,height:m,mask:x}=t,M=t.pixels[0],k=t.pixels[1],w=null!=x?x.filter(t=>t>0).length:p*m,y=new Float32Array(w*l),P=new Uint32Array(c*w),v=e.invertDirection?g(0,0,0,!1):d;for(let s=0;s<m;s++)for(let t=0;t<p;t++){const e=s*p+t;if(!x||x[s*p+t]){const r=(k[e]+360)%360/180*Math.PI,o=b(M[e],n,a,h,i);for(let n=0;n<v.length;n+=2)y[u++]=(t+.5)/p,y[u++]=(s+.5)/m,y[u++]=v[n],y[u++]=v[n+1]+r,y[u++]=o,y[u++]=M[e];const c=7*(u/l-1);P[f++]=c,P[f++]=c+1,P[f++]=c+2,P[f++]=c+0,P[f++]=c+4,P[f++]=c+3,P[f++]=c+0,P[f++]=c+2,P[f++]=c+3,P[f++]=c+2,P[f++]=c+5,P[f++]=c+3,P[f++]=c+5,P[f++]=c+6,P[f++]=c+3}}return{vertexData:y,indexData:P}}const I=[];function A(t,e){if(0===I.length)for(let i=0;i<30;i++)I.push(x(5*i,0,!e.invertDirection));const n=a(s.fromJSON(e.inputUnit),"knots"),{width:r,height:o,mask:h}=t,l=t.pixels[0],c=t.pixels[1],u=6,f=[],p=[];let m=0,d=0;for(let s=0;s<o;s++)for(let t=0;t<r;t++){const e=s*r+t,a=l[e]*n;if((!h||h[s*r+t])&&a>=i){const n=(c[e]+360)%360/180*Math.PI,{pennants:i,barbs:h,shaft:l}=I[Math.min(Math.floor(a/5),29)];if(i.length+h.length===0)continue;let g=f.length/u;const x=(t+.5)/r,M=(s+.5)/o;for(let t=0;t<i.length;t+=2)f[m++]=x,f[m++]=M,f[m++]=i[t],f[m++]=i[t+1]+n,f[m++]=0,f[m++]=a;for(let t=0;t<h.length;t+=2)f[m++]=x,f[m++]=M,f[m++]=h[t],f[m++]=h[t+1]+n,f[m++]=0,f[m++]=a;for(let t=0;t<l.length;t+=2)f[m++]=x,f[m++]=M,f[m++]=l[t],f[m++]=l[t+1]+n,f[m++]=0,f[m++]=a;for(let t=0;t<i.length/6;t++)p[d++]=g,p[d++]=g+1,p[d++]=g+2,g+=3;for(let t=0;t<h.length/8;t++)p[d++]=g,p[d++]=g+1,p[d++]=g+2,p[d++]=g+1,p[d++]=g+2,p[d++]=g+3,g+=4;p[d++]=g+0,p[d++]=g+1,p[d++]=g+2,p[d++]=g+1,p[d++]=g+3,p[d++]=g+2,g+=4}}return{vertexData:new Float32Array(f),indexData:new Uint32Array(p)}}function _(t,e){const n=4*6;let r=0,o=0;const{width:h,height:l,mask:c}=t,u=t.pixels[0],f=[],p=[],m=a(s.fromJSON(e.inputUnit),"knots"),d="wind_speed"===e.style?i:Number.MAX_VALUE;for(let i=0;i<l;i++)for(let t=0;t<h;t++){const e=u[i*h+t]*m;if((!c||c[i*h+t])&&e<d){for(let n=0;n<4;n++)f[r++]=(t+.5)/h,f[r++]=(i+.5)/l,f[r++]=n<2?-.5:.5,f[r++]=n%2==0?-.5:.5,f[r++]=0,f[r++]=e;const s=4*(r/n-1);p[o++]=s,p[o++]=s+1,p[o++]=s+2,p[o++]=s+1,p[o++]=s+2,p[o++]=s+3}}return{vertexData:new Float32Array(f),indexData:new Uint32Array(p)}}function U(t,e){return"simple_scalar"===e.style?_(t,e):"wind_speed"===e.style?A(t,e):v(t,e)}function S(t,e,r,o=[0,0],i=.5){const{width:s,height:a,mask:h}=t,[u,f]=t.pixels,[p,m]=o,d=Math.round((s-p)/r),g=Math.round((a-m)/r),x=d*g,M=new Float32Array(x),k=new Float32Array(x),w=new Uint8Array(x),y="vector-uv"===e;for(let n=0;n<g;n++)for(let t=0;t<d;t++){let e=0;const o=n*d+t,g=Math.max(0,n*r+m),x=Math.max(0,t*r+p),P=Math.min(a,g+r),b=Math.min(s,x+r);for(let t=g;t<P;t++)for(let n=x;n<b;n++){const r=t*s+n;if(!h||h[r]){e++;const t=y?[u[r],f[r]]:[u[r],(360+f[r])%360],[n,i]=y?t:c(t);M[o]+=n,k[o]+=i}}if(e>=(P-g)*(b-x)*(1-i)){w[o]=1;const[t,n]=l([M[o]/e,k[o]/e]);M[o]=t,k[o]=n}else w[o]=0,M[o]=0,k[o]=0}const P=new n({width:d,height:g,pixels:[M,k],mask:w});return P.updateStatistics(),P}export{u as convertToLocalDirections,f as convertVectorFieldData,p as convertVectorFieldUnit,U as createVFMeshData,_ as createVFScalarData,a as getUnitConversionFactor,S as sampleVectorField,m as snapImageToSymbolTile,s as unitKebabDict,l as uvComponentToVector};