@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 3.02 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import t from"../../../../core/Error.js";import e from"../../../../core/Logger.js";import{getMetersPerUnitForSR as r}from"../../../../core/units.js";import{create as s}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{project as i}from"../../../../geometry/projectionUtils.js";import{convertFromPolygon as n,generalizeOptimizedGeometry as o,convertFromPolyline as c}from"../../../../layers/graphics/featureConversionUtils.js";import{checkProjectionSupport as a}from"../../../../layers/graphics/data/projectionSupport.js";import{triangulateUnsafe as m,triangulateSyncUnsafe as l}from"./mesh/templates/templateUtils.js";import{SimpleMesh as p}from"./meshing/SimpleMesh.js";import{createScreenExtent as h}from"../../support/clippingUtils.js";import{DataType as u,PrimitiveType as y}from"../../../webgl/enums.js";class f{static async create(t,e){const r=await g(t,e);return r?new f(r):null}constructor(t){this._target=t}destroy(){this._mesh?.destroy()}getMesh(t,e){const r=this._target;if(!r)return null;if(null!==this._mesh&&this._lastStateVersion===e.id)return this._mesh;const{vertices:s,indices:i}=r.getTriangulation(e),n=i?new Uint32Array(i):void 0,o=new Int32Array(s);return this._lastStateVersion=e.id,this._mesh?.destroy(),this._mesh=p.createForShader(t,{primitive:y.TRIANGLES,index:n,vertex:o,layout:{pos:{type:u.INT,count:2}}}),this._mesh}}async function g(r,s){switch(r.type){case"rect":return new w(r);case"path":return d.fromPath(r);case"geometry":return _.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}")),null}}class _{static async fromGeometry({geometry:t},e){if(!t)return null;switch(t.type){case"polygon":return this._fromPolygon(t,e);case"extent":return this._fromMapExtent(t)}}static async _fromPolygon(t,e){const s=t.spatialReference??e;await a(s,e);const c=i(t,e),l=r(e),p=n(c,!1,!1),h=o(p,"esriGeometryPolygon",100*l,!1,!1);if(!h)return null;const u=await m(h);return u?new _(u.vertices,u.indices):null}static _fromMapExtent(t){const{xmin:e,ymin:r,xmax:s,ymax:i}=t,n=new Float32Array([e,r,s,r,e,i,e,i,s,r,s,i]),o=new Uint32Array([0,1,2,3,4,5]);return new _(n,o)}constructor(t,e){this._vertices=t,this._indices=e}getTriangulation(t){const e=[],r=s();for(let s=0;s<this._vertices.length/2;s++){const[i,n]=t.toScreen(r,[this._vertices[2*s],this._vertices[2*s+1]]);e.push(i,n)}return{vertices:e,indices:this._indices}}}class d{static fromPath({path:t}){const e=c({paths:t},!1,!1),r=l(e);return r?new d(r.vertices,r.indices):null}constructor(t,e){this._vertices=t,this._indices=e}getTriangulation(t){return{vertices:this._vertices,indices:this._indices}}}class w{constructor(t){this._rect=t}getTriangulation(t){const{xmin:e,xmax:r,ymin:s,ymax:i}=h(this._rect,t.size[0],t.size[1]);return{vertices:[e,s,r,s,e,i,e,i,r,s,r,i],indices:new Uint32Array([0,1,2,3,4,5])}}}export{f as ClipMesh};