@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 3.89 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import s from"../../../core/Logger.js";import t from"../../../core/PooledArray.js";import{create as e}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{WorkerHandle as o}from"../../../core/workers/WorkerHandle.js";import{canProjectWithoutEngine as r}from"../../../geometry/projectionUtils.js";import n from"../../../geometry/SpatialReference.js";import{projectVectorToVector as i}from"../../../geometry/projection/projectVectorToVector.js";class h{constructor(s,t,e,o,r,n){this.layout=s,this.interleavedVertexData=t,this.indices=e,this.hasColors=o,this.hasModifications=r,this.positionData=n}}class a{constructor(s,t,e,o,r,n,i){this.componentOffsets=s,this.featureIds=t,this.anchorIds=e,this.anchors=o,this.transformedGeometry=r,this.globalTrafo=n,this.obb=i}}class c extends o{constructor(s){super("SceneLayerWorker","process",{process:s=>[s.geometryBuffer],project:s=>[s.positions.buffer],transformNormals:s=>[s.normals.buffer]},s,{hasInitialize:!0})}setModifications(s,t,e){const o={context:s,modifications:t,isGeodetic:e};return this.broadcast(o,"setModifications")}setLegacySchema(s,t){const e=JSON.stringify(t);return this.broadcast({context:s,jsonSchema:e},"setLegacySchema")}destroyContext(s){return this.broadcast(s,"destroyContext")}async destroyContextAndSelf(s){await this.destroyContext(s),this.destroy()}project(s,t){return this.invokeMethod("project",s,t)}transformNormals(s,t){return this.invokeMethod("transformNormals",s,t)}}const p=new t({deallocator:null}),l=e();function u(t,e,o){p.clear();let n=1/0,h=1/0,a=-1/0,c=-1/0,u=!1;for(const g of e){const t="clip"===g.type?2:"mask"===g.type?1:0,e=g.geometry;let f=s=>s;if(e.spatialReference){if(!r(e.spatialReference,o)){s.getLogger("esri.views.3d.layers.SceneLayerWorkerHandle").warn("im-modification-projection-failed","Can't project modification polygon into layer spatial reference, ignoring modification",{polygon:e});continue}f=s=>(i(s,e.spatialReference,l,o),l)}u=u||1===t;const m=e.rings.length,d=e.rings.some(s=>s.length<3);if(0===m||d)s.getLogger("esri.views.3d.layers.SceneLayerWorkerHandle").warn("im-modification-invalid-polygon","Ignoring invalid modification polygon (no rings or rings with less than 3 vertices).",{polygon:e});else{p.push(t),p.push(m);for(const s of e.rings){p.push(s.length);for(const t of s){const s=f(t);p.push(s[0]),p.push(s[1]),p.push(s[2]??0),n=Math.min(n,s[0]),h=Math.min(h,s[1]),a=Math.max(a,s[0]),c=Math.max(c,s[1])}}}}if(null!=t)if(u){const s=1e-4;p.push(2),p.push(2),p.push(4),p.push(n-s),p.push(h-s),p.push(0),p.push(a+s),p.push(h-s),p.push(0),p.push(a+s),p.push(c+s),p.push(0),p.push(n-s),p.push(c+s),p.push(0),p.push(4),p.push(t[0]),p.push(t[1]),p.push(0),p.push(t[2]),p.push(t[1]),p.push(0),p.push(t[2]),p.push(t[3]),p.push(0),p.push(t[0]),p.push(t[3]),p.push(0)}else p.push(1),p.push(1),p.push(4),p.push(t[0]),p.push(t[1]),p.push(0),p.push(t[2]),p.push(t[1]),p.push(0),p.push(t[2]),p.push(t[3]),p.push(0),p.push(t[0]),p.push(t[3]),p.push(0);p.push(3);const f=new Float64Array(p.length);for(let s=0;s<p.length;++s)f[s]=p.at(s);return f}function f(s,t){let e=0;for(const o of t){const t=o.geometry,r=t.rings.length,n=t.rings.some(s=>s.length<3);if(0!==r&&!n){e+=1,e+=1;for(let o=0;o<t.rings.length;++o){const r=t.rings[o];e+=1;for(let n=0;n<r.length;++n){const r=[s[e+0],s[e+1],s[e+2]];e+=3,t.setPoint(o,n,r)}}}}}function g(s,t){let e=0,o=t.geometry;const r=o.rings.length,i=o.rings.some(s=>s.length<3);if(0===r||i)return null;o=o.clone(),o.spatialReference=n.WGS84,e+=1,e+=1;for(let n=0;n<o.rings.length;++n){const t=o.rings[n];e+=1;for(let r=0;r<t.length;++r){const t=[s[e+0],s[e+1],s[e+2]];e+=3,o.setPoint(n,r,t)}}return o}export{c as SceneLayerWorkerHandle,a as TransformedData,h as TransformedGeometry,f as fromWasmModificationInLoad,g as fromWasmModificationInSave,u as toWasmModification};