@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 4.59 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{_ as t}from"../../../../chunks/tslib.es6.js";import e from"../../../../core/Accessor.js";import"../../../../core/has.js";import{debounce as i,throwIfAborted as o,throwIfAbortError as r,eachAlways as s}from"../../../../core/promiseUtils.js";import{property as a}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as n}from"../../../../core/accessorSupport/decorators/subclass.js";import{create as p,toExtent as m}from"../../../../geometry/support/aaBoundingRect.js";import{getInfo as h}from"../../../../geometry/support/spatialReferenceUtils.js";import l from"../../../../layers/support/TileInfo.js";import{getOuterSize as d,getBBox as c}from"../../viewStateUtils.js";import{Bitmap as u}from"../../engine/Bitmap.js";import g from"../../tiling/TileInfoView.js";import f from"../../tiling/TileKey.js";const y=p(),x=[0,0],S=new f(0,0,0,0),w={container:null,fetchSource:null,requestUpdate:null,imageMaxWidth:2048,imageMaxHeight:2048,imageRotationSupported:!1,imageNormalizationSupported:!1,hidpi:!1};let M=class extends e{constructor(t){super(t),this._imagePromise=null,this.bitmaps=[],this.hidpi=w.hidpi,this.imageMaxWidth=w.imageMaxWidth,this.imageMaxHeight=w.imageMaxHeight,this.imageRotationSupported=w.imageRotationSupported,this.imageNormalizationSupported=w.imageNormalizationSupported,this.update=i((async(t,e)=>{if(o(e),!t.stationary||this.destroyed)return;const i=t.state,s=h(i.spatialReference),a=this.hidpi?t.pixelRatio:1,n=i.worldScreenWidth>0,p=n&&this.imageNormalizationSupported&&i.worldScreenWidth<i.size[0],m=Math.round((this.imageMaxWidth??0)/a),l=Math.round((this.imageMaxHeight??0)/a);p?(x[0]=i.worldScreenWidth,x[1]=i.size[1]):this.imageRotationSupported?(x[0]=i.size[0],x[1]=i.size[1]):d(x,i);const c=Math.floor(x[0])>m||Math.floor(x[1])>l,u=s&&(i.extent.xmin<s.valid[0]||i.extent.xmax>s.valid[1]),g=!this.imageNormalizationSupported&&u,f=!c&&!g,y=this.imageRotationSupported?i.rotation:0,S=this.container.children.slice();if(f){const t=p?i.paddedViewState.center:i.center;this._imagePromise=this._singleExport(i,x,t,i.resolution,y,a,e)}else{let t=Math.min(m,l);n&&(t=Math.min(i.worldScreenWidth,t),t=Math.round(i.worldScreenWidth/Math.ceil(i.worldScreenWidth/t))),this._imagePromise=this._tiledExport(i,t,a,e)}try{const t=await this._imagePromise??[];o(e);const i=[];if(this._imagePromise=null,this.destroyed)return;this.bitmaps=t;for(const e of S)t.includes(e)||i.push(e.fadeOut().then((()=>{e.remove(),e.destroy()})));for(const e of t)i.push(e.fadeIn());await Promise.all(i)}catch(w){this._imagePromise=null,r(w)}}),5e3),this.updateExports=i((async t=>{const e=[];for(const i of this.container.children){if(!i.visible||!i.stage)return;e.push(t(i).then((()=>{i.invalidateTexture(),i.requestRender()})))}this._imagePromise=s(e).then((()=>this._imagePromise=null)),await this._imagePromise}))}destroy(){this.bitmaps.forEach((t=>t.destroy())),this.bitmaps=[]}get updating(){return!this.destroyed&&null!==this._imagePromise}async _export(t,e,i,r,s,a){const n=await this.fetchSource(t,Math.floor(e*s),Math.floor(i*s),{rotation:r,pixelRatio:s,signal:a});o(a);const p=new u(null,!0);return p.x=t.xmin,p.y=t.ymax,p.resolution=t.width/e,p.rotation=r,p.pixelRatio=s,p.opacity=0,this.container.addChild(p),await p.setSourceAsync(n,a),o(a),p}async _singleExport(t,e,i,o,r,s,a){c(y,i,o,e);const n=m(y,t.spatialReference);return[await this._export(n,e[0],e[1],r,s,a)]}_tiledExport(t,e,i,o){const r=l.create({size:e,spatialReference:t.spatialReference,scales:[t.scale]}),s=new g(r),a=s.getTileCoverage(t);if(!a)return null;const n=[];return a.forEach(((r,a,p,h)=>{S.set(r,a,p,0),s.getTileBounds(y,S);const l=m(y,t.spatialReference);n.push(this._export(l,e,e,0,i,o).then((t=>(0!==h&&(S.set(r,a,p,h),s.getTileBounds(y,S),t.x=y[0],t.y=y[3]),t))))})),Promise.all(n)}};t([a()],M.prototype,"_imagePromise",void 0),t([a()],M.prototype,"bitmaps",void 0),t([a()],M.prototype,"container",void 0),t([a()],M.prototype,"fetchSource",void 0),t([a()],M.prototype,"hidpi",void 0),t([a()],M.prototype,"imageMaxWidth",void 0),t([a()],M.prototype,"imageMaxHeight",void 0),t([a()],M.prototype,"imageRotationSupported",void 0),t([a()],M.prototype,"imageNormalizationSupported",void 0),t([a()],M.prototype,"requestUpdate",void 0),t([a()],M.prototype,"updating",null),M=t([n("esri.views.2d.layers.support.ExportStrategy")],M);const _=M;export{_ as default};