@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 3.44 kB
JavaScript
import"../../../../core/has.js";import{isSome as t,isNone as e}from"../../../../core/maybe.js";import{g as s,h as a,r,k as i,m as o}from"../../../../chunks/mat3.js";import{c as n}from"../../../../chunks/mat3f32.js";import{f as l}from"../../../../chunks/vec2f32.js";import{createVFMesh as c,createVFMeshScalar as h}from"../../../../layers/support/rasterFunctions/vectorFieldUtils.js";import{DisplayObject as m}from"../DisplayObject.js";import{createProgramDescriptor as u}from"../webgl/Utils.js";import{BufferObject as d}from"../../../webgl/BufferObject.js";import{Usage as v,DataType as f}from"../../../webgl/enums.js";import{VertexArrayObject as _}from"../../../webgl/VertexArrayObject.js";class y extends m{constructor(t=null){super(),this._source=null,this._symbolizerParameters=null,this._vaoInvalidated=!0,this.coordScale=[1,1],this.height=null,this.key=null,this.offset=null,this.stencilRef=0,this.resolution=null,this.pixelRatio=1,this.x=0,this.y=0,this.rotation=0,this.rawPixelData=null,this.vaoData=null,this.width=null,this.source=t}destroy(){t(this.vaoData)&&(this.vaoData.magdir?.vao.dispose(),this.vaoData.scalar?.vao.dispose(),this.vaoData=null)}get symbolizerParameters(){return this._symbolizerParameters}set symbolizerParameters(t){JSON.stringify(this._symbolizerParameters)!==JSON.stringify(t)&&(this._symbolizerParameters=t,this.invalidateVAO())}get source(){return this._source}set source(t){this._source=t,this.invalidateVAO()}invalidateVAO(){!this._vaoInvalidated&&t(this.vaoData)&&(this.vaoData.magdir?.vao.dispose(),this.vaoData.scalar?.vao.dispose(),this.vaoData=null,this._vaoInvalidated=!0,this.requestRender())}updateVectorFieldVAO(s){if(this._vaoInvalidated){if(this._vaoInvalidated=!1,t(this.source)&&e(this.vaoData)){const{style:t}=this.symbolizerParameters;switch(t){case"beaufort_ft":case"beaufort_km":case"beaufort_kn":case"beaufort_m":case"beaufort_mi":case"classified_arrow":case"ocean_current_kn":case"ocean_current_m":case"single_arrow":{const t=c(this.source,this.symbolizerParameters),e=this._createVectorFieldVAO(s.context,t);this.vaoData={magdir:e}}break;case"simple_scalar":{const t=h(this.source,this.symbolizerParameters),e=this._createVectorFieldVAO(s.context,t);this.vaoData={scalar:e}}break;case"wind_speed":{const t=c(this.source,this.symbolizerParameters),e=this._createVectorFieldVAO(s.context,t),a=h(this.source,this.symbolizerParameters),r=this._createVectorFieldVAO(s.context,a);this.vaoData={magdir:e,scalar:r}}}}this.ready(),this.requestRender()}}_createTransforms(){return{dvs:n()}}setTransform(t){const e=s(this.transforms.dvs),[n,c]=t.toScreenNoRotation([0,0],[this.x,this.y]),h=this.resolution/this.pixelRatio/t.resolution,m=h*this.width,u=h*this.height,d=Math.PI*this.rotation/180;a(e,e,l(n,c)),a(e,e,l(m/2,u/2)),r(e,e,-d),a(e,e,l(-m/2,-u/2)),i(e,e,l(m,u)),o(this.transforms.dvs,t.displayViewMat3,e)}onAttach(){this.invalidateVAO()}onDetach(){this.invalidateVAO()}_createVectorFieldVAO(t,e){const{vertexData:s,indexData:a}=e,r=d.createVertex(t,v.STATIC_DRAW,new Float32Array(s)),i=d.createIndex(t,v.STATIC_DRAW,new Uint32Array(a)),o=u("vector-field",{geometry:[{location:0,name:"a_pos",count:2,type:f.FLOAT,normalized:!1},{location:1,name:"a_offset",count:2,type:f.FLOAT,normalized:!1},{location:2,name:"a_vv",count:2,type:f.FLOAT,normalized:!1}]});return{vao:new _(t,o.attributes,o.bufferLayouts,{geometry:r},i),elementCount:a.length}}}export{y as RasterVFDisplayObject};