UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 5.99 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as t}from"../../chunks/tslib.es6.js";import e from"../../Color.js";import"../../intl.js";import s from"../../core/Accessor.js";import{createTask as o}from"../../core/asyncUtils.js";import{multiplyOpacity as r,getContrast as i,BrightnessThreshold as n}from"../../core/colorUtils.js";import{makeHandle as l}from"../../core/handleUtils.js";import"../../core/has.js";import{deg2rad as a}from"../../core/mathUtils.js";import{formatLength as c}from"../../core/quantityFormatUtils.js";import{watch as h,on as p}from"../../core/reactiveUtils.js";import{createScreenPointArray as m}from"../../core/screenUtils.js";import{getMetersPerUnit as d,getMetersPerVerticalUnitForSR as u}from"../../core/unitUtils.js";import{property as f}from"../../core/accessorSupport/decorators/property.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as g}from"../../core/accessorSupport/decorators/subclass.js";import{squaredDistance as b,set as _,normalize as x,scale as y,lerp as v,add as U}from"../../core/libs/gl-matrix-2/math/vec2.js";import{create as j}from"../../core/libs/gl-matrix-2/factories/vec2f64.js";import{G as L}from"../../chunks/vec32.js";import{isClockwise as I}from"../../geometry/support/coordsUtils.js";import{sv3d as C}from"../../geometry/support/vectorStacks.js";import{fetchMessageBundle as k}from"../../intl/messages.js";import{getConvertedElevationFromVector as D,absoluteHeightElevationInfo as w}from"../../support/elevationInfoUtils.js";import{getDefaultUnitForView as S}from"../../support/getDefaultUnitForView.js";import M from"../overlay/TextOverlayItem.js";import{onLocaleChange as T}from"../../intl/locale.js";const O=3025,P={default:15,far:25};let V=class extends s{constructor(t){super(t),this.context=null,this.stagedVertex=null,this.visible=!0,this.edgeDistance="default",this._messageUnitsTask=null,this._labelInfos=[],this._nextLabelIndex=0}initialize(){this.addHandles([h((()=>[null!=this.context&&this.getCameraOrExtent(this.context),this.visible,this._edgeDistancePixels,this.stagedVertex,this._messagesUnits]),(()=>this._update())),...["vertex-add","vertex-update","vertex-remove"].map((t=>p((()=>this.context?.editGeometryOperations),t,(()=>this._update())))),h((()=>this._colors),(t=>this._updateStyle(t))),T((()=>this._refreshMessages())),l((()=>this._messageUnitsTask?.abort()))]),this._refreshMessages()}destroy(){for(this._nextLabelIndex=0;this._labelInfos.length;)this._destroyLabel(this._labelInfos.pop())}get updating(){return null==this._messagesUnits}get test(){}get _messagesUnits(){return this._messageUnitsTask?.value}get _edgeDistancePixels(){return P[this.edgeDistance]}get _colors(){const t=this.context?.view.effectiveTheme.textColor??e.fromArray([255,255,255]);return{textColor:t,backgroundColor:r(i(t,n.Low),.6)}}_update(){if(this.destroyed)return;this._nextLabelIndex=0;const{context:t,stagedVertex:e}=this;if(!t)return this._destroyUnusedLabels();const{editGeometryOperations:s}=t,{components:o,geometry:r,coordinateHelper:i}=s.data;if(!r)return this._destroyUnusedLabels();const n=o.length;for(let l=0;l<n;++l){const o=G(r,s,e,i,l);if(o.length<2||!A(o,t.view,t.elevationInfo,i.spatialReference))continue;const a=1===n&&!I(o);let c=F,h=H;this.toScreenPointArray(t,o[0],c);for(let e=1;e<o.length;++e){const s=o[e-1],r=o[e];this.toScreenPointArray(t,r,h),this._addLabel(t,s,c,r,h,a),[c,h]=[h,c]}}this._destroyUnusedLabels()}_updateStyle({textColor:t,backgroundColor:e}){const s=this._nextLabelIndex,o=this._labelInfos;for(let r=0;r<s;++r){const{label:s}=o[r];s.textColor=t,s.backgroundColor=e}}_addLabel(t,e,s,o,r,i){const{label:n}=this._getOrCreateLabel(t);if(!this.visible||b(s,r)<O)return void(n.visible=!1);const{spatialReference:l}=t.editGeometryOperations.data,a=t.automaticLengthMeasurementUtils.autoDistance2D(e,o,l),h=this._messagesUnits,p=S(t.view);n.text=null!=h&&null!=a?c(h,a,p):"",n.visible=!0;const m=r[0]-s[0],d=r[1]-s[1];i?_(q,-d,m):_(q,d,-m),x(q,q),y(q,q,this._edgeDistancePixels),v(z,s,r,.5),U(z,z,q),n.position=[z[0],z[1]],Math.abs(q[0])>Math.abs(q[1])?n.anchor=q[0]>0?"left":"right":n.anchor=-q[1]<0?"top":"bottom"}_getOrCreateLabel(t){const e=this._labelInfos.length>this._nextLabelIndex,{textColor:s,backgroundColor:o}=this._colors;if(e){const t=this._labelInfos[this._nextLabelIndex++],{label:e}=t;return e.textColor=s,e.backgroundColor=o,t}const r=new M({anchor:"center",fontSize:8,textColor:s,backgroundColor:o});t.view.overlay?.items.add(r);const i={label:r};return this._labelInfos.push(i),this._nextLabelIndex=this._labelInfos.length,i}_destroyUnusedLabels(){for(;this._labelInfos.length>this._nextLabelIndex;)this._destroyLabel(this._labelInfos.pop())}_destroyLabel({label:t}){this.context?.view.overlay?.items.remove(t),t.destroy()}_refreshMessages(){this._messageUnitsTask?.abort(),this._messageUnitsTask=o((()=>k("esri/core/t9n/Units")))}};function G(t,e,s,o,r){const i=[];if(e.data.components[r].iterateVertices((t=>{i.push(o.toXYZ(t.pos,C.get()))})),0===r&&null!=s&&i.push(o.toXYZ(s,C.get())),i.length<2)return i;const n=i[0],l=i[i.length-1];return"polygon"===t.type&&i.length>2&&!L(n,l)&&i.push(n),i}function A(t,e,s,o){if("2d"===e.type)return!0;const r=d(o)??1,i=u(o),n=t=>D(e,t,o,s,w)??0;for(let l=1;l<t.length;++l){const e=t[l-1],s=t[l],o=(s[0]-e[0])*r,a=(s[1]-e[1])*r,c=(n(s)-n(e))*i;if(Math.abs(c)/Math.sqrt(o*o+a*a)>R)return!1}return!0}t([f()],V.prototype,"context",void 0),t([f()],V.prototype,"stagedVertex",void 0),t([f()],V.prototype,"visible",void 0),t([f()],V.prototype,"edgeDistance",void 0),t([f()],V.prototype,"updating",null),t([f()],V.prototype,"_messageUnitsTask",void 0),t([f()],V.prototype,"_messagesUnits",null),t([f()],V.prototype,"_edgeDistancePixels",null),t([f()],V.prototype,"_colors",null),V=t([g("esri.views.interactive.SegmentLabels")],V);const R=a(5),q=j(),z=j(),F=m(),H=m();export{V as SegmentLabels};