/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../chunks/_rollupPluginBabelHelpers","../../../../core/maybe","../../../../core/MemCache","../../../../core/promiseUtils","../../../../chunks/mat3f32","../../../../geometry/support/aaBoundingRect","./TileHandler","./VectorTile","./decluttering/jobsUtil","../../tiling/TileKey"],(function(e,t,i,n,o,r,s,l,a,u){"use strict";let c=function(s){function c(e,t,i,n,o){var r;return(r=s.call(this,e,t,i)||this)._memCache=n,r._loader=o,r._ongoingTileRequests=new Map,r._ongoingRequestToController=new Map,r}e._inheritsLoose(c,s);var g=c.prototype;return g.destroy=function(){this._ongoingRequestToController.forEach((e=>e.abort())),this._ongoingRequestToController.clear(),this._ongoingTileRequests.clear()},g.getVectorTile=function(){var s=e._asyncToGenerator((function*(e,s,c,g){const h=new u(e,s,c,0);let _=this._memCache.get(h.id);if(t.isSome(_))return _.retain(),_;const T=yield this._getVectorTileData(h);if(n.throwIfAborted(g),!this._layer)return null;if(_=this._memCache.get(h.id),t.isSome(_))return _.retain(),_;const d=this._layer.tileInfo.getTileBounds(r.create(),h);return _=new l.VectorTile(h,d[0],d[3],512,512,this._styleRepository,this._memCache),t.isSome(T)?(_.setData(T),_.retain(),this._memCache.put(h.id,_,_.memoryUsage*_.referenced,i.MIN_PRIORITY)):_.setData(null),_.neededForCoverage=!0,_.transforms.tileUnitsToPixels=o.fromValues(1/8,0,0,0,1/8,0,0,0,1),a.declutterSingleTile(_,this._styleRepository),_}));function c(e,t,i,n){return s.apply(this,arguments)}return c}(),g._getVectorTileData=function(e){const t=e.id;if(this._ongoingTileRequests.has(t))return this._ongoingTileRequests.get(t);const i=new AbortController,n={signal:i.signal},o=this._getParsedVectorTileData(e,n).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,o),this._ongoingRequestToController.set(t,i),o},g._getParsedVectorTileData=function(e,t){return this.fetchTileData(e,t).then((i=>this.parseTileData({key:e,data:i},t)))},g.request=function(e,t){return this._loader.request(e,"binary",t)},c}(s.TileHandler);return c}));
