@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.12 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{isAbortError as e}from"../../../../core/promiseUtils.js";import{StyleUpdateType as t}from"./enums.js";import s from"./WorkerTile.js";import r from"./style/StyleRepository.js";const o=25;class i{constructor(){this._spriteInfo={},this._glyphInfo={},this._sourceDataMaxLOD=o}reset(){return this._spriteInfo={},this._glyphInfo={},Promise.resolve()}getLayers(){return this._styleRepository?.layers??[]}async createTileAndParse(t,r){const{key:o}=t,i={};for(const e of Object.keys(t.sourceName2DataAndRefKey)){const s=t.sourceName2DataAndRefKey[e];i[e]=s.refKey}const a=new s(o,i,this,this._styleRepository);try{return await a.parse({...t,sourceDataMaxLOD:this._sourceDataMaxLOD},r)}catch(n){if(a.setObsolete(),a.release(),!e(n))throw n;return null}}updateStyle(e){if(!e||0===e.length||!this._styleRepository)return;const s=this._styleRepository;for(const r of e){const e=r.type,o=r.data;switch(e){case t.PAINTER_CHANGED:s.setPaintProperties(o.layer,o.paint);break;case t.LAYOUT_CHANGED:s.setLayoutProperties(o.layer,o.layout);break;case t.LAYER_REMOVED:s.deleteStyleLayer(o.layer);break;case t.LAYER_CHANGED:s.setStyleLayer(o.layer,o.index);break;case t.SPRITES_CHANGED:this._spriteInfo={}}}}setStyle(e){const{style:t,sourceDataMaxLOD:s}=e;this._styleRepository=new r(t),this._sourceDataMaxLOD=s,this._spriteInfo={},this._glyphInfo={}}fetchSprites(e,t,s){const r=[],o=this._spriteInfo;for(const i of e){void 0===o[i.name]&&r.push(i)}return 0===r.length?Promise.resolve():t.invoke("getSprites",r,{signal:s?.signal}).then((e=>{for(const t in e){const s=e[t];o[t]=s}}))}getSpriteItems(){return this._spriteInfo}fetchGlyphs(e,t,s,r,o){const i=[];let a=this._glyphInfo[t];return a?s.forEach((e=>{a[e]||i.push(e)})):(a=this._glyphInfo[t]=[],s.forEach((e=>i.push(e)))),0===i.length?Promise.resolve():r.invoke("getGlyphs",{tileID:e,font:t,codePoints:i},o).then((e=>{for(let t=0;t<e.length;t++)e[t]&&(a[t]=e[t])}))}getGlyphItems(e){return this._glyphInfo[e]}}export{i as default};