@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 1.91 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{PipelineCommand as t}from"../PipelineCommand.js";import{readObjectIds as e}from"../featureData/processingUtils.js";import{TestObjectSymbol as n}from"./TestObjectSymbol.js";import{TestSymbol as o}from"./TestSymbol.js";class r{constructor(t){this._symbols=new Array,this._featureDataPartitioning=new Map,this._context=t}async load(){this._symbols[0]=new o(this._context),this._symbols[1]=new n(this._context)}async createAddCommand(e){const n=this._partition(e),o=await Promise.all(n.map((async({index:t,features:e})=>{const n=await this._provisionSymbol(t);return await(n?.createAddCommand(e))}))),r=this._context.renderCommandContext.createEncoder();for(const t of o)null!=t&&r.append(t);return new t(r,[()=>{this._featureDataPartitioning.set(e,n)}])}async createRemoveCommand(e){const{_featureDataPartitioning:n}=this,o=n.get(e),r=this._context.renderCommandContext.createEncoder();if(null==o)return new t(this._context.renderCommandContext.createEncoder(),[]);const a=await Promise.all(o.map((async({index:t,features:e})=>{const n=this._getLoadedSymbol(t);return await(n?.createRemoveCommand(e))})));for(const t of a)null!=t&&r.append(t);return new t(r,[()=>{n.delete(e)}])}async _provisionSymbol(t){if(null==t)return null;const e=this._symbols[t];return e?(e.loaded||await e.load(),e):null}_getLoadedSymbol(t){if(null==t)return null;const e=this._symbols[t];return null!=e&&e.loaded?e:null}_partition(t){const n=e(t,this._context);if(null==n)throw new Error("unable to fetch objectIds");const{featureCount:o}=t,r=[[],[]];for(let e=0;e<o;++e){r[n[e]%2].push(e)}return r.map(((e,n)=>new a(n,t.subset(new Uint32Array(e))))).filter((t=>t.features.featureCount>0))}}class a{constructor(t,e){this.index=t,this.features=e}}export{r as UniqueValueFeatureRenderer};