UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 3.36 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{throwIfAborted as t}from"../../../../../core/promiseUtils.js";import{timeExtentsEqual as a,setUniforms as e}from"../utils.js";import{BufferObject as r}from"../../../../webgl/BufferObject.js";import{DataType as s,BlendFactor as o,PrimitiveType as i,Usage as n,PixelFormat as m,TextureWrapMode as l}from"../../../../webgl/enums.js";import{Texture as p}from"../../../../webgl/Texture.js";import{TextureDescriptor as c}from"../../../../webgl/TextureDescriptor.js";import{VertexArrayObject as h}from"../../../../webgl/VertexArrayObject.js";import{VertexElementDescriptor as _}from"../../../../webgl/VertexElementDescriptor.js";class f{constructor(t){this._params=t,this.animated=!1}isCompatible(t){if(!(t instanceof f))return!1;if(!a(this._params.timeExtent,t._params.timeExtent))return!1;let e=!0;return e=e&&this._params.loadImagery===t._params.loadImagery,e=e&&this._params.color.kind===t._params.color.kind,e=e&&this._params.opacity.kind===t._params.opacity.kind,e}async load(a,e){const{extent:r,size:s}=a;t(e);const o=await this._params.loadImagery(r,s[0],s[1],this._params.timeExtent,e);return new x(o,{color:this._params.color,opacity:this._params.opacity})}render(t,a,r){const{context:s}=t,{program:n}=r;s.setFaceCullingEnabled(!1),s.setBlendingEnabled(!0),s.setBlendFunction(o.ONE,o.ONE_MINUS_SRC_ALPHA),s.useProgram(n),n.setUniformMatrix3fv("u_dvsMat3",a.dvsMat3),s.bindTexture(r.texture,0),n.setUniform1i("u_texture",0),n.setUniform1f("u_Min",r.min),n.setUniform1f("u_Max",r.max),e(n,"color","vec4",this._params.color),e(n,"opacity","float",this._params.opacity),s.bindVAO(r.vertexArray),s.drawArrays(i.TRIANGLE_STRIP,0,4)}}const d=new Map;d.set("a_position",0),d.set("a_texcoord",1);const w=new Map([["geometry",[new _("a_position",2,s.UNSIGNED_SHORT,0,8),new _("a_texcoord",2,s.UNSIGNED_SHORT,4,8)]]]),u={vsPath:"raster/flow/imagery",fsPath:"raster/flow/imagery",attributes:d};class x{constructor(t,a){this._flowData=t,this._values=a}attach(t){const{context:a}=t,{width:e,height:s}=this._flowData,o=r.createVertex(a,n.STATIC_DRAW,new Uint16Array([0,0,0,1,e,0,1,1,0,s,0,0,e,s,1,0])),i=new Map([["geometry",o]]),_=new h(a,d,w,i),f=[];"ramp"===this._values.color.kind&&f.push("vvColor"),"ramp"===this._values.opacity.kind&&f.push("vvOpacity");const x=t.getProgram(u,f);let y=1e6,g=-1e6;for(let r=0;r<s;r++)for(let t=0;t<e;t++)if(0!==this._flowData.mask[r*e+t]){const a=this._flowData.data[2*(r*e+t)],s=this._flowData.data[2*(r*e+t)+1],o=Math.sqrt(a*a+s*s);y=Math.min(y,o),g=Math.max(g,o)}const A=new Uint8Array(4*e*s);for(let r=0;r<s;r++)for(let t=0;t<e;t++)if(0!==this._flowData.mask[r*e+t]){const a=this._flowData.data[2*(r*e+t)],s=this._flowData.data[2*(r*e+t)+1],o=(Math.sqrt(a*a+s*s)-y)/(g-y);A[4*(r*e+t)]=255*o,A[4*(r*e+t)+1]=0,A[4*(r*e+t)+2]=0,A[4*(r*e+t)+3]=255}else A[4*(r*e+t)]=0,A[4*(r*e+t)+1]=0,A[4*(r*e+t)+2]=0,A[4*(r*e+t)+3]=0;const b=new c;b.internalFormat=m.RGBA,b.wrapMode=l.CLAMP_TO_EDGE,b.flipped=!0,b.width=e,b.height=s;const v=new p(a,b,A);this.vertexArray=_,this.program=x,this.texture=v,this.min=y,this.max=g,this._flowData=null}detach(){this.vertexArray.dispose(),this.texture.dispose()}get ready(){return this.program.compiled}}export{f as Imagery,x as ImageryResources};