@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 1.44 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{clone as t}from"../../../../core/lang.js";import{LRUCache as e}from"../../../../core/LRUCache.js";import{throwIfAborted as n}from"../../../../core/promiseUtils.js";import{numericHash as s}from"../../../../core/string.js";function o(t=!1,e){return t?new i(e):new c}class c{async fetch(){return[]}notifySymbologyChange(){}}const r=1024;class i{constructor(t){this._getSymbologyCandidates=t,this._candidatesCache=new e(r),this._cacheVersion=0}async fetch(e,s){if(0===e.length)return[];const o=[],c=[],r=this._candidatesCache;for(const n of e){const e=a(n),s=r.get(e);if(s)for(const n of s)c.push(t(n));else o.push(n),r.put(e,[],1)}if(0===o.length)return c;const i=this._cacheVersion,{candidates:h,sourceCandidateIndices:d}=await this._getSymbologyCandidates(o,s);n(s);if(i!==this._cacheVersion)return this.fetch(e,s);const f=[],{length:g}=h;for(let n=0;n<g;++n){const e=h[n],s=a(o[d[n]]),c=r.get(s);c.push(e),r.put(s,c,c.length),f.push(t(e))}return c.concat(f)}notifySymbologyChange(){this._candidatesCache.clear(),this._cacheVersion++}}function a(t){switch(t.type){case"vertex":{const{objectId:e,target:n}=t,o=`${e}-vertex-${n.x}-${n.y}-${n.z??0}`;return s(o).toString()}case"edge":{const{objectId:e,start:n,end:o}=t,c=`${e}-edge-${n.x}-${n.y}-${n.z??0}-to-${o.x}-${o.y}-${o.z??0}`;return s(c).toString()}default:return""}}export{o as getSymbologySnappingCandidatesFetcher};