@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 3.62 kB
JavaScript
import{isSome as o}from"../../../../../core/maybe.js";import{FADE_DURATION as e}from"./config.js";function t(o,e){if(o.priority-e.priority)return o.priority-e.priority;const t=o.tile.key,i=e.tile.key;return t.world-i.world?t.world-i.world:t.level-i.level?t.level-i.level:t.row-i.row?t.row-i.row:t.col-i.col?t.col-i.col:o.xTile-e.xTile?o.xTile-e.xTile:o.yTile-e.yTile}class i{get running(){return this._running}constructor(o,e,t,i,s,r){this._visibleTiles=o,this._symbolRepository=e,this._createCollisionJob=t,this._assignTileSymbolsOpacity=i,this._symbolLayerSorter=s,this._isLayerVisible=r,this._selectionJob=null,this._selectionJobCompleted=!1,this._collisionJob=null,this._collisionJobCompleted=!1,this._opacityJob=null,this._opacityJobCompleted=!1,this._running=!0}setScreenSize(o,e){this._screenWidth===o&&this._screenHeight===e||this.restart(),this._screenWidth=o,this._screenHeight=e}restart(){this._selectionJob=null,this._selectionJobCompleted=!1,this._collisionJob=null,this._collisionJobCompleted=!1,this._opacityJob=null,this._opacityJobCompleted=!1,this._running=!0}continue(o){if(this._selectionJob||(this._selectionJob=this._createSelectionJob()),!this._selectionJobCompleted){const e=performance.now();if(!this._selectionJob.work(o))return!1;if(this._selectionJobCompleted=!0,0===(o=Math.max(0,o-(performance.now()-e))))return!1}if(this._collisionJob||(this._collisionJob=this._createCollisionJob(this._selectionJob.sortedSymbols,this._screenWidth,this._screenHeight)),!this._collisionJobCompleted){const e=performance.now();if(!this._collisionJob.work(o))return!1;if(this._collisionJobCompleted=!0,0===(o=Math.max(0,o-(performance.now()-e))))return!1}if(this._opacityJob||(this._opacityJob=this._createOpacityJob()),!this._opacityJobCompleted){const e=performance.now();if(!this._opacityJob.work(o))return!1;if(this._opacityJobCompleted=!0,0===(o=Math.max(0,o-(performance.now()-e))))return!1}return this._running=!1,!0}_createSelectionJob(){const o=this._symbolRepository.uniqueSymbols;for(let t=0;t<o.length;t++){const e=o[t];for(let o=0;o<e.uniqueSymbols.length;o++){const t=e.uniqueSymbols[o];for(const o of t.tileSymbols)o.selectedForRendering=!1}}const e=[];let i=0,s=0;const r=this._isLayerVisible;function n(n){let l;const c=performance.now();for(;s<o.length;s++,i=0){const t=o[s],h=t.styleLayerUID;if(!r(h)){e[s]||(e[s]={styleLayerUID:h,symbols:[]});continue}e[s]=e[s]||{styleLayerUID:h,symbols:[]};const a=e[s];for(;i<t.uniqueSymbols.length;i++){if(l=t.uniqueSymbols[i],i%100==99&&performance.now()-c>n)return!1;let o=null,e=!1,s=!1;for(const t of l.tileSymbols)if(!s||!e){const i=t.tile;(!o||i.isCoverage||i.neededForCoverage&&!e)&&(o=t,(i.neededForCoverage||i.isCoverage)&&(s=!0),i.isCoverage&&(e=!0))}if(o.selectedForRendering=!0,s){a.symbols.push(o),l.show=!0;for(const o of l.parts)o.show=!0}else l.show=!1}}for(const o of e)o.symbols.sort(t);return!0}const l=this._symbolLayerSorter;return{work:n,get sortedSymbols(){return e.sort(l)}}}_createOpacityJob(){const e=this._assignTileSymbolsOpacity,t=this._visibleTiles;let i=0;function r(o,t){const i=o.symbols;for(const[e,r]of i)s(r,t);e(o,t);for(const e of o.childrenTiles)r(e,t)}return{work(e){const s=performance.now();for(;i<t.length;i++){if(performance.now()-s>e)return!1;const n=t[i];if(o(n.parentTile))continue;r(n,performance.now())}return!0}}}}function s(o,t){for(const i of o){const o=i.unique;for(const i of o.parts){const s=i.targetOpacity>.5?1:-1;i.startOpacity+=s*((t-i.startTime)/e),i.startOpacity=Math.min(Math.max(i.startOpacity,0),1),i.startTime=t,i.targetOpacity=o.show&&i.show?1:0}}}export{i as SymbolDeclutterer};