UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 3.62 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{disposeMaybe as t}from"../../../../core/maybe.js";import{identity as e,multiply as r,translate as i,scale as s,rotate as o}from"../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/mat3f32.js";import{fromValues as n}from"../../../../core/libs/gl-matrix-2/factories/vec2f32.js";import{fromValues as l}from"../../../../core/libs/gl-matrix-2/factories/vec3f32.js";import{normalizeMapX as f}from"../../../../geometry/support/normalizeUtils.js";import{DisplayObject as m}from"../../engine/DisplayObject.js";import{createProgramDescriptor as c}from"../../engine/webgl/Utils.js";import{BufferObject as u}from"../../../webgl/BufferObject.js";import{BlendFactor as _,PrimitiveType as h,DataType as p,Usage as d}from"../../../webgl/enums.js";import{VertexArrayObject as g}from"../../../webgl/VertexArrayObject.js";const v=Math.PI/180,x=4;class b extends m{constructor(t){super(),this._program=null,this._vao=null,this._vertexBuffer=null,this._indexBuffer=null,this._dvsMat3=a(),this._localOrigin={x:0,y:0},this._getBounds=t}destroy(){this._vao&&(this._vao.dispose(),this._vao=null,this._vertexBuffer=null,this._indexBuffer=null),this._program=t(this._program)}doRender(t){const{context:e}=t,r=this._getBounds();if(r.length<1)return;this._createShaderProgram(e),this._updateMatricesAndLocalOrigin(t),this._updateBufferData(e,r),e.setBlendingEnabled(!0),e.setDepthTestEnabled(!1),e.setStencilWriteMask(0),e.setStencilTestEnabled(!1),e.setBlendFunction(_.ONE,_.ONE_MINUS_SRC_ALPHA),e.setColorMask(!0,!0,!0,!0);const i=this._program;e.bindVAO(this._vao),e.useProgram(i),i.setUniformMatrix3fv("u_dvsMat3",this._dvsMat3),e.gl.lineWidth(1),e.drawElements(h.LINES,8*r.length,p.UNSIGNED_INT,0),e.bindVAO()}_createTransforms(){return{displayViewScreenMat3:a()}}_createShaderProgram(t){if(this._program)return;const e="precision highp float;\n uniform mat3 u_dvsMat3;\n\n attribute vec2 a_position;\n\n void main() {\n mediump vec3 pos = u_dvsMat3 * vec3(a_position, 1.0);\n gl_Position = vec4(pos.xy, 0.0, 1.0);\n }",r="precision mediump float;\n void main() {\n gl_FragColor = vec4(0.75, 0.0, 0.0, 0.75);\n }";this._program=t.programCache.acquire(e,r,y().attributes)}_updateMatricesAndLocalOrigin(t){const{state:a}=t,{displayMat3:m,size:c,resolution:u,pixelRatio:_,rotation:h,viewpoint:p}=a,d=v*h,{x:g,y:x}=p.targetGeometry,b=f(g,a.spatialReference);this._localOrigin.x=b,this._localOrigin.y=x;const y=_*c[0],B=_*c[1],M=u*y,j=u*B,A=e(this._dvsMat3);r(A,A,m),i(A,A,n(y/2,B/2)),s(A,A,l(c[0]/M,-B/j,1)),o(A,A,-d)}_updateBufferData(t,e){const{x:r,y:i}=this._localOrigin,s=2*x*e.length,o=new Float32Array(s),a=new Uint32Array(8*e.length);let n=0,l=0;for(const f of e)f&&(o[2*n]=f[0]-r,o[2*n+1]=f[1]-i,o[2*n+2]=f[0]-r,o[2*n+3]=f[3]-i,o[2*n+4]=f[2]-r,o[2*n+5]=f[3]-i,o[2*n+6]=f[2]-r,o[2*n+7]=f[1]-i,a[l]=n+0,a[l+1]=n+3,a[l+2]=n+3,a[l+3]=n+2,a[l+4]=n+2,a[l+5]=n+1,a[l+6]=n+1,a[l+7]=n+0,n+=4,l+=8);if(this._vertexBuffer?this._vertexBuffer.setData(o.buffer):this._vertexBuffer=u.createVertex(t,d.DYNAMIC_DRAW,o.buffer),this._indexBuffer?this._indexBuffer.setData(a):this._indexBuffer=u.createIndex(t,d.DYNAMIC_DRAW,a),!this._vao){const e=y();this._vao=new g(t,e.attributes,e.bufferLayouts,new Map([["geometry",this._vertexBuffer]]),this._indexBuffer)}}}const y=()=>c("bounds",{geometry:[{location:0,name:"a_position",count:2,type:p.FLOAT}]});export{b as default};