UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 1.87 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import e from"../../../../core/Error.js";import t from"../../../../core/Logger.js";import{watch as r}from"../../../../core/reactiveUtils.js";import{create as s}from"../../../../core/libs/gl-matrix-2/factories/mat3f32.js";import{DisplayObject as i}from"../DisplayObject.js";import a from"./Mesh2D.js";import{createScreenExtent as o}from"../../support/clippingUtils.js";import{VertexArrayObject as h}from"../../../webgl/VertexArrayObject.js";class c extends i{constructor(e,t){super(),this._clip=t,this._cache={},this.stage=e,this._handle=r((()=>t.version),(()=>this._invalidate())),this.ready()}static fromClipArea(e,t){return new c(e,t)}_destroyGL(){null!=this._cache.mesh&&(this._cache.mesh.destroy(),this._cache.mesh=null),null!=this._cache.vao&&(this._cache.vao.dispose(),this._cache.vao=null)}destroy(){this._destroyGL(),this._handle.remove()}getVAO(e,t,r,s){const[i,a]=t.size;if("geometry"!==this._clip.type&&this._lastWidth===i&&this._lastHeight===a||(this._lastWidth=i,this._lastHeight=a,this._destroyGL()),null==this._cache.vao){const i=this._createMesh(t,this._clip),a=i.getIndexBuffer(e),o=i.getVertexBuffers(e);this._cache.mesh=i,this._cache.vao=new h(e,r,s,o,a)}return this._cache.vao}_createTransforms(){return{displayViewScreenMat3:s()}}_invalidate(){this._destroyGL(),this.requestRender()}_createMesh(r,s){switch(s.type){case"rect":return a.fromScreenExtent(o(s,r.size[0],r.size[1]));case"path":return a.fromPath(s);case"geometry":return a.fromGeometry(r,s);default:return t.getLogger("esri.views.2d.engine.webgl.ClippingInfo").error(new e("mapview-bad-type","Unable to create ClippingInfo mesh from clip of type: ${clip.type}")),a.fromScreenExtent({xmin:0,ymin:0,xmax:1,ymax:1})}}}export{c as default};