@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 7.53 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import{handlesGroup as t,makeHandle as i}from"../../../../../core/handleUtils.js";import{destroyMaybe as s}from"../../../../../core/maybe.js";import{watch as r,syncAndInitial as n,initial as o,when as a}from"../../../../../core/reactiveUtils.js";import{property as l,subclass as c}from"../../../../../core/accessorSupport/decorators.js";import{set as m}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as h}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getEffectiveElevationInfo as p,getEffectiveElevationMode as u}from"../../../../../support/elevationInfoUtils.js";import d from"../../../../../symbols/support/ElevationInfo.js";import{SegmentLabels3D as v}from"../../SegmentLabels3D.js";import{SnappingVisualizer3D as f}from"../../SnappingVisualizer3D.js";import{meshTransformFastUpdateHandles as g}from"../meshFastUpdateUtils.js";import{Settings as E}from"../settings.js";import{ExtendedLineVisualElement as y}from"../../visualElements/ExtendedLineVisualElement.js";import{OutlineVisualElement as V}from"../../visualElements/OutlineVisualElement.js";import{VerticesVisualElement as w}from"../../visualElements/VerticesVisualElement.js";import{evaluateElevationAlignmentAtPoint as _}from"../../../layers/graphics/elevationAlignmentUtils.js";import{ElevationContext as I}from"../../../layers/graphics/ElevationContext.js";import{GraphicState as j}from"../../../layers/graphics/GraphicState.js";import{DrawGraphicTool as G,geometryTypeToDrawOperationGeometryType as L}from"../../../../draw/DrawGraphicTool.js";import{DrawOperation as x}from"../../../../draw/DrawOperation.js";import{ElevationDrawSurface as S,SceneDrawSurface as D}from"../../../../draw/drawSurfaces.js";import{updateMeshTransformFromTooltipInfo as C}from"../../../../interactive/tooltip/tooltipCommonUtils.js";import{autorun as O}from"../../../../../core/accessorSupport/trackingUtils.js";let T=class extends G{constructor(e){super(e),this._activeVertexVisualElement=null,this._createGraphicState=null,this._outlineVisualElement=null,this._verticesVisualElement=null,this._verticalLineVisualElement=null,this._settings=new E({getTheme:()=>this.view.effectiveTheme}),this.geometryType=null,this.type="draw-3d"}initialize(){const{mode:e,offset:t,unit:i,featureExpressionInfo:s}=this.elevationInfo;this.internalGraphicsLayer.elevationInfo=new d({mode:e,offset:t,unit:i,featureExpressionInfo:s})}normalizeCtorArgs(e){if(!e.elevationInfo){const t=e.hasZ??!0;return{...e,elevationInfo:p(t)}}return e}initializeGraphic(e){const{view:i}=this,s=this._createGraphicState=new j({graphic:e});return t([i.maskOccludee(e),i.trackGraphicState(s),r(()=>({element:this._outlineVisualElement,isDraped:s.isDraped}),({element:e,isDraped:t})=>{e&&(e.isDraped=t)},n),O(()=>{C(this.tooltipInfos.mesh,this.geometryToPlace)}),this._setupLoadingIndicator(s),...g(s)])}makeDrawOperation(){const{geometryType:e}=this,t="circle"!==e&&"rectangle"!==e;return new x({view:this.view,manipulators:this.manipulators,geometryType:L(e),drawingMode:this.mode,hasZ:this.hasZ,defaultZ:this.defaultZ,snapToSceneEnabled:this.snapToScene,drawSurface:new D(this.view,this.elevationInfo,[this.internalGraphicsLayer]),elevationDrawSurface:new S(this.elevationInfo,this.defaultZ,this.view,this.internalGraphicsLayer),hasM:!1,elevationInfo:this.elevationInfo,snappingManager:this.snappingManager,snappingVisualizer:new f,segmentLabels:t?new v:null,labelOptions:this.sketchOptions.labels,isDraped:this._createGraphicState?this._createGraphicState.isDraped:"on-the-ground"===u(this.hasZ,this.elevationInfo),cursor:this.cursor,constraintsEnabled:!0,automaticLengthMeasurementUtils:this.automaticLengthMeasurementUtils})}onActiveVertexChanged(e){const{view:n}=this;if(this._activeVertexVisualElement)return this._activeVertexVisualElement.vertices=[e],this._activeVertexVisualElement.recreate(),this._updateVerticalLineVisualElement(e),i();const a=this._settings,l=a.manipulators.vertex,c=new w({view:n,spatialReference:n.spatialReference,vertices:[e],elevationInfo:this.internalGraphicsLayer.elevationInfo,size:l.size,outlineSize:l.outlineSize,renderOccluded:l.renderOccluded,attached:!1,isDecoration:!0});this._activeVertexVisualElement=c;const m=a.visualElements.zVerticalLine,h=new y({view:n,extensionType:m.extensionType,innerWidth:1,attached:!1,writeDepthEnabled:!1,renderOccluded:4,isDecoration:!0});this._verticalLineVisualElement=h;const p=t([r(()=>a.visualElements.zVerticalLine,e=>e.apply(h),o),r(()=>({selectedColor:a.colors.selected.toUnitRGBA(),outlineColor:a.manipulators.vertex.outlineColor.toUnitRGBA()}),({selectedColor:e,outlineColor:t})=>{c.color=e,c.outlineColor=t},o),i(()=>{this._activeVertexVisualElement=s(this._activeVertexVisualElement),this._verticalLineVisualElement=s(this._verticalLineVisualElement)})]);return c.attached=!0,this._updateVerticalLineVisualElement(e),p}_updateVerticalLineVisualElement(e){const t=this._verticalLineVisualElement;if(!t)return;const{renderCoordsHelper:i,elevationProvider:s}=this.view;m(z,e[0],e[1],e[2]),b.setFromElevationInfo(this.elevationInfo),z[2]=_(z,s,b,i);i.toRenderCoords(z,this.view.spatialReference,z)?(t.setStartEndFromWorldDownAtLocation(z),t.attached=!0):t.attached=!1}onOutlineChanged(e){if(this._outlineVisualElement)return this._outlineVisualElement.geometry=e,i();const n=this.internalGraphicsLayer.elevationInfo,{view:a}=this,l=this._settings,c=new V({view:a,geometry:e,elevationInfo:n,isDraped:this._createGraphicState?this._createGraphicState.isDraped:"on-the-ground"===u(this.hasZ,n),attached:!1,isDecoration:!0});this._outlineVisualElement=c;const m=t([r(()=>l.visualElements.lineObjects.outline,e=>e.apply(c),o),r(()=>l.visualElements.lineObjects.shadowStyle,e=>e.apply(c),o),i(()=>{this._outlineVisualElement=s(this._outlineVisualElement)})]);return c.attached=!0,c.laserlineEnabled=!0,m}onRegularVerticesChanged(e){if(this._verticesVisualElement)return this._verticesVisualElement.vertices=e,i();const{view:n}=this,a=this._settings,l=a.manipulators.vertex,c=new w({view:n,spatialReference:n.spatialReference,vertices:e,elevationInfo:this.internalGraphicsLayer.elevationInfo,size:l.size,outlineSize:l.outlineSize,renderOccluded:l.renderOccluded,attached:!1,isDecoration:!0}),m=t([r(()=>({color:a.manipulators.vertex.color.toUnitRGBA(),outlineColor:a.manipulators.vertex.outlineColor.toUnitRGBA()}),({color:e,outlineColor:t})=>{c.color=e,c.outlineColor=t},o),i(()=>{this._verticesVisualElement=s(this._verticesVisualElement)})]);return c.attached=!0,this._verticesVisualElement=c,m}updateGraphicGeometry(e){if("mesh"===this.geometryType&&"point"===e?.type){const t=this.geometryToPlace;t?.centerAt(e),C(this.tooltipInfos.mesh,t);const i=this._graphic;return void(t&&i.geometry===t||(i.geometry=t))}super.updateGraphicGeometry(e)}_setupLoadingIndicator(e){const{drawOperation:s}=this;if(!this.geometryToPlace||e.displaying)return s.loading=!1,null;s.loading=!0;const r=i(()=>{s.loading=!1});let o;const l=()=>{o&&cancelAnimationFrame(o)};return t([a(()=>e.displaying,()=>{l(),o=requestAnimationFrame(()=>r.remove())},{...n,once:!0}),i(l),r])}};e([l({constructOnly:!0})],T.prototype,"elevationInfo",void 0),e([l({constructOnly:!0})],T.prototype,"geometryType",void 0),e([l()],T.prototype,"type",void 0),e([l({constructOnly:!0})],T.prototype,"view",void 0),T=e([c("esri.views.3d.interactive.editingTools.draw.DrawGraphicTool3D")],T);const b=new I,z=h();export{T as DrawGraphicTool3D};