UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 8.78 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ 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 a}from"../../../core/uuid.js";import{isLoadedSharedTemplate as s,isSharedFeatureTemplate as l,isSharedGroupTemplate as n,isSharedPresetTemplate as u}from"../../templateUtils.js";import{fixInvalidCurves as p}from"./builders/support/curveFix.js";import{findSpatialReferenceXYTolerance as c}from"./builders/support/toleranceUtils.js";import{createFeatureServiceEdit as d}from"./support/createFeatureServiceEdit.js";import{calculateExtent as m,groupEditsByLayer as y}from"./support/executorUtils.js";import{getBuilder as f}from"./support/getBuilder.js";import{isPoint as h}from"../../../geometry/support/jsonTypeUtils.js";import{isCurvedGeometry as g}from"../../../geometry/support/curves/curveUtils.js";import{getAssociationsTableFields as w}from"../../../networks/support/networkFieldUtils.js";import{associationTypeKebabDict as I,AssociationTypeEnum as T}from"../../../networks/support/typeUtils.js";const b=()=>o.getLogger("esri.editing.sharedTemplates.executor.createTemplateExecutor"),k="globalid";async function G(e){if(!s(e))throw new t("template-executor:template-not-loaded","The template must be loaded before it can be executed.");if(l(e))return N(e);if(n(e))return F(e);if(u(e))return A(e);throw new t("template-executor:unsupported-template-type","The template type is not supported.")}function N(e){return t=>{const o=[],r=[];d({geometry:t,template:e,edits:o,relationships:r});const i=m(o);return{edits:y(o),relationships:r,primary:o[0]??null,featureExtent:i,rotationPoint:i?.center??null}}}async function F(e){const{definition:t}=e,o=await Promise.all(t.allParts.map(S));return(r,a)=>{const s=[],l=[],n=new Set,u=new Map,d=()=>{if(t.createUtilityNetworkAssociations&&"completion"===a){const{utilityNetwork:e,utilityNetworkAssociationsTable:o}=t;e&&o?x({associationGraphics:n,associationsTable:o,edits:s,relationships:l,utilityNetworkHelper:e}):b().warn("Unable to create utility network associations between group template features. The utility network or its associations table is unavailable.")}if(u.size>0&&"completion"===a){const{utilityNetwork:e,utilityNetworkAssociationsTable:o}=t;e&&o?L({associationGraphics:n,associationsTable:o,edits:s,relationships:l,utilityNetworkHelper:e,associationFeaturesByTemplate:u}):b().warn("Unable to create utility network associations between group template features. The utility network or its associations table is unavailable.")}const e=m(s);return{associationGraphics:n,edits:y(s),relationships:l,primary:s[0]??null,featureExtent:e,rotationPoint:e?.center??null}};if(null==r)return b().warn("No geometry provided to group template executor. Result will be empty."),d();const f=c("radial"===r.type?r.geometry.spatialReference:r.spatialReference);"polygon"!==r?.type&&"polyline"!==r?.type||!g(r)||(r=p(r));const h=o.map(t=>t({edits:s,mode:a,xyTolerance:f,parentTemplate:e,relationships:l,shape:r,associationFeaturesByTemplate:u})).filter(i);return 0===h.length?d():Promise.all(h).then(()=>d())}}async function S(e){const t=await f(e.builderType);return o=>t.execute({...o,templatePart:e})}async function A(e){const{createPresetServiceEdit:o}=await import("./support/createPresetServiceEdit.js");return(r,i,a=0)=>{if(!h(r))throw new t("template-executor:invalid-input-geometry","The input geometry for a preset template must be a point.");const s=[],l=[],n=new Map,u=new Set,p=o({geometry:r,template:e,edits:s,relationships:l,rotation:a,mode:i,associationFeaturesByTemplate:n});if(e.definition.associations.length>0&&"completion"===i){const{utilityNetwork:t,utilityNetworkAssociationsTable:o}=e.definition;t&&o?L({associationGraphics:u,associationsTable:o,edits:s,relationships:l,utilityNetworkHelper:t,associationFeaturesByTemplate:n}):b().warn("Unable to create utility network associations between preset template features. The utility network or its associations table is unavailable.")}return{associationGraphics:u,edits:y(s),relationships:l,primary:s[0]??null,featureExtent:m(s),rotationPoint:p}}}function x(e){const{edits:t,utilityNetworkHelper:o}=e,i=new Map;for(const a of t)""!==a.tag&&o.layerIdToSourceIdLookup.has(a.id)&&r(i,a.tag,()=>[]).push(a);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++){j(o,r[i],e)}}}function j(t,o,r){const{associationGraphics:i,associationsTable:s,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 d=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=>4===e?.rule.ruleType||5===e?.rule.ruleType||2===e?.rule.ruleType?null:e).filter(e=>null!==e);if(0===d.length)return;const m=w(s),y=new Set;for(const f of d){const t={};t[m.fromNetworkSourceId]=f.rule.fromNetworkSource.sourceId,t[m.fromGlobalId]=f.from.item.graphic.attributes[f.from.item.layer.globalIdField??k],t[m.fromTerminalId]=null,f.rule.fromTerminal&&(t[m.fromTerminalId]=f.rule.fromTerminal.terminalId),t[m.toNetworkSourceId]=f.rule.toNetworkSource.sourceId,t[m.toGlobalId]=f.to.item.graphic.attributes[f.to.item.layer.globalIdField??k],t[m.toTerminalId]=null,f.rule.toTerminal&&(t[m.toTerminalId]=f.rule.toTerminal.terminalId),t[m.associationType]=f.rule.ruleType,t[m.percentAlong]=null,t[m.isContentVisible]=2===f.rule.ruleType?1:0,t[m.status]=0,t[m.globalId]=a();const o=`${t[m.fromNetworkSourceId]}-${t[m.fromGlobalId]}-${t[m.toNetworkSourceId]}-${t[m.toGlobalId]}-${t[m.associationType]}`;if(y.has(o))continue;y.add(o);const r=new e({attributes:t,sourceLayer:s});i.add(r),l.push({id:s.layerId,graphic:r,tag:"",layer:s}),u.push({sourceGraphic:f.to.item.graphic,sourceLayerId:f.to.item.layer.layerId,destinationGraphic:r,destinationLayerId:s.layerId,sourceField:f.to.item.layer.globalIdField??k,destinationField:m.toGlobalId??k}),u.push({sourceGraphic:f.from.item.graphic,sourceLayerId:f.from.item.layer.layerId,destinationGraphic:r,destinationLayerId:s.layerId,sourceField:f.from.item.layer.globalIdField??k,destinationField:m.fromGlobalId??k})}}function L(o){const{associationGraphics:r,associationsTable:i,edits:s,utilityNetworkHelper:l,relationships:n}=o,u=w(i);for(const[p,c]of o.associationFeaturesByTemplate)for(const o of p.definition.associations){const p={},d=c.get(o.sourceIndex),m=c.get(o.targetIndex);if(!d)throw new t("template-executor:un-association-source-not-found","The preset template references a source feature that has not been created");if(!m)throw new t("template-executor:un-association-target-not-found","The preset template references a target feature that has not been created");p[u.fromNetworkSourceId]=l.getNetworkSourceIdForLayer(d.layer),p[u.fromGlobalId]=d.graphic.attributes[d.layer.globalIdField??k],p[u.fromTerminalId]=o.fromTerminalId,p[u.toGlobalId]=m.graphic.attributes[m.layer.globalIdField??k],p[u.toNetworkSourceId]=l.getNetworkSourceIdForLayer(m.layer),p[u.toTerminalId]=o.toTerminalId;const y=I.fromJSON(o.associationType);if(void 0===y)throw new t("template-executor:un-unsupported-association","The preset template uses an unsupported association type");p[u.associationType]=T[y],p[u.percentAlong]=o.percentAlong,p[u.isContentVisible]=o.isContentVisible?1:0,p[u.status]=0,p[u.globalId]=a();const f=new e({attributes:p,origin:i.graphicOrigin,sourceLayer:i});r.add(f),s.push({id:i.layerId,graphic:f,tag:"",layer:i}),n.push({sourceGraphic:d.graphic,sourceLayerId:d.layer.layerId,destinationGraphic:f,destinationLayerId:i.layerId,sourceField:d.layer.globalIdField??k,destinationField:u.fromGlobalId??k}),n.push({sourceGraphic:m.graphic,sourceLayerId:m.layer.layerId,destinationGraphic:f,destinationLayerId:i.layerId,sourceField:m.layer.globalIdField??k,destinationField:u.toGlobalId??k})}}export{G as createTemplateExecutor};