12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import"../../core/has.js";import i from"../../core/Evented.js";import{HandleOwnerMixin as o}from"../../core/HandleOwner.js";import{makeHandle as r}from"../../core/handleUtils.js";import{destroyMaybe as n,isSome as l,isNone as a,unwrap as s,applySome as p,unwrapOr as c}from"../../core/maybe.js";import{createLength as h,zeroMeters as u,zeroSquareMeters as d}from"../../core/quantityUtils.js";import{watch as m,syncAndInitial as y}from"../../core/reactiveUtils.js";import{getMetersPerVerticalUnitForSR as g}from"../../core/unitUtils.js";import{property as v}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as f}from"../../core/accessorSupport/decorators/subclass.js";import _ from"../../layers/GraphicsLayer.js";import{getConvertedElevation as w}from"../../support/elevationInfoUtils.js";import{createSquare as O,createRectangle as T,createCircle as x,createEllipse as G,createPolygon as V,createPolyline as S,createMultipoint as b}from"./support/createUtils.js";import{createViewAlignedCoordinateSystem as I}from"./support/surfaceCoordinateSystems.js";import{InteractiveToolBase as j}from"../interactive/InteractiveToolBase.js";import C from"../interactive/sketch/SketchLabelOptions.js";import z from"../interactive/sketch/SketchTooltipOptions.js";import{DrawPointTooltipInfo as U,DrawPolylineTooltipInfo as M,DrawPolygonTooltipInfo as k,DrawRectangleTooltipInfo as P,DrawCircleTooltipInfo as A}from"../interactive/tooltip/DrawTooltipInfos.js";import{Tooltip as R}from"../interactive/tooltip/Tooltip.js";import{autoAreaByElevationMode as E}from"../support/automaticAreaMeasurementUtils.js";import{autoLengthByElevationMode as L,autoHorizontalDistanceByElevationModeBetweenPoints as D}from"../support/automaticLengthMeasurementUtils.js";let Z=class extends(o(i.EventedMixin(j))){constructor(e){super(e),this._graphic=null,this._createOperationGeometry=null,this.defaultZ=0,this.geometryType=null,this.hasZ=!0,this.labelOptions=new C,this.mode=null,this.snappingManager=null,this.snapToScene=!1,this.tooltip=null,this.tooltipOptions=new z}initialize(){this.internalGraphicsLayer=new _({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))),m((()=>this.tooltipOptions.enabled),(e=>{this.tooltip=e?new R({view:this.view,info:this._tooltipInfo}):n(this.tooltip)}),y),m((()=>this._tooltipInfo),(e=>{l(this.tooltip)&&(this.tooltip.info=e)}),y)]),this.finishToolCreation()}destroy(){this.drawOperation=n(this.drawOperation),this.tooltip=n(this.tooltip),this._destroyAllVisualisations(),this.view.map.remove(this.internalGraphicsLayer),this.internalGraphicsLayer=n(this.internalGraphicsLayer),this._set("view",null)}get _defaultElevation(){return h(this.defaultZ,"meters")}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),l(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(r((()=>{l(this._graphic)&&(this.internalGraphicsLayer.remove(this._graphic),this._graphic=n(this._graphic))})),H)}_destroyAllVisualisations(){this.handles.remove(N.outline),this.handles.remove(N.regularVertices),this.handles.remove(N.activeVertex),this.handles.remove(H)}_getCreateOperationGeometry(e={operationComplete:!1}){if(null==this.drawOperation||0===this.drawOperation.numVertices)return null;const t=this.drawOperation.stagedVertex,i=this.drawOperation.committedVertices,o=i.slice();l(t)&&o.push(this.drawOperation.coordinateHelper.pointToArray(t));const r=l(t)?this.drawOperation.coordinateHelper.pointToArray(t):i.splice(-1)[0],n={regularVertices:null,activeVertex:null,full:null,outline:null,circle:null,rectangle:null},a=o.length,s=this.view.spatialReference,p="3d"===this.view.type&&"global"===this.view.viewingMode;switch(this.geometryType){case"point":n.regularVertices=i,n.activeVertex=r,n.full=this.drawOperation.coordinateHelper.arrayToPoint(o[0]);break;case"multipoint":n.regularVertices=i,n.activeVertex=r,a>0&&(n.full=b(o,s));break;case"polyline":n.regularVertices=i,n.activeVertex=r,a>0&&(n.full=S([o],s,p));break;case"polygon":n.regularVertices=i,n.activeVertex=r,a>0&&(n.full=V([o],s,p,!0));break;case"circle":if(a>0){const t=I(this.view,o[0]);if(1===a&&e.operationComplete){const e=o[0],i=t.makeMapPoint(e[0]+B*this.view.resolution,e[1]);n.circle=x([e,i],t,!0),n.full=l(n.circle)?n.circle.geometry:null}else 2===a&&(this.forceUniformSize?(n.circle=x(o,t,this.centered),n.full=l(n.circle)?n.circle.geometry:null):(n.rectangle=G(o,t,this.centered),n.full=n.rectangle.geometry))}break;case"rectangle":if(a>0){const t=I(this.view,o[0]);if(1===a&&e.operationComplete){const e=o[0],i=t.makeMapPoint(e[0]+B*this.view.resolution,e[1]);n.rectangle=O([e,i],t,!0),n.full=n.rectangle.geometry}else 2===a&&(n.rectangle=this.forceUniformSize?O(o,t,this.centered):T(o,t,this.centered),n.full=n.rectangle.geometry)}break;default:return null}switch(this.geometryType){case"point":case"multipoint":break;case"polyline":case"polygon":a>1&&(n.outline=S([o],s,p));break;case"circle":case"rectangle":l(n.full)&&"polygon"===n.full.type&&(n.outline=V(n.full.rings,s,p))}return n}initializeGraphic(e){return null}onComplete(e){this._updateGraphic();let t=null;if(this.drawOperation.isCompleted){const e=this._getCreateOperationGeometry({operationComplete:!0});l(e)&&(a(this._graphic)?this._createGraphic(e.full):this._graphic.geometry=e.full,t=s(this._graphic).clone())}this._createOperationGeometry=null,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();this._createOperationGeometry=e,a(e)?this._destroyAllVisualisations():(l(e.outline)?this.handles.add(this.onOutlineChanged(e.outline),N.outline):this.handles.remove(N.outline),l(e.regularVertices)?this.handles.add(this.onRegularVerticesChanged(e.regularVertices),N.regularVertices):this.handles.remove(N.regularVertices),l(e.activeVertex)?this.handles.add(this.onActiveVertexChanged(e.activeVertex),N.activeVertex):this.handles.remove(N.activeVertex),l(e.full)?a(this._graphic)?this._createGraphic(e.full):this._graphic.geometry=e.full:this.handles.remove(H))}get _tooltipInfo(){const{drawOperation:e}=this;if(!e)return null;switch(this.geometryType){case"point":return this._drawPointTooltipInfo;case"polyline":return this._drawPolylineTooltipInfo;case"polygon":return this._drawPolygonTooltipInfo;case"rectangle":return this._drawRectangleTooltipInfo;case"circle":return this._drawCircleTooltipInfo;default:return null}}get _drawPointTooltipInfo(){const e=p(this.graphic,(e=>e.geometry));return a(e)||"point"!==e.type||"2d"===this.view.type&&0===this.defaultZ?null:new U({tooltipOptions:this.tooltipOptions,elevation:this._elevationTooltipDetail})}get _drawPolylineTooltipInfo(){const e=this._createOperationGeometry,t=l(e)?e.full:null;if(a(t)||"polyline"!==t.type)return null;const i=L(t,this._elevationMode);return new M({tooltipOptions:this.tooltipOptions,elevation:this._elevationTooltipDetail,totalLength:c(i,u),viewType:this.view.type})}get _drawPolygonTooltipInfo(){const e=this._createOperationGeometry,t=l(e)?e.full:null;if(a(t)||"polygon"!==t.type)return null;const i=E(t,this._elevationMode);return new k({tooltipOptions:this.tooltipOptions,elevation:this._elevationTooltipDetail,area:c(i,d),viewType:this.view.type})}get _drawRectangleTooltipInfo(){return a(this.drawOperation)?null:new P({tooltipOptions:this.tooltipOptions,xSize:c(this._xSize,u),ySize:c(this._ySize,u),area:c(this._fullGeometryArea,d)})}get _drawCircleTooltipInfo(){if(a(this.drawOperation))return null;const e=this.forceUniformSize;return new A({tooltipOptions:this.tooltipOptions,radius:e?c(this._circleRadius,u):null,xSize:e?null:c(this._xSize,u),ySize:e?null:c(this._ySize,u),area:c(this._fullGeometryArea,d)})}get _circleRadius(){const e=this._createOperationGeometry;return l(e)&&l(e.circle)&&l(e.circle.center)&&l(e.circle.edge)?D(e.circle.center,e.circle.edge,this._elevationMode):null}get _xSize(){const e=this._createOperationGeometry;if(a(e)||a(e.rectangle))return null;const{midpoints:t}=e.rectangle;return l(t)?D(t.left,t.right,this._elevationMode):null}get _ySize(){const e=this._createOperationGeometry;if(a(e)||a(e.rectangle))return null;const{midpoints:t}=e.rectangle;return l(t)?D(t.top,t.bottom,this._elevationMode):null}get _fullGeometryArea(){const e=this._createOperationGeometry,t=l(e)?e.full:null;return a(t)||"polygon"!==t.type?null:E(t,this._elevationMode)}get _elevationTooltipDetail(){return{mode:this.drawOperation.elevationInfo.mode,...this._vertexTooltipElevation}}get _vertexTooltipElevation(){const{tooltipOptions:e,view:t,drawOperation:i}=this;if(a(i))return this._defaultElevation;const o=i.stagedVertex??i.lastVertex;if(a(o)||"2d"===t.type)return this._defaultElevation;const r={mode:e.elevation.mode,offset:0},n=w(t,o,i.elevationInfo,r)*g(o.spatialReference);return h(n,"meters")}get _elevationMode(){return this.drawOperation.isDraped?"on-the-ground":"absolute-height"}};e([v()],Z.prototype,"_createOperationGeometry",void 0),e([v()],Z.prototype,"_defaultElevation",null),e([v({value:!0})],Z.prototype,"centered",null),e([v({nonNullable:!0})],Z.prototype,"defaultZ",void 0),e([v()],Z.prototype,"drawOperation",void 0),e([v({value:!0})],Z.prototype,"enabled",null),e([v({value:!0})],Z.prototype,"forceUniformSize",null),e([v({constructOnly:!0})],Z.prototype,"geometryType",void 0),e([v()],Z.prototype,"graphic",null),e([v({constructOnly:!0})],Z.prototype,"graphicProperties",void 0),e([v()],Z.prototype,"graphicSymbol",null),e([v({constructOnly:!0})],Z.prototype,"hasZ",void 0),e([v({constructOnly:!0,type:C})],Z.prototype,"labelOptions",void 0),e([v({constructOnly:!0})],Z.prototype,"mode",void 0),e([v()],Z.prototype,"snappingManager",void 0),e([v()],Z.prototype,"snapToScene",void 0),e([v()],Z.prototype,"tooltip",void 0),e([v({constructOnly:!0,type:z})],Z.prototype,"tooltipOptions",void 0),e([v({readOnly:!0})],Z.prototype,"type",void 0),e([v({readOnly:!0})],Z.prototype,"updating",null),e([v({constructOnly:!0,nonNullable:!0})],Z.prototype,"view",void 0),e([v()],Z.prototype,"_tooltipInfo",null),e([v()],Z.prototype,"_drawPointTooltipInfo",null),e([v()],Z.prototype,"_drawPolylineTooltipInfo",null),e([v()],Z.prototype,"_drawPolygonTooltipInfo",null),e([v()],Z.prototype,"_drawRectangleTooltipInfo",null),e([v()],Z.prototype,"_drawCircleTooltipInfo",null),e([v()],Z.prototype,"_circleRadius",null),e([v()],Z.prototype,"_xSize",null),e([v()],Z.prototype,"_ySize",null),e([v()],Z.prototype,"_fullGeometryArea",null),e([v()],Z.prototype,"_elevationTooltipDetail",null),e([v()],Z.prototype,"_vertexTooltipElevation",null),e([v()],Z.prototype,"_elevationMode",null),Z=e([f("esri.views.draw.DrawGraphicTool")],Z);const H="create-operation-graphic",N={outline:"outline-visual",regularVertices:"regular-vertices-visual",activeVertex:"active-vertex-visual"};function q(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{Z as DrawGraphicTool,q as geometryTypeToDrawOperationGeometryType};
|