@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 2.16 kB
JavaScript
import e from"../../request.js";import r from"../../core/Error.js";import{isSome as t}from"../../core/maybe.js";import{throwIfAbortError as o}from"../../core/promiseUtils.js";import{normalize as s,removeFile as n}from"../../core/urlUtils.js";import l from"../../portal/Portal.js";import a from"../../portal/PortalQueryParams.js";import{enableWebStyleForceWOSR as u}from"../../support/featureFlags.js";let f={};async function m(e,r){try{return{data:(await j(e,r)).data,baseUrl:n(e),styleUrl:e}}catch(t){return o(t),null}}function i(e,r,o){const s=t(r.portal)?r.portal:l.getDefault();let n;const a=`${s.url} - ${s.user&&s.user.username} - ${e}`;return f[a]||(f[a]=c(e,s,o).then((e=>(n=e,e.fetchData()))).then((r=>({data:r,baseUrl:n.itemUrl??"",styleName:e})))),f[a]}function y(){f&&(f={})}function c(e,t,o){return t.load(o).then((()=>{const r=new a({disableExtraQuery:!0,query:`owner:${h} AND type:${w} AND typekeywords:"${e}"`});return t.queryItems(r,o)})).then((({results:t})=>{let s=null;const n=e.toLowerCase();if(t&&Array.isArray(t))for(const e of t){const r=e.typeKeywords?.some((e=>e.toLowerCase()===n));if(r&&e.type===w&&e.owner===h){s=e;break}}if(!s)throw new r("symbolstyleutils:style-not-found",`The style '${e}' could not be found`,{styleName:e});return s.load(o)}))}function p(e,o,s){return e&&t(e.styleUrl)?m(e.styleUrl,s):e&&t(e.styleName)?i(e.styleName,o,s):Promise.reject(new r("symbolstyleutils:style-url-and-name-missing","Either styleUrl or styleName is required to resolve a style"))}function d(e){return null===e||"CIMSymbolReference"===e.type?e:{type:"CIMSymbolReference",symbol:e}}function b(e,r){if("cimRef"===r)return e.cimRef;if(e.formatInfos&&!u())for(const t of e.formatInfos)if("gltf"===t.type)return t.href;return e.webRef}function j(r,t){const o={responseType:"json",query:{f:"json"},...t};return e(s(r),o)}const h="esri_en",w="Style",U="https://cdn.arcgis.com/sharing/rest/content/items/220936cc6ed342c9937abd8f180e7d1e/resources/styles/cim/{SymbolName}.json?f=json";export{U as Style2DUrlTemplate,f as cachedStyles,y as cleanupStyleUtilsCache,p as fetchStyle,d as makeCIMSymbolRef,j as requestJSON,b as symbolUrlFromStyleItem};