UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 912 B
import r from"../../../request.js";import{result as e}from"../../../core/asyncUtils.js";import o from"../../../core/Error.js";import{isNone as s}from"../../../core/maybe.js";import{throwIfAborted as t,throwIfAbortError as a}from"../../../core/promiseUtils.js";import{isDataProtocol as i,dataToArrayBuffer as m}from"../../../core/urlUtils.js";class n{constructor(r){this._streamDataRequester=r}async loadJSON(r,e){return this._load("json",r,e)}async loadBinary(r,e){return i(r)?(t(e),m(r)):this._load("binary",r,e)}async loadImage(r,e){return this._load("image",r,e)}async _load(t,i,m){if(s(this._streamDataRequester))return(await r(i,{responseType:c[t]})).data;const n=await e(this._streamDataRequester.request(i,t,m));if(!0===n.ok)return n.value;throw a(n.error),new o("",`Request for resource failed: ${n.error}`)}}const c={image:"image",binary:"array-buffer",json:"json"};export{n as DefaultLoadingContext};