UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 3.46 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{handlesGroup as t}from"../../../core/handleUtils.js";import{zeroMeters as e}from"../../../core/quantityUtils.js";import{watch as o,syncAndInitial as n,sync as i}from"../../../core/reactiveUtils.js";import{createScreenPoint as r}from"../../../core/screenUtils.js";import c from"../../../geometry/Point.js";import{connectPasteEvent as s,getXYZDeltasFromTooltipInfo as a}from"../../interactive/tooltip/tooltipCommonUtils.js";import{MovePointTooltipInfo as l}from"../../interactive/tooltip/infos/MovePointTooltipInfo.js";import{SelectedVertexTooltipInfo as p}from"../../interactive/tooltip/infos/SelectedVertexTooltipInfo.js";import{TranslateTooltipInfo as f}from"../../interactive/tooltip/infos/TranslateTooltipInfo.js";import{TranslateVertexTooltipInfo as m}from"../../interactive/tooltip/infos/TranslateVertexTooltipInfo.js";import{autoArea2D as u}from"../../support/automaticAreaMeasurementUtils.js";import{autoLength2D as y,autoDistanceBetweenPoints2D as v}from"../../support/automaticLengthMeasurementUtils.js";import{elevationFromPoint as g}from"../../support/euclideanLengthMeasurementUtils.js";function h(t){const e={sketchOptions:t,viewType:"2d"};return{movePoint:new l(e),selectedVertex:new p(e),translateGraphic:new f(e),translateVertices:new m(e)}}function d(e,r){function c(){const t=r(),e=t.sketchOptions.tooltips.effectiveEnabled?t.activeTooltipInfo:null;return{...t,activeTooltipInfo:e}}let a=!1;function l(t){a||(a=!0,t(),a=!1)}return t([o((()=>{const t=c();return{context:t,geometry:t.graphic?.geometry,vertexGeometry:t.selectedVertex?.geometry}}),(({context:t})=>{l((()=>{x(t),e.info=t.activeTooltipInfo}))}),n),o((()=>{const t=c(),{activeTooltipInfo:e}=t;if(e&&"key"in e)return{context:t,key:e.key}}),((t,e)=>{t&&e&&t.key!==e.key&&l((()=>w(t.context)))}),i),s(e,{onBeforePaste:()=>{a=!0},onAfterPaste:()=>{w(c()),a=!1}})])}function x(t){const e=t.activeTooltipInfo;if(e){switch(e?.type){case"move-point":return T(e,t);case"selected-vertex":return j(e,t)}e.sketchOptions=t.sketchOptions}}function T(t,{graphic:e}){k(t,e,e?.geometry)}function j(t,{graphic:e,selectedVertex:o}){k(t,e,o?.geometry);const n=e?.geometry;switch(n?.type){case"polygon":t.geometryType="polygon",t.totalLength.visible=!1,t.area.actual=u(n);break;case"polyline":t.geometryType="polyline",t.totalLength.actual=y(n),t.area.visible=!1}}function k(t,e,o){e&&"point"===o?.type&&(t.setLocationFromPoint(o),t.elevation.actual=g(o),t.elevation.visible=!!e.geometry?.hasZ,t.elevation.readOnly=!1,t.elevation.showAsZ=!0)}function w(t){function e(e,o){const n=o?.geometry;if(!n||"point"!==n.type)return;const{dx:i,dy:r,dz:s}=a(e,n);if(0===i&&0===r&&0===s)return;const{x:l,y:p,z:f,m,spatialReference:u}=n,y=new c({x:l+i,y:p+r,z:null!=f?f+s:void 0,m,spatialReference:u});t.updateGeometry(o,y,n,i,r)}const{activeTooltipInfo:o,graphic:n,selectedVertex:i}=t;switch(o?.type){case"move-point":return e(o,n);case"selected-vertex":return e(o,i)}}function I(t,e,o){t.clear(),V(t,e,o)}function U(t,e,o,n){t.clear(),"polygon"===o?.type?t.area=u(o):"polyline"===o?.type&&(t.totalLength=y(o)),V(t,e,n)}function V(t,o,n){if(!n)return;const{x:i,y:c}=n.origin,s=o.toMap(n),a=o.toMap(r(i,c)),l=v(a,s);t.distance=null!=l?l:e}export{d as connectTooltip,h as createTooltipInfos,I as updateTranslateTooltipInfo,U as updateTranslateVertexTooltipInfo};