@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 2.19 kB
JavaScript
import{isSome as e}from"../../../../core/maybe.js";import{MIN_PRIORITY as t}from"../../../../core/MemCache.js";import{throwIfAborted as o}from"../../../../core/promiseUtils.js";import{f as i}from"../../../../chunks/mat3f32.js";import{create as s}from"../../../../geometry/support/aaBoundingRect.js";import{TileHandler as r}from"./TileHandler.js";import{VectorTile as n}from"./VectorTile.js";import{declutterSingleTile as l}from"./decluttering/jobsUtil.js";import a from"../../tiling/TileInfoViewPOT.js";import g from"../../tiling/TileKey.js";class h extends r{constructor(e,t,o,i,s){super(e,t,o),this._memCache=i,this._loader=s,this._ongoingTileRequests=new Map,this._ongoingRequestToController=new Map,this._tileInfoView=new a(e.tileInfo,e.fullExtent)}destroy(){super.destroy(),this._ongoingRequestToController.forEach((e=>e.abort())),this._ongoingRequestToController.clear(),this._ongoingTileRequests.clear()}async getVectorTile(r,a,h,m){const u=new g(r,a,h,0);let c=this._memCache.get(u.id);if(e(c))return c.retain(),c;const _=await this._getVectorTileData(u);if(o(m),!this._layer)return null;if(c=this._memCache.get(u.id),e(c))return c.retain(),c;const T=this._layer.tileInfo.getTileBounds(s(),u),f=this._tileInfoView.getTileResolution(r);return c=new n(u,f,T[0],T[3],512,512,this._styleRepository,this._memCache),e(_)?(c.setData(_),c.retain(),this._memCache.put(u.id,c,c.memoryUsage*c.referenced,t)):c.setData(null),c.neededForCoverage=!0,c.transforms.tileUnitsToPixels=i(1/8,0,0,0,1/8,0,0,0,1),l(c,this._styleRepository),c}_getVectorTileData(e){const t=e.id;if(this._ongoingTileRequests.has(t))return this._ongoingTileRequests.get(t);const o=new AbortController,i={signal:o.signal},s=this._getParsedVectorTileData(e,i).then((e=>(this._ongoingTileRequests.delete(t),this._ongoingRequestToController.delete(t),e))).catch((()=>(this._ongoingTileRequests.delete(t),this._ongoingRequestToController.delete(t),null)));return this._ongoingTileRequests.set(t,s),this._ongoingRequestToController.set(t,o),s}_getParsedVectorTileData(e,t){return this.fetchTileData(e,t).then((o=>this.parseTileData({key:e,data:o},t)))}request(e,t){return this._loader.request(e,"binary",t)}}export{h as default};