@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 7.74 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{zeroMeters as e,zeroSquareMeters as t,zeroDegreesGeographic as o,valueInUnit as n,createLength as i}from"../../../core/quantityUtils.js";import{getMetersPerVerticalUnitForSR as r}from"../../../core/unitUtils.js";import{getConvertedElevationFromXYZ as l,absoluteHeightElevationInfo as c}from"../../../support/elevationInfoUtils.js";import{getDrawHelpMessage as a}from"./helpMessageUtils.js";import{getDrawMeshHelpMessage as s}from"./helpMessageUtils3d.js";import{getConstraintContext as p}from"../../interactive/sketch/constraintUtils.js";import{updateTooltipInfoFromMeshTransform as u}from"../../interactive/tooltip/tooltipCommonUtils.js";import{DrawCircleTooltipInfo as d}from"../../interactive/tooltip/infos/DrawCircleTooltipInfo.js";import{DrawMeshTooltipInfo as m}from"../../interactive/tooltip/infos/DrawMeshTooltipInfo.js";import{DrawMultipointTooltipInfo as f}from"../../interactive/tooltip/infos/DrawMultipointTooltipInfo.js";import{DrawPointTooltipInfo as y}from"../../interactive/tooltip/infos/DrawPointTooltipInfo.js";import{DrawPolygonTooltipInfo as g}from"../../interactive/tooltip/infos/DrawPolygonTooltipInfo.js";import{DrawPolylineTooltipInfo as w}from"../../interactive/tooltip/infos/DrawPolylineTooltipInfo.js";import{DrawRectangleTooltipInfo as h}from"../../interactive/tooltip/infos/DrawRectangleTooltipInfo.js";import{directionForVertices as v}from"../../support/angularMeasurementUtils.js";import{autoArea2D as O}from"../../support/automaticAreaMeasurementUtils.js";import{autoLength2D as k,autoDistanceBetweenPoints2D as M}from"../../support/automaticLengthMeasurementUtils.js";import{elevationFromPoint as x,elevationFromZ as j}from"../../support/euclideanLengthMeasurementUtils.js";function T(e,t){return{point:new y({sketchOptions:t,viewType:e}),multipoint:new f({sketchOptions:t,viewType:e}),polyline:new w({sketchOptions:t,viewType:e}),polygon:new g({sketchOptions:t,viewType:e}),mesh:new m({sketchOptions:t,viewType:e}),rectangle:new h({sketchOptions:t}),circle:new d({sketchOptions:t})}}function b(e){const{directionOptions:t,geometryType:o,sketchOptions:n,tooltipInfos:i}=e,r=t=>{const o=N(e).mode,n=i[t].elevation;"relative-to-ground"===o||"relative-to-scene"===o||"on-the-ground"===o?n.lock(W(e)):n.unlock()},l=e=>{if(t){const o=i[e].direction;o.committed=t.angle,o.unlockOnVertexPlacement=!1,n.values.directionMode=t.mode}};switch(o){case"polygon":case"polyline":r(o),l(o);break;case"point":case"mesh":r(o)}}function I(e,t){const{drawOperation:o,view:n}=t,i=V(t),r=N(t);if("2d"===n.type||!e||"absolute-height"!==r.mode||1!==o?.numCommittedVertices||!i||"draw-polyline"!==i.type&&"draw-polygon"!==i.type||i.elevation.locked)return;const[l,c,a]=e,s=K(l,c,a,r,t);null!=s&&i.elevation.lock(s)}function U(e){V(e)?.allFields.forEach((e=>{e.unlockOnVertexPlacement&&e.unlock()}))}function V({geometryType:e,graphic:t,tooltipInfos:o}){return t?.geometry?.type!==P[e]?"circle"===e||"rectangle"===e?o[e]:null:o[e]}const P={point:"point",multipoint:"multipoint",mesh:"mesh",polyline:"polyline",polygon:"polygon",circle:"polygon",rectangle:"polygon",freehandPolygon:"polygon",freehandPolyline:"polyline"};function D(e,t){switch(e?.type){case"draw-point":G(e,t);break;case"draw-multipoint":L(e,t);break;case"draw-polyline":Z(e,t);break;case"draw-polygon":C(e,t);break;case"draw-rectangle":H(e,t);break;case"draw-circle":R(e,t);break;case"draw-mesh":z(e,t)}}function G(e,t){const o=t.graphic?.geometry;"point"===o?.type&&(S(e,o,t),e.helpMessage=a("point",o,t.drawOperation.drawingMode))}function L(e,t){const o=t.graphic?.geometry;"multipoint"===o?.type&&(S(e,o,t),e.helpMessage=a("multipoint",o,t.drawOperation.drawingMode))}function z(e,t){const{graphic:o,view:n}=t,i=o?.geometry;"3d"!==n.type||i&&"mesh"!==i.type||(S(e,i?.origin,t),i&&u(e,i),e.helpMessage=s(o,n))}function S(e,t,o){const{drawOperation:n,view:i,sketchOptions:r}=o,{cursorVertex:l}=n;e.sketchOptions=r,e.viewType=i.type;const c="multipoint"===t?.type?t.getPoint(t.points.length-1):t;if(e.setLocationFromPoint(c,Q(o)),q(e.elevation,o),!l)return void(n.constraints=void 0);const a=l;n.constraints={context:$(a,o),x:e.x.committed,y:e.y.committed,longitude:e.longitude.committed,latitude:e.latitude.committed,elevation:e.elevation.committed,distance:null,direction:null}}function Z(t,o){const{createOperationGeometry:n,drawOperation:i}=o,r=null!=n?n.full:null;r&&"polyline"!==r.type||(F(t,o),t.totalLength.actual=i.lastVertex?(r?k(r):null)??e:null,t.helpMessage=a("polyline",r,o.drawOperation.drawingMode))}function C(e,o){const{createOperationGeometry:n,drawOperation:i}=o,r=null!=n?n.full:null;r&&"polygon"!==r.type||(F(e,o),e.area.actual=i.lastVertex?(r?O(r):null)??t:null,e.helpMessage=a("polygon",r,o.drawOperation.drawingMode))}function F(t,n){const{drawOperation:i,sketchOptions:r,view:l}=n,{cursorVertex:c,lastVertex:a,secondToLastVertex:s}=i,p=r.values.effectiveDirectionMode;t.sketchOptions=r,t.viewType=l.type;const u=a&&c?M(a,c)??e:null;if(t.distance.actual=u,t.distance.readOnly=null==a,t.direction.actual=null,t.direction.readOnly=!0,a&&c&&("absolute"===p||s)){const e=v(s,a,c,p);t.direction.actual=e??o,t.direction.readOnly=!1}t.setLocationFromPoint(c,Q(n)),q(t.elevation,n);const d=A(a,n);t.xyMode=d,t.direction.visible="direction-distance"===d,t.distance.visible="direction-distance"===d,t.effectiveX.visible="coordinates"===d,t.effectiveY.visible="coordinates"===d;const m=c??a;i.constraints=m?{context:$(m,n),x:t.x.committed,y:t.y.committed,longitude:t.longitude.committed,latitude:t.latitude.committed,elevation:t.elevation.committed,distance:t.distance.committed,direction:t.direction.committed}:void 0}function A(e,{sketchOptions:t}){const o=t.tooltips.xyMode;return"auto"===o?e?"direction-distance":"coordinates":o}function H(e,t){e.sketchOptions=t.sketchOptions,e.xSize=X(t),e.ySize=Y(t),e.area=E(t),e.helpMessage=a("rectangle",t.graphic?.geometry,t.drawOperation.drawingMode)}function R(e,t){const{forceUniformSize:o,sketchOptions:n}=t;e.sketchOptions=n,e.radius=o?B(t):null,e.xSize=o?null:X(t),e.ySize=o?null:Y(t),e.area=E(t),e.helpMessage=a("circle",t.graphic?.geometry,t.drawOperation.drawingMode)}function q(e,t){const{drawOperation:o}=t,n=o?.cursorVertex??o?.lastVertex;e.actual=x(n)??W(t),e.visible=o.hasZ,e.readOnly=!1,e.showAsZ=!0}function E(e){const o=e.createOperationGeometry?.full;return"polygon"!==o?.type?t:O(o)??t}function X(t){const o=t.createOperationGeometry?.rectangle?.midpoints;return(null!=o?M(o.left,o.right):null)??e}function Y(t){const o=t.createOperationGeometry?.rectangle?.midpoints;return(null!=o?M(o.top,o.bottom):null)??e}function B({createOperationGeometry:t}){return(null!=t?.circle?.center&&null!=t.circle.edge?M(t.circle.center,t.circle.edge):null)??e}function J(e){const{geometryType:t,tooltipInfos:o}=e;switch(t){case"point":case"multipoint":case"mesh":case"polyline":case"polygon":{const i=o[t].elevation.committed;if(!i)return;return n(i,"meters")/r(Q(e))}default:return}}function K(e,t,o,n,i){const{view:r,drawOperation:c}=i;if("3d"!==r.type||!c)return;o??=0;const a=Q(i),s=N(i),p=l(r,e,t,o,a,s,n);return j(p,a)??W(i)}function N(e){return e.drawOperation.elevationInfo??c}function Q(e){return e.drawOperation.coordinateHelper.spatialReference}function W(e){const t=r(Q(e));return i(e.defaultZ*t,"meters")}function $(e,t){return p(e,t.view,Q(t),N(t),t.drawOperation.coordinateHelper.hasZ(),t.sketchOptions.values.effectiveDirectionMode)}export{T as createTooltipInfos,V as getActiveTooltipInfo,J as getConstraintZ,b as initializeConstraints,I as lockElevationOnVertexAdd,U as unlockConstraintsOnVertexAddOrRemove,D as updateTooltipInfo};