@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.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 e from"./TileKey.js";function s(e,s){const t=new Set;for(const i of e instanceof Set?e.values():e.keys())s.has(i)||t.add(i);return t}class t{constructor(e,s,t){const i=t?e.getTileCoverage(t,0,!0,"closest"):null,o=e.getTileCoverage(s,0,!0,"closest");if(this._tileKeys=new Map,i)for(const n of i.keys())this._tileKeys.set(n.id,n);if(o)for(const n of o.keys())this._tileKeys.set(n.id,n)}get coverageSet(){return new Set(this._tileKeys.keys())}keys(){return this._tileKeys.values()}}class i{constructor(e){this.version=e}}class o{constructor(e){this._subscriptions=new Map,this._visible=new Set,this._paused=new Set,this._version=0,this._config=e}destroy(){}get _coverageSet(){return this._coverage?.coverageSet??new Set}suspend(){this._suspendedOverage=this._coverage,this._coverage=null,this._updateSubscriptions()}resume(){null==this._coverage&&(this._coverage=this._suspendedOverage,this._suspendedOverage=null,this._updateSubscriptions())}update(e,s){return this._version=(this._version+1)%Number.MAX_SAFE_INTEGER,this._updateCoverage(e,s),this._updateSubscriptions(),new Set(this._visible)}_updateCoverage(e,s){this._coverage=new t(this._config.tileInfoView,e,s)}_updateSubscriptions(){const e=this._coverageSet,t=this._updateVisibility(),o=s(t,e),n=s(this._subscriptions,t),r=s(e,this._subscriptions),a=s(n,e),c=s(o,a),u=s(c,this._paused);this._visible=t;for(const s of r.values())this._subscriptions.set(s,new i(this._version));for(const s of u.values())this._paused.add(s);for(const s of a.values())this._subscriptions.delete(s),this._paused.delete(s);(r.size||a.size||u.size)&&this._sendUpdateSubscriptions(r,a,u)}_sendUpdateSubscriptions(e,s,t){const i=Array.from(e.values()).map((e=>({tileId:e,version:this._subscriptions.get(e).version})));this._config.updateSubscriptions({subscribe:i,unsubscribe:Array.from(s.values()),pause:Array.from(t.values())})}_updateVisibility(){const s=new Set,t=new Set;if(!this._coverage)return s;for(const e of this._coverage.keys()){if(this._config.isDone(e)){s.add(e.id);continue}if(this._addVisibleParent(s,t,e))continue;this._addVisibleChildren(s,e)||s.add(e.id)}const i=new e(0,0,0,0),o=new e(0,0,0,0);for(const e of t){i.id=e;for(const e of s)o.id=e,i.containsChild(o)&&s.delete(e)}return s}_addVisibleParent(s,t,i){let o=!1;for(const n of this._visible.values()){new e(n).containsChild(i)&&(s.add(n),t.add(n),o=!0)}return o}_addVisibleChildren(s,t){let i=!1;for(const o of this._visible.values()){const n=new e(o);t.containsChild(n)&&(s.add(o),i=!0)}return i}}export{o as FeatureTileSubscriptionManager};