@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 1.83 kB
JavaScript
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";class o{constructor(){this._spriteInfo={},this._glyphInfo={}}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 n=new s(o,i,this,this._styleRepository);try{return await n.parse(t,r)}catch(l){if(n.setObsolete(),n.release(),!e(l))throw l;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){this._styleRepository=new r(e),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&&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 n=this._glyphInfo[t];return n?s.forEach((e=>{n[e]||i.push(e)})):(n=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]&&(n[t]=e[t])}))}getGlyphItems(e){return this._glyphInfo[e]}}export{o as default};