UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 2.76 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import t from"../../../../core/Error.js";import{getOrCreateMapValue as e}from"../../../../core/MapUtils.js";import{isLoadedSharedTemplate as o,isSharedFeatureTemplate as r,isSharedPresetTemplate as s}from"../../../templateUtils.js";import{createFeatureServiceEdit as i}from"./createFeatureServiceEdit.js";import{maxDigitizingDisplayEdits as n}from"./executorUtils.js";import a from"../../../../geometry/Multipoint.js";import p from"../../../../geometry/Point.js";import{execute as l}from"../../../../geometry/operators/affineTransformOperator.js";import m from"../../../../geometry/operators/support/Transformation.js";import{getPaths as f,getEndpoint as c}from"../../../../geometry/support/curves/curveUtils.js";function h({edits:a,geometry:p,mode:f,relationships:c,rotation:g,tag:y="",template:d,associationFeaturesByTemplate:j}){const{definition:M}=d,Z=p.x-M.origin.x,w=p.y-M.origin.y,x=M.origin.hasZ&&p.hasZ?p.z-M.origin.z:0,z=u(M.origin.clone(),Z,w,x),R=(new m).rotate(g,z.x,z.y),T=M.associations.length>0?e(j,d,()=>new Map):null;for(let e=0;e<M.parts.length;e++){const m=M.parts[e];if(a.length>n&&"digitizing"===f)break;const g=m.template;if(!o(g))throw new t("shared-template:template-not-loaded","A template part's template must be loaded before use");if(r(g)){let t=u(m.geometry,Z,w,x);R.isIdentity()||(t=l(t,R));const o=[];i({edits:o,geometry:t,relationships:c,tag:y,template:g});for(const e of o)a.push(e);T&&T.set(e,o[0]??null)}else if(s(g)){const t=[];if(h({edits:R.isIdentity()?t:a,geometry:p,mode:f,relationships:c,rotation:0,tag:y,template:g,associationFeaturesByTemplate:j}),!R.isIdentity())for(const e of t){const{geometry:t}=e.graphic;t&&"mesh"!==t.type&&(e.graphic.geometry=l(t,R),a.push(e))}}}return z}function u(t,e,o,r=0){if(!t)return null;if("point"===t.type)return new p({spatialReference:t.spatialReference,x:t.x+e,y:t.y+o,...t.hasZ?{z:t.z+r}:{},...t.hasM?{m:t.m}:{}});if("multipoint"===t.type){const s=[];if(t.hasZ&&t.hasM)for(let i=0;i<t.points.length;i++){const n=t.points[i];s.push([n[0]+e,n[1]+o,n[2]+r,n[3]])}else if(t.hasZ)for(let i=0;i<t.points.length;i++){const n=t.points[i];s.push([n[0]+e,n[1]+o,n[2]+r])}else if(t.hasM)for(let r=0;r<t.points.length;r++){const i=t.points[r];s.push([i[0]+e,i[1]+o,i[2]])}else for(let r=0;r<t.points.length;r++){const i=t.points[r];s.push([i[0]+e,i[1]+o])}return new a({spatialReference:t.spatialReference,hasZ:t.hasZ,hasM:t.hasM,points:s})}if("polygon"===t.type||"polyline"===t.type){const s=g(t,e,o);return 0!==r&&t.hasZ&&y(s,r),s}return t.clone()}function g(t,e,o){const r=new m;return r.shift(e,o),l(t,r)}function y(t,e){for(const o of f(t))for(const t of o){c(t)[2]+=e}}export{h as createPresetServiceEdit,u as translate};