@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 6.47 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import{__decorate as e}from"tslib";import{forEach as t,result as r}from"../../../core/asyncUtils.js";import{makeHandle as i}from"../../../core/handleUtils.js";import a from"../../../core/Logger.js";import{abortMaybe as s}from"../../../core/maybe.js";import{isAbortError as n,onAbort as o,throwIfAborted as l,isAborted as h,createAbortError as m}from"../../../core/promiseUtils.js";import{whenOnce as d}from"../../../core/reactiveUtils.js";import{property as g,subclass as u}from"../../../core/accessorSupport/decorators.js";import c from"../../../geometry/Extent.js";import{equals as p,create as x,width as y,height as f,copy as w,intersection as _}from"../../../geometry/support/aaBoundingRect.js";import v from"./SubView3D.js";import{computeImageExportSize as b,createGeometryForExtent as R,createOuterImageGeometry as S}from"./support/overlayImageUtils.js";import{debugFlags as E}from"../support/debugFlags.js";import{ManagedTexture as M}from"../webgl-engine/lib/ManagedTexture.js";import{RenderGeometry as j}from"../webgl-engine/lib/RenderGeometry.js";import{ImageMaterial as I}from"../webgl-engine/materials/ImageMaterial.js";let A=class extends v{constructor(e){super(e),this.drapeSourceType=0,this.updatePolicy=1,this.type="draped",this.maximumDataResolution=null,this._images=new Array,this._extents=new Array,this._overlays=new Array,this._drapeSourceRenderer=null}initialize(){this._drapeSourceRenderer=this.view.overlayManager.registerGeometryDrapeSource(this),this.addHandles(i(()=>this.view.overlayManager.unregisterDrapeSource(this)))}setDrapingExtent(e,t){this._spatialReference=t,e.forEach((e,t)=>{this._overlays[t]=e,this._updateImageExtent(e,t)})}destroy(){this.clear()}get spatialReference(){return this._spatialReference}_updateImageExtent(e,t){const r=this._clippedExtent(e.extent,G);if(null==r)return;const i=b(e.extent,r,e.resolution);let s=e.pixelRatio*this.view.state.pixelRatio;const{layer:o}=this;if("imageMaxWidth"in o&&null!=o.imageMaxWidth||"imageMaxHeight"in o&&null!=o.imageMaxHeight){const e=o.imageMaxWidth,t=o.imageMaxHeight;if(i.width>e){const t=e/i.width;i.height=Math.floor(i.height*t),i.width=e,s*=t}if(i.height>t){const e=t/i.height;i.width=Math.floor(i.width*e),i.height=t,s*=e}}const l=this._extents[t];l&&p(l.extent,r)&&this._imageSizeEquals(r,l.imageSize,i)||(this._extents[t]={extent:x(r),imageSize:i,pixelRatio:s},this.suspended||this._fetch(t).catch(e=>{n(e)||a.getLogger(this).error(e)}))}clear(){for(let e=0;e<this._images.length;e++)this._clearImage(e)}async doRefresh(e){const t=[];for(let r=0;r<this._extents.length;r++)this._extents[r]&&t.push(this._fetch(r,e));await Promise.allSettled(t)}async processResult(e,t,r){(t instanceof HTMLImageElement||t instanceof HTMLCanvasElement)&&(e.image=t)}findExtentInfoAt(e){for(const t of this._extents){const r=t.extent;if(new c(r[0],r[1],r[2],r[3],this._spatialReference).contains(e))return t}return null}async redraw(e,r){await t(this._images,async(t,i)=>{t&&(await e(t,r),await this._createStageObjects(i,t.image,r))})}_imageSizeEquals(e,t,r){if(!this.maximumDataResolution)return!1;const i=y(e)/this.maximumDataResolution.x,a=f(e)/this.maximumDataResolution.y,s=i/t.width,n=a/t.height,o=i/r.width,l=a/r.height,h=Math.abs(s-o),m=Math.abs(n-l),d=E.TESTS_DISABLE_OPTIMIZATIONS?0:1.5;return h<=d&&m<=d}async _fetch(e,t){if(this.suspended)return;const r=this._extents[e],i=r.extent;this._images[e]||(this._images[e]={texture:null,material:null,renderGeometry:null,loadingPromise:null,loadingAbortController:null,image:null,pixelData:null,renderExtent:x(i)});const d=this._images[e];d.loadingAbortController=s(d.loadingAbortController);const g=new c(i[0],i[1],i[2],i[3],this._spatialReference);if(0===g.width||0===g.height)return void this._clearImage(e);const u=new AbortController;d.loadingAbortController=u,o(t,()=>u.abort());const p=u.signal,y=this._waitFetchReady(p).then(async()=>{l(p);const t={requestAsImageElement:!0,pixelRatio:this._overlays[e].pixelRatio,...this.layerView.getFetchOptions(),signal:p},{height:i,width:a}=r.imageSize;return this.layer?"imagery"===this.layer.type?this.layer.internalFetchImage(g,a,i,t):this.layer.fetchImage(g,a,i,t):null}).then(e=>{if(h(p))throw a.getLogger(this).warnOnce("A call to fetchImage resolved even though the request was aborted. fetchImage should not resolve if options.signal.aborted is true."),m();return this.processResult(d,e)}).then(()=>{w(d.renderExtent,i)});d.loadingPromise=y,await this.updatingHandles.addPromise(y.then(async()=>{l(p),await this._createStageObjects(e,d.image,p)}).catch(e=>{throw e&&!n(e)&&a.getLogger(this).error(e),e}).finally(()=>{y===d.loadingPromise&&(d.loadingPromise=null,d.loadingAbortController=null)}))}_clearImage(e){const t=this._images[e];if(t){null!=t.renderGeometry&&(this._drapeSourceRenderer.removeGeometries([t.renderGeometry],1),t.renderGeometry=null);const e=this.view.stage,r=t.texture;r?.unload(),e.removeTexture(r),t.texture=null,t.material=null,t.loadingAbortController=s(t.loadingAbortController),t.loadingPromise=null,t.image=null,t.pixelData=null}}async _createStageObjects(e,t,i){const a=this.view.stage,s=this._images[e],n=()=>{s.texture?.unload(),a.removeTexture(s.texture),s.texture=null,s.renderGeometry&&(this._drapeSourceRenderer.removeGeometries([s.renderGeometry],1),s.renderGeometry=null)};if(t){const o=new M(t,{width:t.width,height:t.height,preMultiplyAlpha:!0,wrap:{s:33071,t:33071}});if(await r(this._images[0===e?1:0].loadingPromise),l(i),n(),await a.schedule(()=>o.load(a.renderView.renderingContext),i),!o.loaded)return void n();let h;if(a.addTexture(o),s.texture=o,s.material??=new I({draped:!0,managedTexture:o}),s.material.setParameters({managedTexture:o}),0===e)h=R(s.material,s.renderExtent);else{const e=this._images[0].renderExtent;if(!e)return void n();h=S(s.material,e,s.renderExtent)}s.renderGeometry=new j(h),s.renderGeometry.localOrigin=this._overlays[e].renderLocalOrigin,this._drapeSourceRenderer.addGeometries([s.renderGeometry],1)}else n(),s.material=null}_clippedExtent(e,t){if("local"!==this.view.viewingMode)return w(t,e);const{groundView:r}=this.view;return r.ready?_(e,r.groundExtent,t):w(t,e)}async _waitFetchReady(e){await d(()=>this.view.stationary,e),l(e)}get usedMemory(){return this._images.reduce((e,t)=>e+(t.texture?.usedMemory??0),0)}};e([g()],A.prototype,"type",void 0),A=e([u("esri.views.3d.layers.DrapedSubView3D")],A);const G=x();export{A as default};