UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 3.46 kB
import e from"../../../../core/Error.js";import{on as t}from"../../../../core/events.js";import r from"../../../../core/Logger.js";import{isPowerOfTwo as s}from"../../../../core/mathUtils.js";import{disposeMaybe as i,isSome as o,isNone as n}from"../../../../core/maybe.js";import{getProjectiveTransform as a}from"../../../../core/perspectiveUtils.js";import{watch as m,when as h,initial as c}from"../../../../core/reactiveUtils.js";import{c as p}from"../../../../chunks/mat3f64.js";import{s as l}from"../../../../chunks/vec2.js";import{a as d}from"../../../../chunks/vec2f64.js";import{DisplayObject as u}from"../DisplayObject.js";import{BufferObject as f}from"../../../webgl/BufferObject.js";import{ContextType as g}from"../../../webgl/context-util.js";import{PixelFormat as w,PixelType as y,TextureSamplingMode as v,TextureWrapMode as _,Usage as j}from"../../../webgl/enums.js";import{Texture as x}from"../../../webgl/Texture.js";import{VertexArrayObject as V}from"../../../webgl/VertexArrayObject.js";const b=p();class A extends u{constructor(s){super(),this.elementView=s,this.isWrapAround=!1,this.perspectiveTransform=d(),this._vertices=new Float32Array(20),this._handles=[],this._handles.push(m((()=>this.elementView.element.opacity),(e=>this.opacity=e),c),m((()=>[this.elementView.coords]),(()=>{this.requestRender()}),c),h((()=>this.elementView.element.loaded),(()=>{const e=this.elementView.element;this.ready(),"video"===e.type&&o(e.content)&&this._handles.push(t(e.content,"play",(()=>this.requestRender())))}),c)),s.element.load().catch((t=>{r.getLogger("esri.views.2d.layers.MediaLayerView2D").error(new e("element-load-error","Element cannot be displayed",{element:s,error:t}))}))}destroy(){this._handles.forEach((e=>e.remove())),this.texture=i(this.texture)}get dvsMat3(){return this.parent.dvsMat3}beforeRender(e){const{context:t}=e,r=this.elementView.element.content;if(o(r)){const e=r instanceof HTMLImageElement,i=r instanceof HTMLVideoElement,o=e?r.naturalWidth:i?r.videoWidth:r.width,n=e?r.naturalHeight:i?r.videoHeight:r.height;this._updatePerspectiveTransform(o,n),this.texture?i&&!r.paused&&(this.texture.setData(r),this.requestRender(),(t.type===g.WEBGL2||s(o)&&s(n))&&this.texture.generateMipmap()):(this.texture=new x(t,{pixelFormat:w.RGBA,dataType:y.UNSIGNED_BYTE,samplingMode:v.LINEAR,wrapMode:_.CLAMP_TO_EDGE,width:o,height:n,preMultiplyAlpha:!0},r),(t.type===g.WEBGL2||s(o)&&s(n))&&this.texture.generateMipmap(),i&&!r.paused&&this.requestRender())}super.beforeRender(e)}_createTransforms(){return null}updateDrawCoords(e,t){const r=this.elementView.coords;if(n(r))return;const[s,i,o,a]=r.rings[0],m=this._vertices,{x:h,y:c}=e,p=0!==t;p?m.set([i[0]-h,i[1]-c,s[0]-h,s[1]-c,o[0]-h,o[1]-c,a[0]-h,a[1]-c,a[0]-h,a[1]-c,i[0]+t-h,i[1]-c,i[0]+t-h,i[1]-c,s[0]+t-h,s[1]-c,o[0]+t-h,o[1]-c,a[0]+t-h,a[1]-c]):m.set([i[0]-h,i[1]-c,s[0]-h,s[1]-c,o[0]-h,o[1]-c,a[0]-h,a[1]-c]),this.isWrapAround=p}getVAO(e,t,r){if(n(this.elementView.coords))return null;const s=this._vertices;if(this._vao)this._geometryVbo.setData(s);else{this._geometryVbo=f.createVertex(e,j.DYNAMIC_DRAW,s);const i=f.createVertex(e,j.STATIC_DRAW,new Uint16Array([0,0,0,1,1,0,1,1,1,1,0,0,0,0,0,1,1,0,1,1]));this._vao=new V(e,r,t,{geometry:this._geometryVbo,tex:i})}return this._vao}_updatePerspectiveTransform(e,t){const r=this._vertices;a(b,[0,0,e,0,0,t,e,t],[r[0],r[1],r[4],r[5],r[2],r[3],r[6],r[7]]),l(this.perspectiveTransform,b[6]/b[8]*e,b[7]/b[8]*t)}}export{A as default};