UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 5.94 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import e from"../../../Graphic.js";import t from"../../../core/Error.js";import o from"../../../core/Logger.js";import{getOrCreateMapValue as r}from"../../../core/MapUtils.js";import{isPromiseLike as i}from"../../../core/promiseUtils.js";import{generateBracedUUID as s}from"../../../core/uuid.js";import{isLoadedSharedTemplate as a,isSharedFeatureTemplate as l,isSharedGroupTemplate as n,isSharedPresetTemplate as u}from"../../templateUtils.js";import{createFeatureServiceEdit as p}from"./support/createFeatureServiceEdit.js";import{calculateExtent as c,groupEditsByLayer as m}from"./support/executorUtils.js";import{getBuilder as d}from"./support/getBuilder.js";import{isPoint as f}from"../../../geometry/support/jsonUtils.js";import{getAssociationsTableFields as y}from"../../../networks/support/networkFieldUtils.js";import{RuleType as T}from"../../../networks/support/typeUtils.js";const g=()=>o.getLogger("esri.editing.sharedTemplates.executor.createTemplateExecutor"),h="globalid";async function w(e){if(!a(e))throw new t("template-executor:template-not-loaded","The template must be loaded before it can be executed.");if(l(e))return I(e);if(n(e))return b(e);if(u(e))return G(e);throw new t("template-executor:unsupported-template-type","The template type is not supported.")}function I(e){return t=>{const o=[],r=[];p({geometry:t,template:e,edits:o,relationships:r});const i=c(o);return{edits:m(o),relationships:r,primary:o[0]??null,featureExtent:i,rotationPoint:i?.center??null}}}async function b(e){const{definition:t}=e,o=await Promise.all(t.allParts.map(k));return(r,s)=>{const a=[],l=[],n=new Set,u=()=>{if(t.createUtilityNetworkAssociations&&"completion"===s){const{utilityNetwork:e,utilityNetworkAssociationsTable:o}=t;e&&o?S({associationGraphics:n,associationsTable:o,edits:a,relationships:l,utilityNetworkHelper:e}):g().warn("Unable to create utility network associations between group template features. The utility network or its associations table is unavailable.")}const e=c(a);return{associationGraphics:n,edits:m(a),relationships:l,primary:a[0]??null,featureExtent:e,rotationPoint:e?.center??null}};if(null==r)return g().warn("No geometry provided to group template executor. Result will be empty."),u();const p=o.map((t=>t({edits:a,mode:s,parentTemplate:e,relationships:l,shape:r}))).filter(i);return 0===p.length?u():Promise.all(p).then((()=>u()))}}async function k(e){const t=await d(e.builderType);return o=>t.execute({...o,templatePart:e})}async function G(e){const{createPresetServiceEdit:o}=await import("./support/createPresetServiceEdit.js");return(r,i,s=0)=>{if(!f(r))throw new t("template-executor:invalid-input-geometry","The input goemetry for a preset template must be a point.");const a=[],l=[],n=o({geometry:r,template:e,edits:a,relationships:l,rotation:s,mode:i});return{edits:m(a),relationships:l,primary:a[0]??null,featureExtent:c(a),rotationPoint:n}}}function S(e){const{edits:t,utilityNetworkHelper:o}=e,i=new Map;for(const s of t)""!==s.tag&&o.layerIdToSourceIdLookup.has(s.id)&&r(i,s.tag,(()=>[])).push(s);for(const r of i.values())if(!(r.length<2))for(let t=0;t<r.length;t++){const o=r[t];for(let i=t+1;i<r.length;i++){A(o,r[i],e)}}}function A(t,o,r){const{associationGraphics:i,associationsTable:a,edits:l,utilityNetworkHelper:n,relationships:u}=r,p=n.findAgat(t.graphic,t.layer),c=n.findAgat(o.graphic,o.layer);if(!p||!c)return;const m=n.findRules(p).map((e=>e.fromNetworkSource?.sourceId!==p.networkSourceId||e.fromAssetGroup?.assetGroupCode!==p.assetGroup||null!==e.fromAssetType?.assetTypeCode&&e.fromAssetType?.assetTypeCode!==p.assetType||e.toNetworkSource.sourceId!==c.networkSourceId||e.toAssetGroup?.assetGroupCode!==c.assetGroup||null!==e.toAssetType&&e.toAssetType?.assetTypeCode!==c.assetType?e.toNetworkSource.sourceId!==p.networkSourceId||e.toAssetGroup?.assetGroupCode!==p.assetGroup||null!==e.toAssetType&&e.toAssetType?.assetTypeCode!==p.assetType||e.fromNetworkSource.sourceId!==c.networkSourceId||e.fromAssetGroup?.assetGroupCode!==c.assetGroup||null!==e.fromAssetType?.assetTypeCode&&e.fromAssetType?.assetTypeCode!==c.assetType?null:{rule:e,from:{agat:c,item:o},to:{agat:p,item:t}}:{rule:e,from:{agat:p,item:t},to:{agat:c,item:o}})).filter((e=>e?.rule.ruleType===T.RTJunctionEdgeConnectivity||e?.rule.ruleType===T.RTEdgeJunctionEdgeConnectivity||e?.rule.ruleType===T.RTContainment?null:e)).filter((e=>null!==e));if(0===m.length)return;const d=y(a),f=new Set;for(const y of m){const t={};t[d.fromNetworkSourceId]=y.rule.fromNetworkSource.sourceId,t[d.fromGlobalId]=y.from.item.graphic.attributes[y.from.item.layer.globalIdField??h],t[d.fromTerminalId]=null,y.rule.fromTerminal&&(t[d.fromTerminalId]=y.rule.fromTerminal.terminalId),t[d.toNetworkSourceId]=y.rule.toNetworkSource.sourceId,t[d.toGlobalId]=y.to.item.graphic.attributes[y.to.item.layer.globalIdField??h],t[d.toTerminalId]=null,y.rule.toTerminal&&(t[d.toTerminalId]=y.rule.toTerminal.terminalId),t[d.associationType]=y.rule.ruleType,t[d.percentAlong]=null,t[d.isContentVisible]=y.rule.ruleType===T.RTContainment?1:0,t[d.status]=0,t[d.globalId]=s();const o=`${t[d.fromNetworkSourceId]}-${t[d.fromGlobalId]}-${t[d.toNetworkSourceId]}-${t[d.toGlobalId]}-${t[d.associationType]}`;if(f.has(o))continue;f.add(o);const r=new e({attributes:t,sourceLayer:a});i.add(r),l.push({id:a.layerId,graphic:r,tag:"",layer:a}),u.push({sourceGraphic:y.to.item.graphic,sourceLayerId:y.to.item.layer.layerId,destinationGraphic:r,destinationLayerId:a.layerId,sourceField:y.to.item.layer.globalIdField??h,destinationField:d.toGlobalId??h}),u.push({sourceGraphic:y.from.item.graphic,sourceLayerId:y.from.item.layer.layerId,destinationGraphic:r,destinationLayerId:a.layerId,sourceField:y.from.item.layer.globalIdField??h,destinationField:d.fromGlobalId??h})}}export{w as createTemplateExecutor};