@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.28 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import e from"../core/Logger.js";import{getOrCreateMapValue as t}from"../core/MapUtils.js";import{throwIfAborted as r}from"../core/promiseUtils.js";import{addMaybe as n}from"../core/SetUtils.js";import{isGroupTemplateDefinition as i,isPresetTemplateDefinition as o,isFeatureTemplateDefinition as s}from"./sharedTemplates/templateDefinitions/templateDefinitionUtils.js";import{isSubtypeGroupLayer as a,isSubtypeSublayer as l,isFeatureLayer as f}from"../layers/support/layerUtils.js";import{getServices as u}from"../undoredo/support/Services.js";const p=()=>e.getLogger("esri.editing.templateUtils");function c(e){return null!=e&&"prototype"in e}function m(e){return d(e)&&!("definition"in e)}function y(e){return d(e)&&"definition"in e}function d(e){return null!=e&&"templateId"in e}function g(e){return y(e)&&"feature"===e?.type&&(null==e.definition||s(e.definition))}function w(e){return y(e)&&"group"===e?.type&&(null==e.definition||i(e.definition))}function A(e){return y(e)&&"preset"===e?.type&&(null==e.definition||o(e.definition))}function S(e){return y(e)&&null!=e?.definition}const b=e=>{if(null==e||"object"!=typeof e)return[];return[..."templates"in e&&Array.isArray(e.templates)?e.templates:[],..."types"in e&&Array.isArray(e.types)?e.types.flatMap((e=>e.templates)):[]]};async function h(e,t,n){if(null==t)return e.map((e=>({layer:e,templates:b(e)})));const i=await M(e,t);r(n);const o=new Map,s=Array.from(i).map((e=>j({serviceInfo:e,out:o,signal:n}))),a=await Promise.allSettled(s);for(const r of a.filter((e=>"rejected"===e.status)))p().warn("Failed to fetch shared templates for service. Will use standard templates if available.",r.reason);return e.map((e=>({layer:e,templates:o.get(e)??b(e)})))}async function j({serviceInfo:e,out:t,signal:n}){const{featureService:i,layersAndTables:o}=e,s=await v({featureService:i,layers:o.toArray(),signal:n});r(n);for(const[r,l]of s.entries())if(0!==l.length)if(a(r)){const e=U(l),n=[],i=e.get(1/0)??n;for(const o of r.sublayers){const r=e.get(o.subtypeCode)??n;t.set(o,[...r,...i])}}else t.set(r,l)}async function v({featureService:e,layers:r,signal:n}){if(!e.capabilities?.editing.supportsSharedTemplates)return new Map;const i=new Map(r.map((e=>[e.layerId,e]))),o=await e.querySharedTemplates({query:{layers:Array.from(i.keys())},requestOptions:{signal:n}}),s=new Map;for(const a of o)for(const e of a.layerIds)i.has(e)&&t(s,i.get(e),(()=>[])).push(a);return s}async function M(e,t){const r=await u(t).load(),i=new Set;for(const o of e)n(i,L(r,o));return await Promise.all(Array.from(i).map((e=>e.featureService.load()))),i}function L(e,t){return l(t)&&t.parent?e.tablesAndLayersLookup.get(t.parent):f(t)?e.tablesAndLayersLookup.get(t):null}function U(e){const r=new Map;for(const n of e)t(r,n.subtypeCode??1/0,(()=>[])).push(n);return r}export{b as getAllStandardFeatureTemplatesForLayer,L as getServiceInfoForLayer,h as getTemplatesForLayers,S as isLoadedSharedTemplate,g as isSharedFeatureTemplate,w as isSharedGroupTemplate,A as isSharedPresetTemplate,y as isSharedTemplate,m as isSharedTemplateMetadata,d as isSharedTemplateOrMetadata,c as isStandardFeatureTemplate};