UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) • 35.9 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as t}from"tslib";import e from"../../../Graphic.js";import{createTask as i}from"../../../core/asyncUtils.js";import s from"../../../core/Collection.js";import o from"../../../core/Error.js";import{EventedAccessor as r}from"../../../core/Evented.js";import n from"../../../core/Logger.js";import{getOrCreateMapValue as a}from"../../../core/MapUtils.js";import{destroyMaybe as h,abortMaybe as p,assertIsSome as c}from"../../../core/maybe.js";import{pausable as l,when as d,watch as m,initial as v,sync as u}from"../../../core/reactiveUtils.js";import{property as y,subclass as _}from"../../../core/accessorSupport/decorators.js";import{UpdatingHandles as g}from"../../../core/support/UpdatingHandles.js";import f from"../../../geometry/Point.js";import G from"../../../geometry/Polyline.js";import{fromPolylineUsingImportOperator as b,toGeometry as x}from"../../../geometry/operators/support/apiConverter.js";import{closeRingsAndFixWinding as M,geometryToCoordinates as C}from"../../../geometry/support/coordsUtils.js";import{isPoint as S}from"../../../geometry/support/typeUtils.js";import{interpolateCircle as E}from"../../../geometry/support/curves/circleUtils.js";import{deriveCircleFromCircularArc as w,toEllipticArc7 as I}from"../../../geometry/support/curves/circularArcUtils.js";import{getPaths as V,getEndpoint as O,isCircularArc as H,isEllipticArc4 as L,isBezierCurve as k,isCoordinate as P,cloneCurve as T,isEllipticArc7 as R}from"../../../geometry/support/curves/curveUtils.js";import{deriveCircleFromEllipticArc4 as A}from"../../../geometry/support/curves/ellipticArc4Utils.js";import{wrapAtan2 as U}from"../../../geometry/support/curves/mathUtils.js";import j from"../../../layers/GraphicsLayer.js";import{SnappingVisualizer2D as F}from"../../2d/interactive/SnappingVisualizer2D.js";import{ConnectedReshapeManager as D}from"./ConnectedReshapeManager.js";import{screenDeltaToMapDelta as K,cloneMove as z}from"./drawUtils.js";import N from"./GraphicMover.js";import $ from"./HighlightHelper.js";import{addUniqueLayer as q,isConnectedReshapeSupportedLayer as X}from"./layerUtils.js";import{createTooltipInfos as Y,connectTooltip as Z,updateTranslateTooltipInfo as B,updateTranslateVertexTooltipInfo as J}from"./reshapeTooltipUtils.js";import{defaultSymbols as Q,createMidpointGraphics as W,createVertexGraphics as tt,createCurveControlPointGraphics as et,createCurveConstructionLineGraphics as it,attributeKeys as st,getMidpoint as ot,controlPointKinds as rt,fastCloneGeometry as nt,saveUpdatedCurveOrCoordinate as at,toolIdAttribute as ht,splitCurve as pt,isSingleSegmentCircle as ct,isSingleSegmentEllipse as lt}from"./reshapeUtils.js";import{ViewEventPriorities as dt}from"../../input/InputManager.js";import{createCoordinateHelper as mt}from"../../interactive/coordinateHelper.js";import{sketchKeys as vt}from"../../interactive/keybindings.js";import{EditGeometryOperations as ut}from"../../interactive/editGeometry/EditGeometryOperations.js";import yt from"../../interactive/sketch/SketchOptions.js";import{SnappingContext as _t}from"../../interactive/snapping/SnappingContext.js";import{makeTooltip as gt,enterInputModeIfAvailable as ft}from"../../interactive/tooltip/tooltipCommonUtils.js";const Gt=Symbol(),bt={mode:"on-the-ground",offset:0};let xt=class extends r{constructor(t){super(t),this._updateHandlesOnExternalGeometryChange=null,this._activeOperationInfo=null,this._connectedReshapeManager=null,this._editGeometryOperations=null,this._primaryGraphicMoving=!1,this._segmentLabels=null,this._segmentLabelsImportTask=null,this._mover=null,this._snappingContext=null,this._snappingGraphicsLayer=null,this._hoverGraphic=null,this._snappingTask=null,this._stagedVertex=null,this._relatedGraphicIndex=null,this._updatingHandles=new g,this.callbacks={onReshapeStart(){},onReshape(){},onReshapeStop(){},onMoveStart(){},onMove(){},onMoveStop(){},onGraphicClick(){}},this.connectedReshapeProviders=null,this.enableMidpoints=!0,this.enableCurveOnMidpoint=!1,this.enableMovement=!0,this.enableVertices=!0,this.filterVerticesEnabled=!0,this.graphic=null,this.highlightName=null,this.highlightsEnabled=!0,this.layer=null,this.snappingManager=null,this.symbols=Q,this.tooltip=null,this.activeTooltipInfo=null,this.sketchOptions=new yt,this.type="reshape",this.vertexGraphics=new s,this.curveControlPointGraphics=new s,this.constructionLineGraphics=new s,this.midpointGraphics=new s,this.selectedManipulators=new s,this.view=null}initialize(){const t=this.view;this._highlightHelper=new $({view:t}),this._setup(),this._updateHandlesOnExternalGeometryChange=l(()=>this.graphic?.geometry,t=>{if(!t||!0===this._primaryGraphicMoving)return;const e=new Set(this.selectedManipulators.map(Lt));this._highlightHelper.removeAll(),this._setUpHighlights(),this._setupGraphics(),this._clearSelection(),this.vertexGraphics.filter(t=>e.has(Lt(t))).forEach(t=>this._addToSelection(t)),this.curveControlPointGraphics.filter(t=>e.has(Lt(t))).forEach(t=>this._addToSelection(t));const{enableMovement:i,_mover:s,graphic:o,midpointGraphics:r,vertexGraphics:n,curveControlPointGraphics:a}=this,h=n.concat(r,a).toArray();i&&h.push(o),s?.set("graphics",h)},u),this.tooltip=gt(()=>({view:t,options:this.sketchOptions.tooltips})),this.tooltipInfos=Y(this.sketchOptions),this.addHandles([d(()=>t?.ready,()=>{const{layer:t,view:e}=this;q(e,t),this.addHandles(e.on("key-down",t=>this._keyDownHandler(t),dt.TOOL))},{once:!0,initial:!0}),m(()=>this.graphic,()=>this.refresh()),...this._effectiveFilterVerticesEnabled?[m(()=>[this.view.viewpoint,this.view.stationary],()=>{this.view.stationary&&this.refresh()})]:[],m(()=>this.layer,(t,e)=>{e&&(this._clearSelection(),this._resetGraphics(e)),this.refresh()}),m(()=>[this.highlightsEnabled,this.highlightName],()=>{this._highlightHelper?.removeAll(),this._setUpHighlights()}),m(()=>this.enableMidpoints,()=>this.refresh()),Z(this.tooltip,()=>this._tooltipsContext,this._updatingHandles),m(()=>this.sketchOptions.labels.enabled,t=>{this._segmentLabels?this._segmentLabels.visible=t:this._setUpGeometryHelper()}),m(()=>this.view.effectiveTheme.accentColor,()=>this._updateSymbolsForTheme(),v),this._updateHandlesOnExternalGeometryChange]),this._updateTooltip()}destroy(){this._reset(),this._mover=h(this._mover),this._connectedReshapeManager=h(this._connectedReshapeManager),this.tooltip=h(this.tooltip),this._segmentLabelsImportTask=p(this._segmentLabelsImportTask),this._segmentLabels=h(this._segmentLabels),this._updatingHandles=h(this._updatingHandles)}get _coordinateHelper(){return this._editGeometryOperations?.data.coordinateHelper??mt(!!this.graphic.geometry?.hasZ,!!this.graphic.geometry?.hasM,this.view.spatialReference)}get _effectiveFilterVerticesEnabled(){return"2d"===this.view?.type&&this.filterVerticesEnabled}get test(){return{segmentLabels:this._segmentLabels}}get _selectedManipulator(){return 1===this.selectedManipulators.length?this.selectedManipulators.at(0):void 0}get _tooltipsContext(){const{automaticAreaMeasurementUtils:t,automaticLengthMeasurementUtils:e,sketchOptions:i,activeTooltipInfo:s,graphic:o}=this;return{sketchOptions:i,activeTooltipInfo:s,graphic:o,selectedVertex:this._selectedManipulator,automaticAreaMeasurementUtils:t,automaticLengthMeasurementUtils:e,updateGeometry:(t,e,i,s,o)=>{this._setUpGeometryHelper();const r=t===this.graphic;r?this._emitMoveStartEvent(0,0):this._emitReshapeStartEvent(t);const n=!0;if(this._syncGeometryAfterVertexMove(t,e,s,o,n),r){const{view:t}=this,s=t.toScreen(i),o=t.toScreen(e),r=(o?.x??0)-(s?.x??0),n=(o?.y??0)-(s?.y??0);this._emitMoveEvent(r,n),this._emitMoveStopEvent(r,n)}else this._emitReshapeEvent(t),this._emitReshapeStopEvent(t)}}}get state(){const t=this.view.ready,e=!(!this.graphic||!this.layer);return t&&e?"active":t?"ready":"disabled"}get updating(){return this._updatingHandles.updating}isUIGraphic(t){return t===this.graphic||this._isMidpoint(t)||this._isCurveControlPoint(t)||this._isVertex(t)||this._isConstructionLine(t)}refresh(t){if(this._reset(),this._setup(),t){for(const e of this.vertexGraphics)t.has(Lt(e))&&this._addToSelection(e);for(const e of this.curveControlPointGraphics)t.has(Lt(e))&&this._addToSelection(e)}}reset(){this.graphic=null}clearSelection(){this._clearSelection()}removeSelectedVertices(){const{selectedManipulators:t}=this;t.length&&this._removeVertices(t)}_setup(){const{graphic:t,layer:e}=this;if(!e||null==t?.geometry)return;const i=t.geometry;"mesh"!==i.type&&"extent"!==i.type?("polygon"===i.type&&M(i),this._setUpHighlights(),this._setupGraphics(),this._setupMover(),this._setupConnectedReshapeManager(),this._setUpGeometryHelper()):this._logGeometryTypeError()}_setUpHighlights(){this.highlightsEnabled&&this.graphic&&this._highlightHelper?.add(this.graphic,this.highlightName)}_setUpGeometryHelper(){const t=this.graphic.geometry;if(null==t||"mesh"===t.type||"extent"===t.type)return this._segmentLabels=h(this._segmentLabels),void this._logGeometryTypeError();this._editGeometryOperations?this._syncEditGeometryOperations(t):this._editGeometryOperations=ut.fromGeometry(t,2,{allowCurves:!0}),this._updatingHandles.addPromise(this._setupSegmentLabels())}_saveSnappingContextForHandle(t,e){this._snappingGraphicsLayer=new j({listMode:"hide",internal:!0,title:"Reshape snapping layer"}),this.view.map.layers.add(this._snappingGraphicsLayer);const i=this._editGeometryOperations;c(i),this._snappingContext=new _t({editGeometryOperations:i,elevationInfo:bt,pointer:e.viewEvent?.pointerType||"mouse",excludeFeature:this.graphic,feature:this.graphic,visualizer:new F(this._snappingGraphicsLayer),vertexHandle:this._getVertexFromEditGeometry(t)})}_reset(){this._clearSelection(),this._highlightHelper?.removeAll(),this._updateTooltip(),this._resetGraphics(),this._resetSnappingStateVars(),this._segmentLabelsImportTask=p(this._segmentLabelsImportTask),this._segmentLabels=h(this._segmentLabels),this._activeOperationInfo=null,this._mover=h(this._mover),this.removeHandles(Gt)}_resetSnappingStateVars(){null!=this.snappingManager&&this.snappingManager.doneSnapping(),null!=this._snappingGraphicsLayer&&(this.view?.map&&this.view.map.layers.remove(this._snappingGraphicsLayer),this._snappingGraphicsLayer.destroy()),this._snappingTask=p(this._snappingTask),this._snappingTask=null,this._snappingContext=null,this._stagedVertex=null}_resetGraphics(t){this._removeMidpointGraphics(t),this._removeVertexGraphics(t),this._removeCurveGraphics(t),this._updateTooltip()}_removeMidpointGraphics(t=this.layer){const{midpointGraphics:e}=this;t?.removeMany(e.items),e.drain(h)}_removeVertexGraphics(t=this.layer){const{vertexGraphics:e}=this;this._relatedGraphicIndex=null,t?.removeMany(e.items),e.drain(h)}_removeCurveGraphics(t=this.layer){const{curveControlPointGraphics:e,constructionLineGraphics:i}=this;t?.removeMany(e.items),t?.removeMany(i.items),e.drain(h),i.drain(h)}_setupGraphics(){const t=this.graphic.geometry;if(null!=t&&("polyline"===t.type||"polygon"===t.type||"multipoint"===t.type)){const e=Mt(t);this.enableMidpoints&&"multipoint"!==t.type&&this._setUpMidpointGraphics(e),this.enableVertices&&(this._setUpVertexGraphics(e),this._setupCurveGraphics(e))}}_setUpMidpointGraphics(t){this._removeMidpointGraphics();const e=W(t,this.symbols,this._coordinateHelper,"polygon"===this.graphic.geometry?.type,this.filterVerticesEnabled?this.view.extent:null,this.filterVerticesEnabled?this.view.resolution:-1);this.midpointGraphics.addMany(e),this.layer.addMany(e)}_setUpVertexGraphics(t){if(this._removeVertexGraphics(),this._effectiveFilterVerticesEnabled){const e=tt(t,this.symbols,this._coordinateHelper,this.view.extent,this.view.resolution);this._relatedGraphicIndex=e.graphicIndex,this.vertexGraphics.addMany(e.graphics),this.layer.addMany(e.graphics)}else{const e=tt(t,this.symbols,this._coordinateHelper,null,-1).graphics;this.vertexGraphics.addMany(e),this._storeRelatedVertexIndices(),this.layer.addMany(e)}}_setupCurveGraphics(t){this._removeCurveGraphics();const e=et(t,this.symbols,this._coordinateHelper),i=it(t,this.symbols,this._coordinateHelper);this.curveControlPointGraphics.addMany(e),this.constructionLineGraphics.addMany(i),this.layer.addMany(i),this.layer.addMany(e)}async _setupSegmentLabels(){const t=this._editGeometryOperations,e=this.sketchOptions.labels.enabled;if(t&&this._segmentLabels?.context?.editGeometryOperations===t&&e||(this._segmentLabels=h(this._segmentLabels)),!this._segmentLabels&&t&&e){const e=this._segmentLabelsImportTask??=i(async t=>{const e=import("../../2d/interactive/SegmentLabels2D.js"),{SegmentLabels2D:i}=await this._updatingHandles.addPromise(e);return t.aborted?null:i}),s=await e.promise;if(!s)return;this._segmentLabels=h(this._segmentLabels),this._segmentLabels=new s({context:{view:this.view,editGeometryOperations:t,elevationInfo:bt,labelOptions:this.sketchOptions.labels,automaticLengthMeasurementUtils:this.automaticLengthMeasurementUtils},visible:!0})}}_updateSymbolsForTheme(){const t=this.view.effectiveTheme.accentColor;this.symbols={vertices:{...this.symbols.vertices,default:this.symbols.vertices.default.clone().set("color",t),hover:this.symbols.vertices.hover?.clone().set("color",t)},controlPoints:{...this.symbols.controlPoints,default:this.symbols.controlPoints.default.clone().set("color",t),hover:this.symbols.controlPoints.hover?.clone().set("color",t)},midpoints:{...this.symbols.midpoints},constructionLines:this.symbols.constructionLines.clone().set("color",t)};for(const e of this.vertexGraphics)this._isSelected(e)?e.symbol=this.symbols.vertices.selected:this._hoverGraphic===e?e.symbol=this.symbols.vertices.hover:e.symbol=this.symbols.vertices.default;for(const e of this.curveControlPointGraphics)this._isSelected(e)?e.symbol=this.symbols.controlPoints.selected:this._hoverGraphic===e?e.symbol=this.symbols.controlPoints.hover:e.symbol=this.symbols.controlPoints.default;for(const e of this.constructionLineGraphics)e.symbol=this.symbols.constructionLines}_storeRelatedVertexIndices(){const t=this.vertexGraphics.items;if(!t)return;const e=t.map(({geometry:t})=>({x:t.x,y:t.y}));for(let i=0;i<e.length;i++){const s=[];for(let t=0;t<e.length;t++){if(i===t)continue;const o=e[i],r=e[t];o.x===r.x&&o.y===r.y&&s.push(t)}t[i].attributes[st.relatedGraphicIndices]=s}}_setupMover(){const{enableMovement:t,graphic:e,midpointGraphics:i,vertexGraphics:s,view:o}=this,r=s.concat(i,this.curveControlPointGraphics).toArray();t&&"multipoint"!==e.geometry?.type&&r.push(e),this._mover=new N({enableMoveAllGraphics:!1,highlightsEnabled:!1,indicatorsEnabled:!1,graphics:r,view:o,callbacks:{onGraphicClick:t=>this._onGraphicClickCallback(t),onGraphicMoveStart:t=>this._onGraphicMoveStartCallback(t),onGraphicMove:t=>this._onGraphicMoveCallback(t),onGraphicMoveStop:t=>this._onGraphicMoveStopCallback(t),onGraphicPointerOver:t=>this._onGraphicPointerOverCallback(t),onGraphicPointerOut:t=>this._onGraphicPointerOutCallback(t)}})}_setupConnectedReshapeManager(){const{connectedReshapeProviders:t}=this;null!=t&&0!==t.length&&(this._connectedReshapeManager=new D({providerFactories:t,view:this.view}))}_onGraphicClickCallback(t){t.viewEvent.stopPropagation();const e=t.graphic,i=this._isCurveControlPoint(e);if(e===this.graphic)this.clearSelection(),this.emit("graphic-click",t),this.callbacks.onGraphicClick?.(t);else if(this._isMidpoint(e)){if(2===t.viewEvent.button)return;const i=this.graphic.clone(),s=this._handleMidpointClickOrStartMove(t);this.refresh(),s.length&&this._emitVertexAddEvent([e],i,s)}else if(this._isVertex(e)||i){if(t.viewEvent.stopPropagation(),2===t.viewEvent.button)return void(i||this._removeVertices(e));t.viewEvent.native.shiftKey||this._clearSelection(),this.selectedManipulators.includes(e)?this._removeFromSelection(e,!0):this._addToSelection(e)}}_setUpOperation(t){const{graphic:e,dx:i,dy:s}=t,o=e===this.graphic;this._resetSnappingStateVars(),this._setUpGeometryHelper(),this._saveSnappingContextForHandle(e,t),this._activeOperationInfo={target:this.graphic,mover:e,operationType:o?"move":"reshape",totalDx:i,totalDy:s}}_onGraphicMoveStartCallback(t){const{dx:e,dy:i,graphic:s}=t,o=this._connectedReshapeManager,r=o?Pt(this.graphic):null;if(s===this.graphic){const{geometry:n}=s;return this._primaryGraphicMoving=!0,this._setUpOperation(t),this._emitMoveStartEvent(e,i),r&&o?.startFeatureMove([r]),this._effectiveFilterVerticesEnabled&&this._resetGraphics(this.layer),void(null!=n&&"point"===n.type&&this._onHandleMove(s,e,i,t,()=>{this._updateTooltip(this.graphic,t.viewEvent),this._emitMoveEvent(e,i)}))}const{selectedManipulators:n}=this;if(!n.includes(s)){if(this._clearSelection(),this._isMidpoint(s)){const e=this.graphic.clone(),i=this._handleMidpointClickOrStartMove(t);i.length&&(this._emitVertexAddEvent([s],e,i),this._refreshGraphicIndicesAttributes(i[0]))}this._addToSelection(s)}if(this._setUpOperation(t),r){const t=n.filter(t=>this._isVertex(t));o?.startVertexMove(r,Tt(t))}this._emitReshapeStartEvent(s),this._onHandleMove(s,e,i,t,()=>{this._updateTooltip(s,t.viewEvent),this._emitReshapeEvent(s)})}_onGraphicMoveCallback(t){const e=this._activeOperationInfo;if(!e)return;const{dx:i,dy:s,graphic:o}=t;e.totalDx+=i,e.totalDy+=s;const{operationType:r}=e,{geometry:n}=o;if(null!=n)if("move"!==r)this._onHandleMove(o,i,s,t,()=>{this._updateTooltip(o,t.viewEvent),this._emitReshapeEvent(o)});else{if("point"===n.type)this._onHandleMove(o,i,s,t,()=>{this._updateTooltip(this.graphic,t.viewEvent),this._emitMoveEvent(i,s)});else if("polyline"===n.type||"polygon"===n.type){const{dxMap:e,dyMap:o}=K(i,s,this.view);if(this._effectiveFilterVerticesEnabled){if(this.selectedManipulators.length>0){const t=this.selectedManipulators.toArray();this.selectedManipulators.removeAll();for(const e of t){if("point"===e.geometry?.type){const{pathIndex:t,pointIndex:i}=e.attributes,s=V(n)[t][i];if(s){const t=O(s);e.geometry=this._coordinateHelper.arrayToPoint(t)}}this._addToSelection(e.clone())}}}else{const t=Mt(n);this._updateVertexGraphicLocations(t)}this._connectedReshapeManager?.translate(e,o,0),this._updateTooltip(this.graphic,t.viewEvent),this._emitMoveEvent(i,s)}this._syncEditGeometryOperations(n)}}_onGraphicMoveStopCallback(t){const e=this._activeOperationInfo;if(this._primaryGraphicMoving=!1,!e)return;const{dx:i,dy:s,graphic:o}=t,{operationType:r}=e;if(e.totalDx+=i,e.totalDy+=s,this._onHandleMove(o,i,s,t,()=>"move"===r?this._emitMoveStopEvent():this._emitReshapeStopEvent(o)),this._effectiveFilterVerticesEnabled&&"move"===r){const t=new Set;for(const e of this.selectedManipulators)t.add(Lt(e));return this.refresh(t),void this._updateTooltip()}if(this._isMidpoint(o)||o.getAttribute(st.curveFromStraightEdgeFlag))return this.refresh(),void this._connectedReshapeManager?.finish();this._updateTooltip(this._isVertex(o)?o:null),this._resetSnappingStateVars(),this._connectedReshapeManager?.finish(),this._activeOperationInfo=null}_updateVertexGraphicLocations(t){const{_coordinateHelper:e}=this;for(const i of this.vertexGraphics){const{pathIndex:s,pointIndex:o}=i.attributes;i.geometry=e.arrayToPoint(O(t[s][o]))}this._updateMidpointGraphicLocations(t),this._updateCurveGraphicLocations(t)}_updateMidpointGraphicLocations(t,e){const{_coordinateHelper:i}=this;if(e)for(const s of this.midpointGraphics){const{pathIndex:o,pointIndexStart:r,pointIndexEnd:n}=s.attributes;if(!e.has(o))continue;const a=e.get(o);if(!a.has(r)&&!a.has(n))continue;const h=t[o];s.geometry=new f(ot(h[r],h[n],i))}else for(const s of this.midpointGraphics){const{pathIndex:e,pointIndexStart:o,pointIndexEnd:r}=s.attributes,n=t[e];s.geometry=new f(ot(n[o],n[r],i))}}_updateCurveGraphicLocations(t){const{spatialReference:e}=this._coordinateHelper,i=new Map;for(const s of this.selectedManipulators){const[t,e]=Ht(s);null!=t&&null!=e&&s.getAttribute(st.controlPointKind)&&a(i,t,()=>new Set)?.add(e)}for(const s of this.curveControlPointGraphics){const[e,o]=Ht(s);if(i.get(e)?.has(o))continue;const r=t[e][o];if(H(r)||L(r)){const i=O(t[e][o-1]),n=H(r)?w(i,r):A(i,r),[a,h]=E(n,.25);s.geometry=new f({x:a,y:h,spatialReference:this._coordinateHelper.spatialReference})}else if(k(r)){const t=s.getAttribute(st.controlPointKind),[e,i]=t===rt.bezier.cp1?r.b[1]:r.b[2];s.geometry=new f({x:e,y:i,spatialReference:this._coordinateHelper.spatialReference})}}for(const s of this.constructionLineGraphics){const i=s.getAttribute(st.controlPointKind),[o,r]=Ht(s),n=t[o],a=O(n[r-1]),h=O(n[r]),p=t[o][r];i===rt.bezier.line1?s.geometry=new G({paths:[[[a[0],a[1]],[...p.b[1]]]],spatialReference:e}):s.geometry=new G({paths:[[[h[0],h[1]],[...p.b[2]]]],spatialReference:e})}}_refreshGraphicIndicesAttributes(t){const{componentIndex:e,vertexIndex:i}=t,s=t=>{const[s,o]=Ht(t);s===e&&o>=i&&t.setAttribute(st.pointIndex,o+1)};this.vertexGraphics.forEach(s),this.curveControlPointGraphics.forEach(s),this.constructionLineGraphics.forEach(s);for(const o of this.midpointGraphics){if(o.getAttribute(st.pathIndex)!==e)continue;const t=o.getAttribute(st.pointIndexStart);t>=i&&(o.setAttribute(st.pointIndexStart,t+1),o.setAttribute(st.pointIndexEnd,o.getAttribute(st.pointIndexEnd)+1))}}_getVertexFromEditGeometry(t){const[e,i]=Ht(t);return c(this._editGeometryOperations),this._editGeometryOperations.data.parts[e].vertices[i]}_onHandleMove(t,e,s,o,r){p(this._snappingTask);const n=this._snappingContext;if(!n)return;const a=t.geometry,h="graphic-move-stop"===o.type;if(a&&S(a))if(null!=this.snappingManager&&this.selectedManipulators.length<2&&!h){const o=this.snappingManager;this._stagedVertex=o.update({point:a,context:n}),this._syncGeometryAfterVertexMove(t,new f(this._stagedVertex),e,s,h),r(),this._snappingTask=i(async i=>{const p=await o.snap({point:a,context:n,signal:i});p.valid&&(this._stagedVertex=p.apply(),this._syncGeometryAfterVertexMove(t,new f(this._stagedVertex),e,s,h),r())})}else{const i=null!=this._stagedVertex?new f(this._stagedVertex):a;this._syncGeometryAfterVertexMove(t,i,e,s,h),r()}else r()}_syncGeometryAfterVertexMove(t,e,i,s,o=!1){const r=nt(this._editGeometryOperations?.data.geometry);if(!r)return;const{_coordinateHelper:n}=this,a=n.pointToVector(e),h=this._getVertexFromEditGeometry(t);let p=null;if(h){const t=n.getZ(a);p=[h.pos[0],h.pos[1]];const e=a[0]-h.pos[0],i=a[1]-h.pos[1],s=null!=t?t-h.pos[2]:0;"point"!==r.type&&"mesh"!==r.type||this._editGeometryOperations?.moveVertices([h],e,i,s),this._connectedReshapeManager?.translate(e,i,s)}if("point"===r.type)t.geometry=e;else if("mesh"===r.type)t.geometry=r.centerAt(e);else{if(t!==this.graphic){p&&!this._isVertex(t)&&(p=null);const o=n.spatialReference,[a,h]=Ht(t);let c=Ct(r);const l=n.pointToArray(e);if(this._updateGeometryFromGraphic(t,c,a,h,l,o,"polygon"===r.type),this._isVertex(t)||this._isCurveControlPoint(t)){const e=new Map;e.set(a,new Set([h])),c=this._moveRelatedCoordinates(c,t,l,e,p),c=this._moveSelectedHandleCoordinates(c,t,i,s,"polygon"===r.type),this._updateMidpointGraphicLocations(c,e),this._updateCurveGraphicLocations(c)}else this._isMidpoint(t)&&this._updateCurveGraphicLocations(c);at(r,c)}this._updateGraphicGeometry(r),this._syncEditGeometryOperations(r),o&&(this._mover?this._mover.updateGeometry(this._mover.graphics.indexOf(t),e):t.geometry=e)}}_syncEditGeometryOperations(t){const e=this._editGeometryOperations?.trySetGeometry(t);e||(this._editGeometryOperations=null,this._setUpGeometryHelper())}_moveRelatedCoordinates(t,e,i,s,o){if(this._effectiveFilterVerticesEnabled&&this._relatedGraphicIndex&&o){const r=this._relatedGraphicIndex.search({minX:o[0],maxX:o[0],minY:o[1],maxY:o[1]});for(const n of r)n.coordinate[0]===o[0]&&n.coordinate[1]===o[1]&&n.graphic&&(s&&a(s,n.pathIndex,()=>new Set).add(n.pointIndex),Ot(t,n.pathIndex,n.pointIndex,i,this._coordinateHelper.spatialReference),this._relatedGraphicIndex.remove(n),n.coordinate[0]=e.geometry.x,n.coordinate[1]=e.geometry.y,n.graphic.geometry=e.geometry,this._relatedGraphicIndex.insert(n));return t}const{relatedGraphicIndices:r}=e.attributes,n=this._coordinateHelper.spatialReference;if(!r?.length)return t;for(const h of r){const o=this.vertexGraphics.at(h),[r,p]=Ht(o);s&&a(s,r,()=>new Set).add(p),Ot(t,r,p,i,n),o.geometry=e.geometry}return t}_moveSelectedHandleCoordinates(t,e,i,s,o){const r=this._coordinateHelper.spatialReference;for(const n of this.selectedManipulators)if(n!==e){const[e,a]=Ht(n),h=n.getAttribute(st.relatedGraphicIndices),p=z(n.geometry,i,s,this.view),c=C(p);if(n.geometry=p,this._updateGeometryFromGraphic(n,t,e,a,c,r,o),h?.length)for(const i of h){const e=this.vertexGraphics.at(i),[s,o]=Ht(e);Ot(t,s,o,c,r),e.geometry=p}}return t}_updateGeometryFromGraphic(t,e,i,s,o,r,n){const a=e[i].length-1;this._isCurveControlPoint(t)?Et(e,i,s,[o[0],o[1]],t.getAttribute(st.controlPointKind)):(Ot(e,i,s,o,r),n&&(0===s?Ot(e,i,a,o,r):s===a&&(e[i][0]=o)))}_onGraphicPointerOverCallback(t){const e=t.graphic;this._hoverGraphic=e;const i=this._isVertex(e);i&&!this._isSelected(e)?e.symbol=this.symbols.vertices.hover:this._isCurveControlPoint(e)&&!this._isSelected(e)&&(e.symbol=this.symbols.controlPoints.hover),this._updateTooltip(i?e:null),this._updateHoverCursor(e)}_onGraphicPointerOutCallback(t){const e=t.graphic;this._hoverGraphic=null,this._isVertex(e)&&!this._isSelected(e)&&(e.symbol=this.symbols.vertices.default),this._isCurveControlPoint(e)&&!this._isSelected(e)&&(e.symbol=this.symbols.controlPoints.default),this.removeHandles(Gt),this._updateTooltip()}_handleMidpointClickOrStartMove(t){const{graphic:e}=t,i=this.graphic.geometry;if(null==i||"polygon"!==i.type&&"polyline"!==i.type)return[];const s=nt(i),o=[],{[st.pathIndex]:r,[st.pointIndexStart]:n,[st.pointIndexEnd]:a}=e.attributes,h=C(e.geometry),p=0===a?n+1:a;e.attributes={[st.tool]:ht,[st.pathIndex]:r,[st.pointIndex]:p,[st.relatedGraphicIndices]:[]};const c=Ct(s),l=c[r][a];if(P(l)){if(this.enableCurveOnMidpoint&&t.viewEvent.native.shiftKey){const t=O(c[r][p]);c[r].splice(p,1,{c:[t,[h[0],h[1]]]}),e.setAttribute(st.controlPointKind,rt.circle.interior),e.setAttribute(st.curveFromStraightEdgeFlag,!0),this.midpointGraphics.remove(e),this.curveControlPointGraphics.push(e),at(s,c)}else c[r].splice(p,0,h),o.push({coordinates:c[r][p],componentIndex:r,vertexIndex:p})}else{const t=O(c[r][n]),e=pt(t,l,.5,this._coordinateHelper);c[r].splice(a,1,...e),o.push({coordinates:O(c[r][p]),componentIndex:r,vertexIndex:p})}return this._updateGraphicGeometry(s),this._syncEditGeometryOperations(s),o}_addToSelection(t){const e=kt(t);for(const i of e)this._isCurveControlPoint(i)?i.symbol=this.symbols.controlPoints.selected:i.symbol=this.symbols.vertices.selected,this.selectedManipulators.add(i),this._updateTooltip(i);this._emitSelectEvent(e)}_removeFromSelection(t,e){if(this._isVertex(t)){const{vertices:i}=this.symbols;t.symbol=e?i.hover:i.default}else if(this._isCurveControlPoint(t)){const{controlPoints:i}=this.symbols;t.symbol=e?i.hover:i.default}this.selectedManipulators.remove(t),this._emitDeselectEvent([t]),this._updateTooltip()}_clearSelection(){const t=this.selectedManipulators.toArray(),{controlPoints:e,vertices:i}=this.symbols;if(t.length>0){for(const s of t)this._isVertex(s)?s.symbol=i.default:this._isCurveControlPoint(s)&&(s.symbol=e.default);this.selectedManipulators.removeAll(),this._emitDeselectEvent(t),this._updateTooltip()}}_keyDownHandler(t){null==this._activeOperationInfo&&ft(t,this.tooltip)||vt.delete.includes(t.key)&&!t.repeat&&this.selectedManipulators.length&&(this._removeVertices(this.selectedManipulators),t.stopPropagation())}_removeVertices(t){const e=this.graphic.geometry,i=this.vertexGraphics.length;if(null==e||"polygon"!==e.type&&"polyline"!==e.type&&"multipoint"!==e.type)return;if("polygon"===e.type&&i<4||"multipoint"===e.type&&i<2||"polyline"===e.type&&i<3)return;const s=this.graphic.clone(),o=nt(e);let r=Ct(o);const n=[],a=kt(t);for(const h of a){if(this._isCurveControlPoint(h))continue;const{x:t,y:e}=h.geometry;for(let i=0;i<r.length;i++){const s=r[i];for(let o=0;o<s.length;o++){const[a,h]=O(s[o]);if(t===a&&e===h){n.push({coordinates:O(r[i][o]),componentIndex:i,vertexIndex:o}),r[i].splice(Number(o),1);const t=r[i][o];t&&!P(t)&&(r[i][o]=O(t))}}}}if("polygon"===o.type)r=r.filter(t=>{if(t.length<2)return!1;const[e,i]=O(t[0]),[s,o]=O(t[t.length-1]);return(2!==t.length||e!==s||i!==o)&&(e===s&&i===o||t.push(t[0]),!0)});else if("polyline"===o.type)for(const h of r)1===h.length&&r.splice(r.indexOf(h),1);at(o,r),this._updateGraphicGeometry(o),this.refresh(),this._emitVertexRemoveEvent(a,s,n)}_isVertex(t){return this.vertexGraphics.includes(t)}_isCurveControlPoint(t){return this.curveControlPointGraphics.includes(t)}_isConstructionLine(t){return this.constructionLineGraphics.includes(t)}_isSelected(t){return(this._isVertex(t)||this.curveControlPointGraphics.includes(t))&&this.selectedManipulators.includes(t)}_isMidpoint(t){return this.midpointGraphics.includes(t)}_updateHoverCursor(t){const e=this._isMidpoint(t)?"copy":"move";this.addHandles(this.view.acquireCursor(e,"high"),Gt)}_updateTooltip(t,e){let i=null;const{graphic:s,view:o,tooltipInfos:r}=this,n=s?.geometry;"point"===n?.type?i=r.movePoint:this._selectedManipulator?i=r.selectedVertex:t===this.graphic?(i=r.translateGraphic,B(i,o,this._tooltipsContext,e)):t&&this.selectedManipulators.length>1&&(i=r.translateVertices,J(i,o,n,this._tooltipsContext,this._updatingHandles,e)),this.activeTooltipInfo=i}_updateGraphicGeometry(t){this._updateHandlesOnExternalGeometryChange?.pause(),this.graphic.geometry=t,this._updateHandlesOnExternalGeometryChange?.resume()}_emitMoveStartEvent(t,e){const i={type:"move-start",mover:this.graphic,dx:t,dy:e};this.emit("move-start",i),this.callbacks.onMoveStart?.(i)}_emitMoveEvent(t,e){const i={type:"move",mover:this.graphic,dx:t,dy:e};this.emit("move",i),this.callbacks.onMove?.(i)}_emitMoveStopEvent(t,e){if(null==t||null==e){const i=this._activeOperationInfo;if(!i)return;t=i.totalDx,e=i.totalDy}const i={type:"move-stop",mover:this.graphic,dx:t,dy:e};this.emit("move-stop",i),this.callbacks.onMoveStop?.(i)}_emitReshapeStartEvent(t){const e={type:"reshape-start",graphic:this.graphic,mover:t,selected:this.selectedManipulators.toArray()};this.emit("reshape-start",e),this.callbacks.onReshapeStart?.(e)}_emitReshapeEvent(t){const e={type:"reshape",graphic:this.graphic,mover:t,selected:this.selectedManipulators.toArray()};this.emit("reshape",e),this.callbacks.onReshape?.(e)}_emitReshapeStopEvent(t){const e={type:"reshape-stop",graphic:this.graphic,mover:t,selected:this.selectedManipulators.toArray()};this.emit("reshape-stop",e),this.callbacks.onReshapeStop?.(e)}_emitSelectEvent(t){const e={type:"vertex-select",added:t};this.emit("select",e),this.callbacks.onVertexSelect?.(e)}_emitDeselectEvent(t){const e={type:"vertex-deselect",removed:t};this.emit("deselect",e),this.callbacks.onVertexDeselect?.(e)}_emitVertexAddEvent(t,e,i){const s={type:"vertex-add",added:t,graphic:this.graphic,oldGraphic:e,vertices:i};this.emit("vertex-add",s),this.callbacks.onVertexAdd?.(s)}_emitVertexRemoveEvent(t,e,i){const s={type:"vertex-remove",removed:t,graphic:this.graphic,oldGraphic:e,vertices:i};this.emit("vertex-remove",s),this.callbacks.onVertexRemove?.(s)}_logGeometryTypeError(){n.getLogger(this).error(new o("reshape:invalid-geometry","Reshape operation not supported for the provided graphic. The geometry type is not supported."))}};function Mt(t){let e=Ct(t);e=e.map(t=>t.slice());for(const i of e)for(let t=0;t<i.length;t++)i[t]=T(i[t]);if("polygon"===t.type)for(const i of e){const t=i[i.length-1];if(!P(t))continue;const e=i[0];e[0]===t[0]&&e[1]===t[1]&&i.length>2&&i.pop()}return e}function Ct(t){return"polygon"===t.type?t.curveRings?.slice()??t.rings.slice():"polyline"===t.type?t.curvePaths?.slice()??t.paths.slice():t.points.map(t=>[t])}function St(t,e,i,s){const o=t[e][i];if(H(o))o.c[1]=s;else if(L(o)){const o=O(t[e][i]);t[e][i]={c:[o,s]}}}function Et(t,e,i,s,o){switch(o){case rt.circle.interior:St(t,e,i,s);break;case rt.bezier.cp1:t[e][i].b[1]=s;break;case rt.bezier.cp2:t[e][i].b[2]=s}}function wt(t,e){return t<1e-8*e}function It(t,{cx:e,cy:i,isInvalid:s,thetaStart:o,thetaEnd:r},n,a){const[h,p]=t,[c,l]=n,d=c-h,m=l-p;e-=h,i-=p;const v=a?o>r:o<r,[u,y]=s?[e,i]:v?[-i,e]:[i,-e],[_,g]=[d,m],[f,G]=[u,y],b=_*G-g*f,x=(d**2+m**2)/2;if(wt(Math.abs(b),x))return[(h+c)/2,(p+l)/2];const[M,C]=[G/b*x,-f/b*x],S=M**2+C**2,[E,w]=[d/2-M,m/2-C];if(wt(E**2+w**2,S)){const[t,e]=v?[-C,M]:[C,-M];return[t+M+h,e+C+p]}const I=Math.sqrt((M**2+C**2)/(E**2+w**2))*Math.sign(d*u+m*y);return[E*I+M+h,w*I+C+p]}function Vt(t,e,i){const s=b(new G({curvePaths:[[t,e]],spatialReference:i})),{curvePaths:o}=x(s,i),r=o[0][1];return R(r)?r:I(t,r)}function Ot(t,e,i,s,o){const r=t[e][i],n=t[e].at(i+1);if(ct(t,e)){const i=t[e][1];return t[e][0]=[...s],void(t[e][1]={a:[[...s],[...i.a[1]],0,0]})}if(lt(t,e)){const i=t[e][1],[o,r]=i.a[1],[n,a]=s,h=Math.hypot(n-o,a-r),[p,c]=[n-o,a-r],l=U(c,p);return t[e][0]=[...s],void(t[e][1]={a:[[...s],[...i.a[1]],0,0,l,h,i.a[6]]})}const a=O(r);if(P(r))r.splice(0,r.length,...s);else if(k(r))r.b[0].splice(0,r.b[0].length,...s);else if(H(r)||L(r)){const o=O(t[e][i-1]),n=H(r)?w(o,r):A(o,r);t[e].splice(i,1,{c:[[...s],It(o,n,s,!0)]})}else if(R(r)){r.a[0].splice(0,r.a[0].length,...s);const n=O(t[e][i-1]);r.a=Vt(n,r,o).a}if(n&&!P(n)&&!k(r))if(H(n)||L(n)){const o=O(n),r=H(n)?w(a,n):A(a,n);t[e].splice(i+1,1,{c:[o,It(o,r,s,!1)]})}else if(R(n)){const t=O(r);n.a=Vt(t,n,o).a}}function Ht({attributes:t}){return[t?.[st.pathIndex]||0,t?.[st.pointIndex]||0]}function Lt({attributes:t}){return`${t?.[st.pathIndex]}-${t?.[st.pointIndex]}-${t?.[st.controlPointKind]??"vertex"}`}function kt(t){return t instanceof e?[t]:[...t]}function Pt(t){const e=t.sourceLayer??t.layer;return X(e)?{graphic:t,layer:e}:null}function Tt(t){return t.toArray().map(({attributes:t})=>({pathIndex:t[st.pathIndex],vertexIndex:t[st.pointIndex]}))}t([y()],xt.prototype,"_activeOperationInfo",void 0),t([y()],xt.prototype,"_connectedReshapeManager",void 0),t([y()],xt.prototype,"_coordinateHelper",null),t([y()],xt.prototype,"_editGeometryOperations",void 0),t([y()],xt.prototype,"_effectiveFilterVerticesEnabled",null),t([y()],xt.prototype,"_primaryGraphicMoving",void 0),t([y()],xt.prototype,"_segmentLabels",void 0),t([y()],xt.prototype,"test",null),t([y()],xt.prototype,"_segmentLabelsImportTask",void 0),t([y()],xt.prototype,"_updatingHandles",void 0),t([y()],xt.prototype,"_selectedManipulator",null),t([y()],xt.prototype,"_tooltipsContext",null),t([y()],xt.prototype,"callbacks",void 0),t([y()],xt.prototype,"connectedReshapeProviders",void 0),t([y()],xt.prototype,"enableMidpoints",void 0),t([y()],xt.prototype,"enableCurveOnMidpoint",void 0),t([y()],xt.prototype,"enableMovement",void 0),t([y()],xt.prototype,"enableVertices",void 0),t([y()],xt.prototype,"filterVerticesEnabled",void 0),t([y()],xt.prototype,"graphic",void 0),t([y()],xt.prototype,"highlightName",void 0),t([y()],xt.prototype,"highlightsEnabled",void 0),t([y()],xt.prototype,"layer",void 0),t([y()],xt.prototype,"snappingManager",void 0),t([y({readOnly:!0})],xt.prototype,"state",null),t([y()],xt.prototype,"symbols",void 0),t([y()],xt.prototype,"tooltip",void 0),t([y()],xt.prototype,"tooltipInfos",void 0),t([y()],xt.prototype,"activeTooltipInfo",void 0),t([y({constructOnly:!0})],xt.prototype,"automaticAreaMeasurementUtils",void 0),t([y({constructOnly:!0})],xt.prototype,"automaticLengthMeasurementUtils",void 0),t([y()],xt.prototype,"updating",null),t([y({type:yt})],xt.prototype,"sketchOptions",void 0),t([y({readOnly:!0})],xt.prototype,"type",void 0),t([y({readOnly:!0})],xt.prototype,"vertexGraphics",void 0),t([y({readOnly:!0})],xt.prototype,"curveControlPointGraphics",void 0),t([y({readOnly:!0})],xt.prototype,"constructionLineGraphics",void 0),t([y({readOnly:!0})],xt.prototype,"midpointGraphics",void 0),t([y({readOnly:!0})],xt.prototype,"selectedManipulators",void 0),t([y()],xt.prototype,"view",void 0),xt=t([_("esri.views.draw.support.Reshape")],xt);const Rt=xt;export{Rt as default};