UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 4.08 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{handlesGroup as t}from"../../../core/handleUtils.js";import{debounce as e}from"../../../core/promiseUtils.js";import{zeroMeters as o}from"../../../core/quantity.js";import{watch as i,syncAndInitial as n,sync as r}from"../../../core/reactiveUtils.js";import{createScreenPoint as a}from"../../../core/screenUtils.js";import c from"../../../geometry/Point.js";import{isCurvedGeometry as s}from"../../../geometry/support/curves/curveUtils.js";import{connectPasteEvent as l,getXYZDeltasFromTooltipInfo as p}from"../../interactive/tooltip/tooltipCommonUtils.js";import{MovePointTooltipInfo as m}from"../../interactive/tooltip/infos/MovePointTooltipInfo.js";import{SelectedVertexTooltipInfo as f}from"../../interactive/tooltip/infos/SelectedVertexTooltipInfo.js";import{TranslateTooltipInfo as u}from"../../interactive/tooltip/infos/TranslateTooltipInfo.js";import{TranslateVertexTooltipInfo as y}from"../../interactive/tooltip/infos/TranslateVertexTooltipInfo.js";import{elevationFromPoint as v}from"../../support/euclideanLengthMeasurementUtils.js";function g(t){const e={sketchOptions:t,viewType:"2d"};return{movePoint:new m(e),selectedVertex:new f(e),translateGraphic:new u(e),translateVertices:new y(e)}}function h(o,a,c){function s(){const t=a(),e=t.sketchOptions.tooltips.effectiveEnabled?t.activeTooltipInfo:null;return{...t,activeTooltipInfo:e}}let p=!1;function m(t){p||(p=!0,t(),p=!1)}const f=e(t=>x(t)),u=t=>{m(()=>{d(t),o.info=t.activeTooltipInfo,c.addPromise(f(t)).catch(()=>{})})};return t([i(()=>{const t=s();return{context:t,geometry:t.graphic?.geometry,vertexGeometry:t.selectedVertex?.geometry}},({context:t})=>u(t),n),i(()=>{const t=s(),{activeTooltipInfo:e}=t;if(e&&"key"in e)return{context:t,key:e.key}},(t,e)=>{t&&e&&t.key!==e.key&&m(()=>L(t.context))},r),l(o,{onBeforePaste:()=>{p=!0},onAfterPaste:()=>{L(s()),p=!1}})])}function d(t){const e=t.activeTooltipInfo;if(e)switch(e.sketchOptions=t.sketchOptions,e?.type){case"move-point":T(e,t);break;case"selected-vertex":w(e,t)}}async function x(t){const e=t.activeTooltipInfo;if("selected-vertex"===e?.type)return await j(e,t)}function T(t,{graphic:e}){k(t,e,e?.geometry)}function w(t,{graphic:e,selectedVertex:o,automaticLengthMeasurementUtils:i}){k(t,e,o?.geometry);const n=e?.geometry;if(!n||!s(n))switch(n?.type){case"polygon":t.geometryType="polygon",t.totalLength.visible=!1;break;case"polyline":t.geometryType="polyline",t.totalLength.actual=i.autoLength2D(n),t.area.visible=!1;break;case"multipoint":t.geometryType="multipoint",t.area.visible=!1,t.totalLength.visible=!1}}async function j(t,{graphic:e,automaticAreaMeasurementUtils:o}){const i=e?.geometry;if("polygon"===i?.type)t.area.actual=await o.autoArea2D(i)}function k(t,e,o){e&&"point"===o?.type&&(t.setLocationFromPoint(o),t.elevation.actual=v(o),t.elevation.visible=!!e.geometry?.hasZ,t.elevation.readOnly=!1,t.elevation.showAsZ=!0)}function L(t){function e(e,o){const i=o?.geometry;if(!i||"point"!==i.type)return;const{dx:n,dy:r,dz:a}=p(e,i);if(0===n&&0===r&&0===a)return;const{x:s,y:l,z:m,m:f,spatialReference:u}=i,y=new c({x:s+n,y:l+r,z:null!=m?m+a:void 0,m:f,spatialReference:u});t.updateGeometry(o,y,i,n,r)}const{activeTooltipInfo:o,graphic:i,selectedVertex:n}=t;switch(o?.type){case"move-point":return e(o,i);case"selected-vertex":return e(o,n)}}function U(t,e,o,i){t.clear(),M(t,e,i,o)}function I(t,e,i,n,r,a){if(i&&s(i))return void t.clear();t.distance=o,t.elevation=null,t.totalLength=null;const{automaticLengthMeasurementUtils:c}=n;if("polyline"===i?.type)t.totalLength=c.autoLength2D(i);M(t,e,a,n),r.addPromise(b(t,i,n)).catch(()=>{})}const b=e(async(t,e,{automaticAreaMeasurementUtils:o})=>{if("polygon"===e?.type)t.area=await o.autoArea2D(e);else t.area=null});function M(t,e,i,{automaticLengthMeasurementUtils:n}){if(!i)return;const{x:r,y:c}=i.origin,s=e.toMap(i),l=e.toMap(a(r,c)),p=n.autoDistanceBetweenPoints2D(l,s);t.distance=null!=p?p:o}export{h as connectTooltip,g as createTooltipInfos,U as updateTranslateTooltipInfo,I as updateTranslateVertexTooltipInfo};