UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 1.57 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import e from"../../../request.js";import{throwIfAborted as t,whenOrAbort as r}from"../../../core/promiseUtils.js";import{isSVG as s}from"../../../core/urlUtils.js";import{queueAutoPriority as i}from"../../../request/queue.js";import{TextureCollection as o,TextureRequest as n,TextureHandle as l}from"./TextureCollection.js";import{ManagedTexture as a}from"../webgl-engine/lib/ManagedTexture.js";class h extends o{constructor(e,t){super(e,t)}async fromUrl(s,o,a){t(a);const h=a?.signal,u=this.makeUid(s,o);let d=this._textureRequests.get(u);if(!d){const t=new AbortController,r={...i,responseType:"image",signal:t.signal},a=e(s,r);d=new n,d.abortController=t;const h=d;this._textureRequests.set(u,d),d.textureAsync=a.then(async({data:e})=>{const t=this._createTexture(s,e,o);return h.texture=t,h.abortController=null,await t.load(this._stage.renderView.renderingContext),this._stage.addTexture(t),new l(u,t,()=>this._release(u))},e=>{throw h.abortController=null,e})}d.referenceCount++;try{return await r(d.textureAsync,h)}catch(c){throw this._release(u),c}}_createTexture(e,t,r){const i={width:t.width,height:t.height,wrap:{s:33071,t:33071},preMultiplyAlpha:!0,reloadable:!0};if(s(e)){if(r||0===t.width&&0===t.height){const e=t.width?t.height/t.width:1;r=r||64,e>1?(t.width=Math.round(r/e),t.height=r):(t.width=r,t.height=Math.round(r*e))}this._stage.renderView?.renderingContext.driverTest.svgPremultipliesAlpha.result&&(i.preMultiplyAlpha=!1)}return new a(t,i)}}export{h as StreamTextureCollection};