UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 5.85 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"../../core/Error.js";import{makeHandle as i}from"../../core/handleUtils.js";import"../../core/has.js";import{destroyMaybe as s}from"../../core/maybe.js";import{watch as a}from"../../core/reactiveUtils.js";import{property as r,subclass as o}from"../../core/accessorSupport/decorators.js";import l from"../../layers/GraphicsLayer.js";import{isSceneLayer as d}from"../../layers/support/layerUtils.js";import{highlightsSupported as h}from"../../views/support/layerViewUtils.js";import n from"./UpdateFeatureWorkflowData.js";import{UpdateRecordWorkflow as c,handleKeys as p}from"./UpdateRecordWorkflow.js";import{getVisualVariableAttributes as u,setUpGeometryUpdate as w,updateGraphicSymbolWhenRequired as y,swapForEditingSession as m,cloneGraphicExceptMesh as f,canCreateInteractiveEditSession as k,isTerminalUpdateEventType as g}from"./workflowUtils.js";import _ from"../Sketch/SketchViewModel.js";var v;const V={...p,highlights:Symbol(),sketchGraphics:Symbol(),sketchViewModel:Symbol(),waitingForTool:Symbol()};let b=v=class extends c{constructor(e){super(e),this.type="update-feature",this._layerViewEditSession=null,this._sketchGraphicClone=null,this._sketchLayer=null,this._sketchViewModel=null,this._webStyleCache=new Map}destroy(){this._layerViewEditSession?.rollback()}get curveResizeDisabled(){return this.data.curveResizeDisabled}get curveUpdatesDisabled(){return this.data.curveUpdatesDisabled}get sketchUpdateOptions(){const{capabilities:e,layer:t}=this.data.editorItem;return{enableScaling:!this.curveResizeDisabled,multipleSelectionEnabled:!1,reshapeOptions:{enableCreateCurveFromStraightEdge:!d(t)&&e.supportsTrueCurve}}}get supportsSplitFeatureWorkflow(){return this.data.supportsSplitFeatureWorkflow}get viewGraphic(){return this._sketchViewModel?this._sketchGraphicClone:this.data.edits.feature??this.fullFeature}async commit(){this.removeHandles(V.sketchGraphics);try{const e=this.data.edits.stagedForDelete;await super.commit();const t=this._layerViewEditSession;e?t?.rollback():t?.commit()}catch(e){throw await this._configureSketchViewModel(),new t("editor-workflow:failed-to-commit","An error occurred when sending the updates to the service",{error:e})}}async start(){return await super.start(),await this._initializeSketchViewModel()}_initializeFormViewModel(){super._initializeFormViewModel(),this.addHandles([this._formViewModel.on("value-change",e=>{this._layerViewEditSession?.setAttribute(e.fieldName,e.value)}),a(()=>this._formViewModel.feature?.sourceLayer,e=>this._sketchGraphicClone.sourceLayer=e)])}_configureHighlight(){const{edits:e,layerView:t}=this.data;h(t)&&this.addHandles(t.highlight(e.feature),V.highlights)}async _configureSketchViewModel(){const{_sketchLayer:e,_sketchViewModel:t}=this;if(!t||!e)return;const{data:i,_formViewModel:s,_sketchGraphicClone:a}=this,{edits:r,viewModel:o}=i,l=r.feature,{view:d}=o,h=u(l),n=await w({feature:l,featureClone:a,visualVariableAttributes:h,sketchLayer:e,sketchViewModel:t,updateOptions:this.sketchUpdateOptions,view:d,webStyleCache:this._webStyleCache,onUpdate:({geometry:e,attributes:t},i)=>{if(r.updateAttributes(t),r.updateGeometry(e),s.feature&&(s.feature.geometry=e),null!=h.rotation){const{field:e}=h.rotation;s.setValue(e,t[e])}if(null!=h.size){const{field:e}=h.size;s.setValue(e,t[e])}("undo"===i.type||"redo"===i.type||"update"===i.type&&null!=i.toolEventInfo&&g(i.toolEventInfo.type))&&s.notifyFeatureGeometryChanged()},addUpdatingPromise:e=>{this._updatingHandles.addPromise(e)},addHandle:e=>{this.addHandles(e,V.waitingForTool)}});this.addHandles(n,V.sketchGraphics),t.addHandles(n)}async _initializeSketchViewModel(){const{data:e,_sketchGraphicClone:t}=this,{readOnly:a}=e,r=e.edits.feature,{capabilities:o,layer:d}=e.editorItem,h=e.viewModel.view;if(this.removeHandles([V.highlights,V.sketchGraphics,V.sketchViewModel,V.waitingForTool]),!o.update.geometry||a||this.curveUpdatesDisabled)return{enter:async()=>{this.hasHandles(V.highlights)||this._configureHighlight()},exit:()=>this.removeHandles([V.highlights])};const n=new l({elevationInfo:d.elevationInfo,internal:!0,listMode:"hide",title:"updateFeaturesWorkflow-internal"}),c=new _({allowDeleteKey:!1,layer:n,sketchOptions:e.sketchOptions,snappingManager:e.snappingManager,useLegacyCreateTools:e.viewModel.useLegacyCreateTools,updateOnGraphicClick:!1,defaultUpdateOptions:this.sketchUpdateOptions,view:h});return this._sketchLayer=n,this._sketchViewModel=c,h?.map.add(n),await(h?.whenLayerView(n)),this.addHandles(i(()=>{h?.destroyed||h?.map.remove(n),n.destroyed||n.destroy(),this._sketchViewModel=s(c)}),V.sketchViewModel),await y(t,this._webStyleCache,"2d"===h?.type?h.scale:null),this.addHandles([await m(n,h,r,t)]),{enter:async()=>{this.hasHandles(V.sketchGraphics)||await this._configureSketchViewModel()},exit:()=>this.removeHandles([V.sketchGraphics]),viewModel:c}}_onFullFeatureLoaded(e){super._onFullFeatureLoaded(e);const t=this._sketchGraphicClone=f(e),{edits:i,layerView:s}=this.data;i.updateGeometry(e.geometry),i.trackChanges(),k(s)&&(this._layerViewEditSession=s.createInteractiveEditSession(t))}static async create(e){const t=new v({data:await n.create(e),onCommit:this._onCommitFactory(e.applyEdits)});return t._set("steps",this._createWorkflowSteps(t)),t}get test(){}};e([r()],b.prototype,"curveResizeDisabled",null),e([r()],b.prototype,"curveUpdatesDisabled",null),e([r()],b.prototype,"sketchUpdateOptions",null),e([r()],b.prototype,"supportsSplitFeatureWorkflow",null),e([r()],b.prototype,"_layerViewEditSession",void 0),e([r()],b.prototype,"_sketchGraphicClone",void 0),e([r()],b.prototype,"_sketchLayer",void 0),e([r()],b.prototype,"_sketchViewModel",void 0),b=v=e([o("esri.widgets.Editor.UpdateFeatureWorkflow")],b);export{b as UpdateFeatureWorkflow,V as handleKeys};