import{abstract}from"../util.js";import TileCache from"../TileCache.js";import TileState from"../TileState.js";import Event from"../events/Event.js";import{equivalent}from"../proj.js";import{toSize,scale as scaleSize}from"../size.js";import Source from"./Source.js";import{getKeyZXY,withinExtentAndZ}from"../tilecoord.js";import{wrapX,getForProjection as getTileGridForProjection}from"../tilegrid.js";class TileSource extends Source{constructor(e){super({attributions:e.attributions,attributionsCollapsible:e.attributionsCollapsible,projection:e.projection,state:e.state,wrapX:e.wrapX}),this.opaque_=void 0!==e.opaque&&e.opaque,this.tilePixelRatio_=void 0!==e.tilePixelRatio?e.tilePixelRatio:1,this.tileGrid=void 0!==e.tileGrid?e.tileGrid:null;let t=e.cacheSize;if(void 0===t){var i=[256,256];const l=e.tileGrid;l&&toSize(l.getTileSize(l.getMinZoom()),i);var r="undefined"!=typeof screen,o=r?screen.availWidth||screen.width:1920,r=r?screen.availHeight||screen.height:1080;t=4*Math.ceil(o/i[0])*Math.ceil(r/i[1])}this.tileCache=new TileCache(t),this.tmpSize=[0,0],this.key_=e.key||"",this.tileOptions={transition:e.transition},this.zDirection=e.zDirection||0}canExpireCache(){return this.tileCache.canExpireCache()}expireCache(e,t){const i=this.getTileCacheForProjection(e);i&&i.expireCache(t)}forEachLoadedTile(e,i,r,o){const l=this.getTileCacheForProjection(e);if(!l)return!1;let s=!0,n,a,c;for(let t=r.minX;t<=r.maxX;++t)for(let e=r.minY;e<=r.maxY;++e)a=getKeyZXY(i,t,e),c=!1,l.containsKey(a)&&(n=l.get(a),c=(c=n.getState()===TileState.LOADED)&&!1!==o(n)),c||(s=!1);return s}getGutterForProjection(e){return 0}getKey(){return this.key_}setKey(e){this.key_!==e&&(this.key_=e,this.changed())}getOpaque(e){return this.opaque_}getResolutions(){return this.tileGrid.getResolutions()}getTile(e,t,i,r,o){return abstract()}getTileGrid(){return this.tileGrid}getTileGridForProjection(e){return this.tileGrid||getTileGridForProjection(e)}getTileCacheForProjection(e){var t=this.getProjection();return t&&!equivalent(t,e)?null:this.tileCache}getTilePixelRatio(e){return this.tilePixelRatio_}getTilePixelSize(e,t,i){const r=this.getTileGridForProjection(i);i=this.getTilePixelRatio(t),t=toSize(r.getTileSize(e),this.tmpSize);return 1==i?t:scaleSize(t,i,this.tmpSize)}getTileCoordForTileUrlFunction(e,t){const i=void 0!==t?t:this.getProjection();t=this.getTileGridForProjection(i);return this.getWrapX()&&i.isGlobal()&&(e=wrapX(t,e,i)),withinExtentAndZ(e,t)?e:null}clear(){this.tileCache.clear()}refresh(){this.clear(),super.refresh()}useTile(e,t,i,r){}}class TileSourceEvent extends Event{constructor(e,t){super(e),this.tile=t}}export default TileSource;export{TileSourceEvent};