UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 1.68 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{fromJSON as e}from"../../geometry/support/jsonUtils.js";import{convertFromGeometry as t}from"../graphics/featureConversionUtils.js";import{OptimizedFeature as r}from"../graphics/OptimizedFeature.js";import{systemOriginIdFieldName as i,systemDestinationIdFieldName as s}from"./constants.js";class o{constructor(){this._featureLookup=new Map}static getInstance(){return o.instance||(o.instance=new o),o.instance}static resetInstance(){o.instance&&(o.instance=null)}deleteFromStore(e){e.forEach((e=>{this._featureLookup.delete(e)}))}readFromStoreByList(e){const t=[];return e.forEach((e=>{const r=this.readFromStoreById(e);r&&t.push(r)})),t}readFromStoreById(e){return this._featureLookup.get(e)??null}writeToStore(o,n,p){const a=[];return o.forEach((o=>{if(!o?.id)return;o.properties||(o.properties=[]);let u,c=null;if(p&&o.properties[p]&&(c=t(o.properties[p])),"originId"in o&&"destinationId"in o&&(o.properties[i]=o.originId,o.properties[s]=o.destinationId),o.properties[n]=o.id,o.id&&this._featureLookup.has(o.id)&&this._featureLookup.get(o.id).attributes){const t=this._featureLookup.get(o.id),i=JSON.parse(JSON.stringify(Object.assign(t.attributes,o.properties)));p&&o.properties[p]&&(i[p]=e(o.properties[p])),u=new r(c?JSON.parse(JSON.stringify(c)):t?.geometry?JSON.parse(JSON.stringify(t.geometry)):null,i,null,o.properties[n])}else u=new r(c?JSON.parse(JSON.stringify(c)):null,o.properties,null,o.properties[n]);this._featureLookup.set(`${o.typeName?`${o.typeName}__${o.id}`:o.id}`,u),a.push(u)})),a}}export{o as default};