@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 4.57 kB
JavaScript
import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../core/Accessor.js";import{createTask as s}from"../../core/asyncUtils.js";import{makeHandle as o}from"../../core/handleUtils.js";import{isNone as i,isSome as r,applySome as a}from"../../core/maybe.js";import{throwIfAborted as n}from"../../core/promiseUtils.js";import{formatLength as l}from"../../core/quantityFormatUtils.js";import{watch as p,on as c}from"../../core/reactiveUtils.js";import{createScreenPointArray as h}from"../../core/screenUtils.js";import{property as d}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import"../../core/arrayUtils.js";import{subclass as m}from"../../core/accessorSupport/decorators/subclass.js";import{k as u,s as f,f as b,b as g,l as _,j as x}from"../../chunks/vec2.js";import{a as y}from"../../chunks/vec2f64.js";import{F as v}from"../../chunks/vec3.js";import{isClockwise as j}from"../../geometry/support/coordsUtils.js";import{fetchMessageBundle as U}from"../../intl/messages.js";import{getGeometryEffectiveElevationMode as I}from"../../support/elevationInfoUtils.js";import{getDefaultUnitForView as L}from"../../support/getDefaultUnitForView.js";import D from"../overlay/TextOverlayItem.js";import{autoDirectDistanceByElevationMode as O}from"../support/automaticLengthMeasurementUtils.js";const S=3025,w={default:15,far:25};let V=class extends t{constructor(e){super(e),this.context=null,this.stagedVertex=null,this.visible=!0,this.edgeDistance="default",this._messagesUnits=null,this._labelInfos=[],this._nextLabelIndex=0}initialize(){const e=s((async e=>{const t=await U("esri/core/t9n/Units");n(e),this._messagesUnits=t})),t=()=>a(this.context,(e=>e.editGeometryOperations));this.addHandles([p((()=>[r(this.context)&&this.getCameraOrExtent(this.context),this.visible,this._edgeDistancePixels,this.stagedVertex,this._messagesUnits]),(()=>this._update())),...["vertex-add","vertex-update","vertex-remove"].map((e=>c(t,e,(()=>this._update())))),o((()=>e.abort()))])}destroy(){for(this._nextLabelIndex=0;this._labelInfos.length;)this._destroyLabel(this._labelInfos.pop())}get updating(){return i(this._messagesUnits)}get test(){return{labelContents:this._labelInfos.slice(0,this._nextLabelIndex).map((e=>e.label.text))}}get _edgeDistancePixels(){return w[this.edgeDistance]}_update(){this._nextLabelIndex=0;const e=this.context;if(i(e))return void this._destroyUnusedLabels();const{components:t,geometry:s,coordinateHelper:o}=e.editGeometryOperations.data;if(!s)return void this._destroyUnusedLabels();const a=t.length;for(let i=0;i<a;++i){const n=[];if(t[i].iterateVertices((e=>{n.push(o.toXYZ(e.pos))})),0===i&&r(this.stagedVertex)&&n.push(o.toXYZ(this.stagedVertex)),n.length<2)continue;const l=n[0],p=n[n.length-1];"polygon"===s.type&&n.length>2&&!v(l,p)&&n.push(l);const c=1===a&&!j(n,!1,!1);let h=C,d=G;this.toScreenPointArray(e,l,h);for(let t=1;t<n.length;++t){const s=n[t-1],o=n[t];this.toScreenPointArray(e,o,d),this._addLabel(e,s,h,o,d,c),[h,d]=[d,h]}}this._destroyUnusedLabels()}_addLabel(e,t,s,o,i,a){const{label:n}=this._getOrCreateLabel(e);if(!this.visible||u(s,i)<S)return void(n.visible=!1);const p=r(e.graphicState)?e.graphicState.isDraped?"on-the-ground":"absolute-height":I(e.editGeometryOperations.data.geometry,e.elevationInfo),{spatialReference:c}=e.editGeometryOperations.data,h=O(t,o,c,p),d=this._messagesUnits,m=L(e.view);n.text=r(d)&&r(h)?l(d,h,m):"",n.visible=!0;const y=i[0]-s[0],v=i[1]-s[1];a?f(P,-v,y):f(P,v,-y),b(P,P),g(P,P,this._edgeDistancePixels),_(k,s,i,.5),x(k,k,P),n.position=[k[0],k[1]],Math.abs(P[0])>Math.abs(P[1])?n.anchor=P[0]>0?"left":"right":n.anchor=-P[1]<0?"top":"bottom"}_getOrCreateLabel(e){if(this._labelInfos.length>this._nextLabelIndex)return this._labelInfos[this._nextLabelIndex++];const t=new D({fontSize:10,anchor:"center"});e.view.overlay?.items.add(t);const s={label:t};return this._labelInfos.push(s),this._nextLabelIndex=this._labelInfos.length,s}_destroyUnusedLabels(){for(;this._labelInfos.length>this._nextLabelIndex;)this._destroyLabel(this._labelInfos.pop())}_destroyLabel({label:e}){a(this.context,(t=>t.view.overlay?.items.remove(e))),e.destroy()}};e([d()],V.prototype,"context",void 0),e([d()],V.prototype,"stagedVertex",void 0),e([d()],V.prototype,"visible",void 0),e([d()],V.prototype,"edgeDistance",void 0),e([d()],V.prototype,"updating",null),e([d()],V.prototype,"_messagesUnits",void 0),e([d()],V.prototype,"_edgeDistancePixels",null),V=e([m("esri.views.interactive")],V);const P=y(),k=y(),C=h(),G=h();export{V as SegmentLabels};