12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import e from"../../request.js";import t from"../../core/Error.js";import{isAbortError as r}from"../../core/promiseUtils.js";import{isAnimatedPNG as i,parseApng as s}from"../../views/2d/engine/webgl/animatedFormats/apng.js";import{isAnimatedGIF as n,parseGif as a}from"../../views/2d/engine/webgl/animatedFormats/gif.js";class o{constructor(){this._resourceMap=new Map,this._inFlightResourceMap=new Map,this.geometryEngine=null}destroy(){this._inFlightResourceMap.clear(),this._resourceMap.clear()}getResource(e){return this._resourceMap.get(e)??null}async fetchResource(e,t){const r=this._resourceMap.get(e);if(r)return{width:r.width,height:r.height};const i=this._inFlightResourceMap.get(e);if(i)return i.then((e=>({width:e.width,height:e.height})));const s=h(e,t);return this._inFlightResourceMap.set(e,i),s.then((t=>(this._inFlightResourceMap.delete(e),this._resourceMap.set(e,t),{width:t.width,height:t.height})),(()=>({width:0,height:0})))}deleteResource(e){this._inFlightResourceMap.delete(e),this._resourceMap.delete(e)}}async function c(i,s){const n=window.URL.createObjectURL(i);try{const{data:t}=await e(n,{...s,responseType:"image"});return t}catch(a){if(!r(a))throw new t("mapview-invalid-resource",`Could not fetch requested resource at ${n}`);throw a}finally{window.URL.revokeObjectURL(n)}}async function h(e,t){const{arrayBuffer:r,mediaType:o}=await u(e,t),h="image/png"===o;if("image/gif"===o&&n(r))return a(r);if(h&&i(r))return s(r,t);return c(new Blob([r],{type:o}),t)}async function u(i,s){let n;const a=";base64,";if(i.includes(a)){const e=i.indexOf(a),t=i.indexOf(a)+a.length,r=i.substring(t),s=atob(r),o=new Uint8Array(s.length);for(let i=0;i<s.length;i++)o[i]=s.charCodeAt(i);n={arrayBuffer:o.buffer,mediaType:i.substring(0,e).replace("data:","")}}else try{const t=await e(i,{responseType:"array-buffer",...s}),r=t.data;n={arrayBuffer:r,mediaType:t.getHeader("Content-Type")}}catch(o){if(!r(o))throw new t("mapview-invalid-resource",`Could not fetch requested resource at ${i}`)}return n}export{o as default};
|