@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 1.97 kB
JavaScript
import t from"../../../../core/Error.js";import e from"../../../../core/Logger.js";import{isSome as r,isNone as s}from"../../../../core/maybe.js";import{watch as i}from"../../../../core/reactiveUtils.js";import{c as o}from"../../../../chunks/mat3f32.js";import{DisplayObject as h}from"../DisplayObject.js";import a from"./Mesh2D.js";import{VertexArrayObject as c}from"../../../webgl/VertexArrayObject.js";const n=t=>parseFloat(t)/100;class m extends h{constructor(t,e){super(),this._clip=e,this._cache={},this.stage=t,this._handle=i((()=>e.version),(()=>this._invalidate())),this.ready()}static fromClipArea(t,e){return new m(t,e)}_destroyGL(){r(this._cache.mesh)&&(this._cache.mesh.destroy(),this._cache.mesh=null),r(this._cache.vao)&&(this._cache.vao.dispose(),this._cache.vao=null)}destroy(){this._destroyGL(),this._handle.remove()}getVAO(t,e,r,i){const[o,h]=e.size;if("geometry"!==this._clip.type&&this._lastWidth===o&&this._lastHeight===h||(this._lastWidth=o,this._lastHeight=h,this._destroyGL()),s(this._cache.vao)){const s=this._createMesh(e,this._clip),o=s.getIndexBuffer(t),h=s.getVertexBuffers(t);this._cache.mesh=s,this._cache.vao=new c(t,r,i,h,o)}return this._cache.vao}_createTransforms(){return{dvs:o()}}_invalidate(){this._destroyGL(),this.requestRender()}_createScreenRect(t,e){const[r,s]=t.size,i="string"==typeof e.left?n(e.left)*r:e.left,o="string"==typeof e.right?n(e.right)*r:e.right,h="string"==typeof e.top?n(e.top)*s:e.top,a="string"==typeof e.bottom?n(e.bottom)*s:e.bottom,c=i,m=h;return{x:c,y:m,width:Math.max(r-o-c,0),height:Math.max(s-a-m,0)}}_createMesh(r,s){switch(s.type){case"rect":return a.fromRect(this._createScreenRect(r,s));case"path":return a.fromPath(s);case"geometry":return a.fromGeometry(r,s);default:return e.getLogger("esri.views.2d.engine.webgl.ClippingInfo").error(new t("mapview-bad-type","Unable to create ClippingInfo mesh from clip of type: ${clip.type}")),a.fromRect({x:0,y:0,width:1,height:1})}}}export{m as default};