@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 3.65 kB
JavaScript
import{_ as e}from"../../../../../chunks/tslib.es6.js";import{isNone as t,unwrapOr as s}from"../../../../../core/maybe.js";import{throwIfAborted as o}from"../../../../../core/promiseUtils.js";import"../../../../../core/Logger.js";import"../../../../../core/accessorSupport/ensureType.js";import"../../../../../core/arrayUtils.js";import"../../../../../core/Error.js";import"../../../../../core/has.js";import{subclass as i}from"../../../../../core/accessorSupport/decorators/subclass.js";import{a as n,i as r}from"../../../../../chunks/vec3.js";import{c as d,a as c}from"../../../../../chunks/vec3f64.js";import{create as a,fromPoints as p,projectPoint as m}from"../../../../../geometry/support/lineSegment.js";import{g as h,m as u}from"../../../../../chunks/sphere.js";import{SnappingTypes as g}from"../../../../../layers/graphics/data/QueryEngineResult.js";import l from"../../../../3d/webgl-engine/lib/Octree.js";import{extractComponentsEdgeLocationsLayout as _}from"../../../../3d/webgl-engine/lib/edgeRendering/edgeProcessing.js";import{MAX_CANDIDATE_COUNT as f,boundsFromEdge as b}from"./sceneLayerSnappingUtils.js";let j=class{constructor(){this._idToComponent=new Map,this._components=new l((e=>e.bounds)),this._edges=new l((e=>e.bounds)),this._tmpLineSegment=a(),this._tmpP1=d(),this._tmpP2=d(),this._tmpP3=d(),this.remoteClient=null}async fetchCandidates(e,t){await Promise.resolve(),o(t),await this._ensureEdgeLocations(e,t);const s=[];return this._edges.forEachNeighbor((t=>(this._addCandidates(e,t,s),s.length<f)),e.bounds),{result:{candidates:s}}}async _ensureEdgeLocations(e,o){const i=[];if(this._components.forEachNeighbor((e=>{if(t(e.info)){const{id:t,uid:s}=e;i.push({id:t,uid:s})}return!0}),e.bounds),!i.length)return;const n={components:i},r=await this.remoteClient.invoke("fetchAllEdgeLocations",n,s(o,{}));for(const t of r.components)this._setFetchEdgeLocations(t)}async add(e){const t=new E(e.id,e.bounds);return this._idToComponent.set(t.id,t),this._components.add([t]),{result:{}}}async remove(e){const t=this._idToComponent.get(e.id);if(t){const e=[];this._edges.forEachNeighbor((s=>(s.component===t&&e.push(s),!0)),t.bounds),this._edges.remove(e),this._components.remove([t]),this._idToComponent.delete(t.id)}return{result:{}}}_setFetchEdgeLocations(e){const s=this._idToComponent.get(e.id);if(t(s)||e.uid!==s.uid)return;const o=_.createView(e.locations),i=new Array(o.count),n=d(),r=d();for(let t=0;t<o.count;t++){o.position0.getVec(t,n),o.position1.getVec(t,r);const d=b(n,r,e.origin),c=new C(s,t,d);i[t]=c}this._edges.add(i);const{objectIds:c,origin:a}=e;s.info={locations:o,objectIds:c,origin:a}}_addCandidates(e,t,s){const{info:o}=t.component,{origin:i,objectIds:r}=o,d=o.locations,c=d.position0.getVec(t.index,this._tmpP1),a=d.position1.getVec(t.index,this._tmpP2);n(c,c,i),n(a,a,i);const p=r[d.componentIndex.get(t.index)];this._addEdgeCandidate(e,p,c,a,s),this._addVertexCandidate(e,p,c,s),this._addVertexCandidate(e,p,a,s)}_addEdgeCandidate(e,t,s,o,i){if(!(e.types&g.EDGE))return;const n=h(e.bounds),d=p(s,o,this._tmpLineSegment),a=m(d,n,this._tmpP3);u(e.bounds,a)&&i.push({type:"edge",objectId:t,target:c(a),distance:r(n,a),start:c(s),end:c(o)})}_addVertexCandidate(e,t,s,o){if(!(e.types&g.VERTEX))return;const i=h(e.bounds);u(e.bounds,s)&&o.push({type:"vertex",objectId:t,target:c(s),distance:r(i,s)})}};j=e([i("esri.views.interactive.snapping.featureSources.sceneLayerSource.SceneLayerSnappingSourceWorker")],j);const y=j;class E{constructor(e,t){this.id=e,this.bounds=t,this.info=null,this.uid=++E.uid}}E.uid=0;class C{constructor(e,t,s){this.component=e,this.index=t,this.bounds=s}}export{y as default};