@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 1.96 kB
JavaScript
import e from"../../../../../core/Evented.js";import has from"../../../../../core/has.js";import{r as t}from"../../../../../chunks/rbush.js";import{Tile as s}from"./Tile.js";import i from"../../../tiling/TileCoverage.js";import o from"../../../tiling/TileKey.js";const h={added:[],removed:[]},n=new Set,r=new o(0,0,0,0);class d extends e{constructor(e){super(),this._tiles=new Map,this._index=t(9,has("esri-csp-restrictions")?e=>({minX:e.bounds[0],minY:e.bounds[1],maxX:e.bounds[2],maxY:e.bounds[3]}):[".bounds[0]",".bounds[1]",".bounds[2]",".bounds[3]"]),this.tiles=[],this.tileScheme=e}destroy(){this.clear()}clear(){this.tiles.length=0,this._tiles.clear(),this._index.clear()}has(e){return this._tiles.has(e)}get(e){return this._tiles.get(e)}boundsIntersections(e){return this._index.search({minX:e[0],minY:e[1],maxX:e[2],maxY:e[3]})}updateTiles(e){const t={added:[],removed:[]};for(const i of e.added)if(!this.has(i)){const e=new s(this.tileScheme,i);this._tiles.set(i,e),this._index.insert(e),t.added.push(e)}for(const s of e.removed)if(this.has(s)){const e=this.get(s);this._tiles.delete(s),this._index.remove(e),t.removed.push(e)}this.tiles.length=0,this._tiles.forEach((e=>this.tiles.push(e))),(t.added.length||t.removed.length)&&this.emit("update",t)}setViewState(e){const t=this.tileScheme.getTileCoverage(e,0);if(!t)return;const{spans:o,lodInfo:d}=t,{level:l}=d;if(o.length>0)for(const{row:i,colFrom:a,colTo:m}of o)for(let e=a;e<=m;e++){const t=r.set(l,i,d.normalizeCol(e),d.getWorldForColumn(e)).id;if(n.add(t),!this.has(t)){const e=new s(this.tileScheme,t);this._tiles.set(t,e),this._index.insert(e),this.tiles.push(e),h.added.push(e)}}for(let s=this.tiles.length-1;s>=0;s--){const e=this.tiles[s];n.has(e.id)||(this._tiles.delete(e.id),this.tiles.splice(s,1),this._index.remove(e),h.removed.push(e))}(h.added.length||h.removed.length)&&this.emit("update",h),i.pool.release(t),n.clear(),h.added.length=0,h.removed.length=0}}export{d as default};