@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 5.35 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{_ as e}from"../../../chunks/tslib.es6.js";import i from"../../../core/Accessor.js";import{createTask as t}from"../../../core/asyncUtils.js";import{makeHandle as r,handlesGroup as s}from"../../../core/handleUtils.js";import a from"../../../core/Logger.js";import{getOrCreateMapValue as o}from"../../../core/MapUtils.js";import{throwIfAborted as n}from"../../../core/promiseUtils.js";import{whenOnce as p,watch as d}from"../../../core/reactiveUtils.js";import{addMaybe as c}from"../../../core/SetUtils.js";import{property as h}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/RandomLCG.js";import{subclass as u}from"../../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as l}from"../../../core/support/UpdatingHandles.js";import m from"../../../layers/GraphicsLayer.js";import{isSubtypeSublayer as y,isKnowledgeGraphSublayer as v}from"../../../layers/support/layerUtils.js";import{getDisplayedSymbol as g}from"../../../symbols/support/symbolUtils.js";import{GraphicState as f}from"../../3d/layers/graphics/GraphicState.js";var _;!function(e){e[e.FeatureMove=0]="FeatureMove",e[e.VertexMove=1]="VertexMove"}(_||(_={}));const w=()=>a.getLogger("esri.views.draw.support.ConnectedReshapeManager"),G=Symbol();let L=class extends i{constructor(e){super(e),this.activeOperationType=null,this.providerFactories=[],this.view=null,this._activeProviders=new Set,this._graphics=new Map,this._modifiedFeatures=new Map,this._modifiedGraphicsLayer=new m({listMode:"hide",internal:!0,title:"Connected Reshape Modified Graphics (Internal)"}),this._pendingGraphicsLayer=new m({listMode:"hide",internal:!0,title:"Connected Reshape Pending Graphics (Internal)"}),this._pendingFeatures=new Map,this._updatingHandles=new l}initialize(){this.view.map.addMany([this._modifiedGraphicsLayer,this._pendingGraphicsLayer])}destroy(){this.view.destroyed||this.view.map.removeMany([this._modifiedGraphicsLayer,this._pendingGraphicsLayer]),this._modifiedGraphicsLayer.destroy(),this._pendingGraphicsLayer.destroy(),this._updatingHandles.destroy()}get updating(){return this._updatingHandles.updating||Array.from(this._activeProviders).some((e=>e.updating))}startFeatureMove(e){this.activeOperationType=_.FeatureMove,this._activeProviders.clear();for(const i of this.providerFactories)c(this._activeProviders,i.getFeatureReshapeProvider(e))}startVertexMove(e,i){this.activeOperationType=_.VertexMove,this._activeProviders.clear();for(const t of this.providerFactories)c(this._activeProviders,t.getVertexReshapeProvider(e,i))}finish(){this.activeOperationType=null,this._activeProviders.clear();for(const[e,i]of this._pendingFeatures){this._pendingFeatures.delete(e),this._modifiedFeatures.set(e,i);const t=this._graphics.get(e);t&&(this._modifiedGraphicsLayer.add(t),this._pendingGraphicsLayer.remove(t))}}translate(e,i,t=0){if(null===this.activeOperationType)return;const r=P(e),s=P(i),a=P(t);for(const o of this._activeProviders){const e=o.translate(r,s,a);this._update(e)}}async _initializeGraphic(e,i){e.symbol??=await this._updatingHandles.addPromise(g(e,{scale:this.view.scale,useSourceLayer:!0})),this._pendingFeatures.has(i.uniqueId)?this._pendingGraphicsLayer.add(e):this._modifiedFeatures.has(i.uniqueId)&&this._modifiedGraphicsLayer.add(e),this.addHandles(await F(i.originalGraphic,e,this.view),G)}_update(e){for(const i of e){const e=this._modifiedFeatures.delete(i.uniqueId);this._pendingFeatures.set(i.uniqueId,i);const t=o(this._graphics,i.uniqueId,(()=>{const e=i.graphic.cloneShallow();return this._initializeGraphic(e,i),e}));t.geometry=i.graphic.geometry,e&&(this._modifiedGraphicsLayer.remove(t),this._pendingGraphicsLayer.add(t))}}get test(){return{activeProviders:this._activeProviders,modifiedFeatures:this._modifiedFeatures,modifiedGraphicsLayer:this._modifiedGraphicsLayer,pendingFeatures:this._pendingFeatures,pendingGraphicsLayer:this._pendingGraphicsLayer}}};async function F(e,i,a){const o=e.sourceLayer,d=e.getObjectId();if(null==d)return w().error("editing:cannot-hide-graphic","Unable to hide original graphic because it has no objectId."),r();let c=null;function h(e){c?.abort(),c=t((async i=>{const t=await b(a,o);n(i),t&&t.setVisibility?.(d,e)}))}return await M(a,i),h(!1),s([j(a,i,(e=>h(!e))),r((async()=>{h(!0);const e=await b(a,o);await p((()=>!e?.updating))}))])}function j(e,i,t){if("3d"===e.type){const r=new f({graphic:i});return s([e.trackGraphicState(r),d((()=>r.displaying),t)])}return d((()=>i.visible),t)}async function M(e,i){if("3d"===e.type){const t=new f({graphic:i}),r=e.trackGraphicState(t);await p((()=>t.displaying||t.error)),r.remove()}else await p((()=>i.visible))}async function b(e,i){const t=y(i)||v(i)?i.parent:i;return t?e.whenLayerView(t):null}function P(e){return isNaN(e)?0:e}e([h()],L.prototype,"activeOperationType",void 0),e([h()],L.prototype,"providerFactories",void 0),e([h()],L.prototype,"updating",null),e([h({constructOnly:!0})],L.prototype,"view",void 0),L=e([u("esri.views.draw.support.ConnectedReshapeManager")],L);export{L as ConnectedReshapeManager,_ as ConnectedReshapeOperationType,F as swapForEditingSession,j as watchGraphicVisibility,M as whenGraphicDisplayed};