12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.24/esri/copyright.txt for details.
- */
- import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import"../../core/has.js";import r from"../../core/Evented.js";import{HandleOwnerMixin as i}from"../../core/HandleOwner.js";import{makeHandle as a}from"../../core/handleUtils.js";import{destroyMaybe as o,isSome as s,isNone as n,unwrap as l}from"../../core/maybe.js";import{property as p}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as h}from"../../core/accessorSupport/decorators/subclass.js";import c from"../../layers/GraphicsLayer.js";import{createSquare as d,createRectangle as u,createCircle as m,createEllipse as g,createPolygon as y,createPolyline as v,createMultipoint as f}from"./support/createUtils.js";import{createViewAlignedCoordinateSystem as w}from"./support/surfaceCoordinateSystems.js";import{InteractiveToolBase as O}from"../interactive/InteractiveToolBase.js";let _=class extends(i(r.EventedMixin(O))){constructor(e){super(e),this._graphic=null,this.defaultZ=0,this.geometryType=null,this.hasZ=!0,this.mode=null,this.snappingManager=null,this.snapToScene=!1}initialize(){this.internalGraphicsLayer=new c({listMode:"hide",internal:!0}),this.view.map.layers.add(this.internalGraphicsLayer),this.drawOperation=this.makeDrawOperation(),this.handles.add([this.drawOperation.on("vertex-add",(e=>this.onVertexAdd(e))),this.drawOperation.on("vertex-remove",(e=>this.onVertexRemove(e))),this.drawOperation.on("vertex-update",(e=>this.onVertexUpdate(e))),this.drawOperation.on("cursor-update",(e=>this.onCursorUpdate(e))),this.drawOperation.on("complete",(e=>this.onComplete(e)))]),this.finishToolCreation()}destroy(){this.drawOperation=o(this.drawOperation),this._destroyAllVisualisations(),this.view.map.remove(this.internalGraphicsLayer),this.internalGraphicsLayer=o(this.internalGraphicsLayer),this._set("view",null)}get canRedo(){return this.drawOperation.canRedo}get canUndo(){return this.drawOperation.canUndo}set centered(e){this._set("centered",e),this._updateGraphic()}set enabled(e){this.drawOperation.interactive=e,this._set("enabled",e)}set forceUniformSize(e){this._set("forceUniformSize",e),this._updateGraphic()}get graphic(){return this._graphic}set graphicSymbol(e){this._set("graphicSymbol",e),s(this._graphic)&&(this._graphic.symbol=e)}get updating(){return this.drawOperation?.updating??!1}completeCreateOperation(){this.drawOperation.complete()}onInputEvent(e){this.drawOperation.onInputEvent(e)}redo(){this.drawOperation.redo()}reset(){}undo(){this.drawOperation.undo()}_createGraphic(e){this._graphic=new t({...this.graphicProperties,geometry:e,symbol:this.graphicSymbol}),this.internalGraphicsLayer.add(this._graphic),this.handles.add(this.initializeGraphic(this._graphic)),this.notifyChange("graphic"),this.handles.add(a((()=>{s(this._graphic)&&(this.internalGraphicsLayer.remove(this._graphic),this._graphic=o(this._graphic))})),V)}_destroyAllVisualisations(){this.handles.remove(x.outline),this.handles.remove(x.regularVertices),this.handles.remove(x.activeVertex),this.handles.remove(V)}_getCreateOperationGeometry(e={operationComplete:!1}){if(null==this.drawOperation||0===this.drawOperation.numVertices)return null;const t=this.drawOperation.stagedVertex,r=this.drawOperation.committedVertices,i=r.slice();s(t)&&i.push(this.drawOperation.coordinateHelper.pointToArray(t));const a=s(t)?this.drawOperation.coordinateHelper.pointToArray(t):r.splice(-1)[0],o={regularVertices:null,activeVertex:null,full:null,outline:null},n=i.length,l=this.view.spatialReference,p="3d"===this.view.type&&"global"===this.view.viewingMode;switch(this.geometryType){case"point":o.regularVertices=r,o.activeVertex=a,o.full=this.drawOperation.coordinateHelper.arrayToPoint(i[0]);break;case"multipoint":o.regularVertices=r,o.activeVertex=a,n>0&&(o.full=f(i,l));break;case"polyline":o.regularVertices=r,o.activeVertex=a,n>0&&(o.full=v([i],l,p));break;case"polygon":o.regularVertices=r,o.activeVertex=a,n>0&&(o.full=y([i],l,p,!0));break;case"circle":if(n>0){const t=w(this.view,i[0]);if(1===n&&e.operationComplete){const e=i[0],r=t.makeMapPoint(e[0]+b*this.view.resolution,e[1]);o.full=m([e,r],t,!0)}else 2===n&&(o.full=this.forceUniformSize?m(i,t,this.centered):g(i,t,this.centered))}break;case"rectangle":if(n>0){const t=w(this.view,i[0]);if(1===n&&e.operationComplete){const e=i[0],r=t.makeMapPoint(e[0]+b*this.view.resolution,e[1]);o.full=d([e,r],t,!0)}else 2===n&&(o.full=this.forceUniformSize?d(i,t,this.centered):u(i,t,this.centered))}break;default:return null}switch(this.geometryType){case"point":case"multipoint":break;case"polyline":case"polygon":n>1&&(o.outline=v([i],l,p));break;case"circle":case"rectangle":s(o.full)&&"polygon"===o.full.type&&(o.outline=y(o.full.rings,l,p))}return o}initializeGraphic(e){return null}onComplete(e){this._updateGraphic();let t=null;if(this.drawOperation.isCompleted){const e=this._getCreateOperationGeometry({operationComplete:!0});s(e)&&(n(this._graphic)?this._createGraphic(e.full):this._graphic.geometry=e.full,t=l(this._graphic).clone())}this.emit("complete",{graphic:t,...e})}onCursorUpdate(e){this._updateGraphic(),this.emit("cursor-update",e)}onDeactivate(){this.drawOperation.isCompleted||this.drawOperation.cancel()}onVertexAdd(e){this._updateGraphic(),this.emit("vertex-add",e)}onVertexRemove(e){this._updateGraphic(),this.emit("vertex-remove",e)}onVertexUpdate(e){this._updateGraphic(),this.emit("vertex-update",e)}_updateGraphic(){const e=this._getCreateOperationGeometry();n(e)?this._destroyAllVisualisations():(s(e.outline)?this.handles.add(this.onOutlineChanged(e.outline),x.outline):this.handles.remove(x.outline),s(e.regularVertices)?this.handles.add(this.onRegularVerticesChanged(e.regularVertices),x.regularVertices):this.handles.remove(x.regularVertices),s(e.activeVertex)?this.handles.add(this.onActiveVertexChanged(e.activeVertex),x.activeVertex):this.handles.remove(x.activeVertex),s(e.full)?n(this._graphic)?this._createGraphic(e.full):this._graphic.geometry=e.full:this.handles.remove(V))}};e([p({value:!0})],_.prototype,"centered",null),e([p({nonNullable:!0})],_.prototype,"defaultZ",void 0),e([p()],_.prototype,"drawOperation",void 0),e([p({value:!0})],_.prototype,"enabled",null),e([p({value:!0})],_.prototype,"forceUniformSize",null),e([p({constructOnly:!0})],_.prototype,"geometryType",void 0),e([p()],_.prototype,"graphic",null),e([p({constructOnly:!0})],_.prototype,"graphicProperties",void 0),e([p()],_.prototype,"graphicSymbol",null),e([p({constructOnly:!0})],_.prototype,"hasZ",void 0),e([p({constructOnly:!0})],_.prototype,"mode",void 0),e([p()],_.prototype,"snappingManager",void 0),e([p()],_.prototype,"snapToScene",void 0),e([p({readOnly:!0})],_.prototype,"type",void 0),e([p({readOnly:!0})],_.prototype,"updating",null),e([p({constructOnly:!0,nonNullable:!0})],_.prototype,"view",void 0),_=e([h("esri.views.draw.DrawGraphicTool")],_);const V="create-operation-graphic",x={outline:"outline-visual",regularVertices:"regular-vertices-visual",activeVertex:"active-vertex-visual"};function G(e){switch(e){case"point":case"polyline":case"polygon":case"multipoint":return e;case"circle":case"rectangle":return"segment";default:return null}}const b=48;export{_ as DrawGraphicTool,G as geometryTypeToDrawOperationGeometryType};
|