@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.71 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{fadeDuration as o}from"./config.js";function e(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 t{get running(){return this._running}constructor(o,e,t,i,s,n){this._visibleTiles=o,this._symbolRepository=e,this._createCollisionJob=t,this._assignTileSymbolsOpacity=i,this._symbolLayerSorter=s,this._isLayerVisible=n,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 e=0;e<o.length;e++){const t=o[e];for(let o=0;o<t.uniqueSymbols.length;o++){const e=t.uniqueSymbols[o];for(const o of e.tileSymbols)o.selectedForRendering=!1}}const t=[];let i=0,s=0;const n=this._isLayerVisible;function r(r){let l;const c=performance.now();for(;s<o.length;s++,i=0){const e=o[s],h=e.styleLayerUID;if(!n(h)){t[s]||(t[s]={styleLayerUID:h,symbols:[]});continue}t[s]=t[s]||{styleLayerUID:h,symbols:[]};const a=t[s];for(;i<e.uniqueSymbols.length;i++){if(l=e.uniqueSymbols[i],i%100==99&&performance.now()-c>r)return!1;let o=null,t=!1,s=!1;for(const e of l.tileSymbols)if(!s||!t){const i=e.tile;(!o||i.isCoverage||i.neededForCoverage&&!t)&&(o=e,(i.neededForCoverage||i.isCoverage)&&(s=!0),i.isCoverage&&(t=!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 t)o.symbols.sort(e);return!0}const l=this._symbolLayerSorter;return{work:r,get sortedSymbols(){return t.sort(l)}}}_createOpacityJob(){const o=this._assignTileSymbolsOpacity,e=this._visibleTiles;let t=0;function s(e,t){for(const o of e.symbols.values())i(o,t);o(e,t);for(const o of e.childrenTiles)s(o,t)}return{work(o){const i=performance.now();for(;t<e.length;t++){if(performance.now()-i>o)return!1;const n=e[t];if(null!=n.parentTile)continue;s(n,performance.now())}return!0}}}}function i(e,t){for(const i of e){const e=i.unique;for(const i of e.parts){const s=i.targetOpacity>.5?1:-1;i.startOpacity+=s*((t-i.startTime)/o),i.startOpacity=Math.min(Math.max(i.startOpacity,0),1),i.startTime=t,i.targetOpacity=e.show&&i.show?1:0}}}export{t as SymbolDeclutterer};