@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 14.5 kB
JavaScript
import{_ as e}from"../../../../chunks/tslib.es6.js";import t from"../../../../Color.js";import"../../../../intl.js";import i from"../../../../core/Accessor.js";import{getAccentColor as s,getTextHaloColor as n,getTextColor as o}from"../../../../core/analysisThemeUtils.js";import a from"../../../../core/Handles.js";import{nextHighestPowerOfTen as r,deg2rad as l}from"../../../../core/mathUtils.js";import{isNone as c,destroyMaybe as d,isSome as h}from"../../../../core/maybe.js";import{formatDecimal as m,formatImperialLength as u,formatImperialVerticalLength as g,formatMetricLength as p,formatMetricVerticalLength as _}from"../../../../core/quantityFormatUtils.js";import{toUnit as v}from"../../../../core/quantityUtils.js";import{watch as b,syncAndInitial as L}from"../../../../core/reactiveUtils.js";import{createRenderScreenPointArray3 as w,createRenderScreenPointArray as S}from"../../../../core/screenUtils.js";import{preferredImperialLengthUnit as y,convertUnit as f}from"../../../../core/unitUtils.js";import{property as A}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import"../../../../core/arrayUtils.js";import{subclass as P}from"../../../../core/accessorSupport/decorators/subclass.js";import{h as V}from"../../../../chunks/vec2.js";import{g as j,a as E}from"../../../../chunks/vec3.js";import{c as z}from"../../../../chunks/vec3f64.js";import{MeasurementMode as M}from"../interfaces.js";import{ViewMode as D,VisualElementOrientation as O}from"./interfaces.js";import{screenSpaceTangent as G}from"../support/viewUtils.js";import{LabelVisualElement as x,mirrorPosition as C}from"../../interactive/visualElements/LabelVisualElement.js";import{LineVisualElement as T}from"../../interactive/visualElements/LineVisualElement.js";import{MeasurementArrowVisualElement as H}from"../../interactive/visualElements/MeasurementArrowVisualElement.js";import{RightAngleQuadVisualElement as U}from"../../interactive/visualElements/RightAngleQuadVisualElement.js";import{GeodesicSegment as k,EuclideanSegment as R}from"../../interactive/visualElements/support/Segment.js";import{RenderOccludedFlag as F}from"../../webgl-engine/lib/Material.js";import{createStipplePatternSimple as B}from"../../webgl-engine/materials/lineStippleUtils.js";import{onLocaleChange as Q}from"../../../../intl/locale.js";import{fetchMessageBundle as q}from"../../../../intl/messages.js";let W=class extends i{get visible(){return this.analysisView.visible}get viewMode(){const{elevationAlignedStartPoint:e,elevationAlignedEndPoint:t}=this.analysisView;if(c(e)||c(t)||e.equals(t))return D.None;const i=this.analysisView.result;if(c(i))return D.Direct;if("geodesic"===i.mode)return this._requiresGeodesicGuideAt(this._startPosition)||this._requiresGeodesicGuideAt(this._endPosition)?D.ProjectedGeodesic:D.Direct;const{verticalDistance:s,horizontalDistance:n}=i,o=s.value,a=n.value;return Math.min(o/a,a/o)<this.triangleCollapseRatioThreshold?D.Direct:D.Triangle}get actualVisualizedMeasurement(){if(c(this.analysisView.result))switch(this.analysisView.measurementMode){case M.Auto:case M.Euclidean:default:return"euclidean";case M.Geodesic:return"geodesic"}return this.analysisView.result.mode}get allowVisualElementsOrientationChange(){return c(this._triangleOrientationOverride)}set allowVisualElementsOrientationChange(e){c(this._triangleOrientationOverride)!==e&&(c(this._triangleOrientationOverride)?this._triangleOrientationOverride=this._actualVisualElementsOrientation:this._triangleOrientationOverride=null)}get labels(){const e="geodesic"===this.actualVisualizedMeasurement;return{direct:this._segmentLabel,horizontal:e?this._segmentLabel:this._horizontalLabel,vertical:this._verticalLabel}}constructor(e){super(e),this._params={triangleColor:t.toUnitRGBA(s(.75)),triangleLineWidth:3,geodesicProjectionLineWidth:2,geodesicProjectionLineColor:t.toUnitRGBA(s(.75)),guideLineWidth:2,guideStippleLengthPixels:6,direcLabelFontSize:16,horizontalLabelFontSize:12,verticalLabelFontSize:12},this._handles=new a,this._segmentVisualElement=null,this._triangleVisualElement=null,this._rightAngleQuad=null,this._projectedGeodesicLine=null,this._geodesicStartHint=null,this._geodesicEndHint=null,this._segmentLabel=null,this._verticalLabel=null,this._horizontalLabel=null,this._startPosition=z(),this._endPosition=z(),this._cornerPosition=z(),this._startPositionAtSeaLevel=z(),this._endPositionAtSeaLevel=z(),this._triangleOrientationOverride=null,this.messages=null,this.loadingMessages=!0,this.visualElementOrientation=O.Auto,this.triangleCollapseRatioThreshold=.03}initialize(){const e=this._params,i={attached:!0,view:this.view};this._segmentVisualElement=new H({...i,geometry:null,renderOccluded:F.OccludeAndTransparent}),this._triangleVisualElement=new T({...i,width:e.triangleLineWidth,color:e.triangleColor,renderOccluded:F.OccludeAndTransparent}),this._rightAngleQuad=new U({...i,color:t.toUnitRGBA(s(.75)),renderOccluded:F.OccludeAndTransparent});const a={...i,polygonOffset:!0,renderOccluded:F.OccludeAndTransparent};this._projectedGeodesicLine=new T({...a,width:e.geodesicProjectionLineWidth,color:e.geodesicProjectionLineColor,stipplePattern:B(e.guideStippleLengthPixels)}),this._geodesicStartHint=new T({...a,width:e.guideLineWidth,color:e.geodesicProjectionLineColor,stipplePattern:B(e.guideStippleLengthPixels)}),this._geodesicEndHint=new T({...a,width:e.guideLineWidth,color:e.geodesicProjectionLineColor,stipplePattern:B(e.guideStippleLengthPixels)});const r={...i,backgroundColor:n(.6),textColor:o()};this._segmentLabel=new x({...r,fontSize:e.direcLabelFontSize}),this._verticalLabel=new x({...r,fontSize:e.verticalLabelFontSize}),this._horizontalLabel=new x({...r,fontSize:e.horizontalLabelFontSize}),this._handles.add([b((()=>{const{elevationAlignedStartPoint:e,elevationAlignedEndPoint:t}=this.analysisView,i=this.view;return{view:i,camera:i.state.camera,viewMode:this.viewMode,elevationAlignedStartPoint:e,elevationAlignedEndPoint:t,orientation:this._actualVisualElementsOrientation,visualizedMeasurement:this.actualVisualizedMeasurement,stripeLength:this._measurementArrowStripeLength}}),(e=>this._updateGeometryAndViewMode(e)),L),b((()=>({visible:this.visible,viewMode:this.viewMode})),(e=>this._updateVisualElementVisibility(e)),L),b((()=>({text:this._labelsText,visualizedMeasurement:this.actualVisualizedMeasurement})),(e=>this._updateLabelText(e)),L),b((()=>({visible:this.visible,viewMode:this.viewMode})),(e=>this._updateLabelVisibility(e)),L),b((()=>this._measurementArrowStripeLength),(e=>this._updateSegmentStripeLength(e)),L),Q((async()=>this._updateMessageBundle()))]),this._updateMessageBundle()}destroy(){this._handles=d(this._handles),this._segmentVisualElement=d(this._segmentVisualElement),this._triangleVisualElement=d(this._triangleVisualElement),this._rightAngleQuad=d(this._rightAngleQuad),this._projectedGeodesicLine=d(this._projectedGeodesicLine),this._geodesicStartHint=d(this._geodesicStartHint),this._geodesicEndHint=d(this._geodesicEndHint),this._segmentLabel=d(this._segmentLabel),this._verticalLabel=d(this._verticalLabel),this._horizontalLabel=d(this._horizontalLabel),this.set("view",null)}_updateVisualElementVisibility({visible:e,viewMode:t}){if(this._segmentVisualElement.visible=!1,this._triangleVisualElement.visible=!1,this._rightAngleQuad.visible=!1,this._projectedGeodesicLine.visible=!1,this._geodesicStartHint.visible=!1,this._geodesicEndHint.visible=!1,e)switch(t){case D.None:break;case D.Direct:this._segmentVisualElement.visible=!0;break;case D.Triangle:this._segmentVisualElement.visible=!0,this._triangleVisualElement.visible=!0,this._rightAngleQuad.visible=!0;break;case D.ProjectedGeodesic:this._segmentVisualElement.visible=!0,this._projectedGeodesicLine.visible=!0,this._geodesicStartHint.visible=!0,this._geodesicEndHint.visible=!0}}_updateGeometryAndViewMode({view:e,camera:t,viewMode:i,elevationAlignedStartPoint:s,elevationAlignedEndPoint:n,orientation:o,visualizedMeasurement:a,stripeLength:r}){const l=e.renderCoordsHelper;if(c(l)||c(s)||c(n)||s.equals(n))return;let d=this._startPosition,h=this._endPosition;l.toRenderCoords(s,d),l.toRenderCoords(n,h);const m=o===O.AboveSegment?1:-1,u=m*(l.getAltitude(h)-l.getAltitude(d));u<0&&(d=this._endPosition,h=this._startPosition);const g="geodesic"===a?new k(this._startPosition,this._endPosition,l.spatialReference):new R(this._startPosition,this._endPosition);switch(this._segmentVisualElement.geometry=g,this._updateSegmentStripeLength(r),i){case D.Direct:this._updateSegment(g,o);break;case D.Triangle:this._updateSegmentAndTriangle({view:e,camera:t,segment:g,orientation:o,startPosition:d,endPosition:h,deltaSign:m,altitudeDelta:u});break;case D.ProjectedGeodesic:this._updateSegmentAndProjection({view:e,orientation:o,startPosition:d,endPosition:h})}}_updateSegment(e,t){this._segmentLabel.anchor=t===O.AboveSegment?"top":"bottom",this._segmentLabel.geometry={type:"segment",segment:e,sampleLocation:"center"}}_updateSegmentAndTriangle({view:{renderCoordsHelper:e},camera:t,segment:i,orientation:s,startPosition:n,endPosition:o,deltaSign:a,altitudeDelta:r}){const l=this._cornerPosition;e.worldUpAtPosition(n,l),j(l,l,a*Math.abs(r)),E(l,l,n),this._triangleVisualElement.geometry=[[[n[0],n[1],n[2]],[l[0],l[1],l[2]],[o[0],o[1],o[2]]]],this._rightAngleQuad.geometry={previous:n,center:l,next:o};const c=new R(n,l),d=new R(l,o),h=N(n,o,l,s,t);this._segmentLabel.anchor=h.segment,this._segmentLabel.geometry={type:"segment",segment:i,sampleLocation:"center"},this._verticalLabel.geometry={type:"segment",segment:c,sampleLocation:"center"},this._verticalLabel.anchor=h.vertical,this._horizontalLabel.geometry={type:"segment",segment:d,sampleLocation:"center"},this._horizontalLabel.anchor=h.horizontal}_updateSegmentAndProjection({view:{renderCoordsHelper:e},orientation:t,startPosition:i,endPosition:s}){e.setAltitude(this._startPositionAtSeaLevel,0,i),e.setAltitude(this._endPositionAtSeaLevel,0,s);const n=new k(this._startPositionAtSeaLevel,this._endPositionAtSeaLevel,e.spatialReference);this._projectedGeodesicLine.setGeometryFromSegment(n),this._geodesicStartHint.setGeometryFromSegment(new R(this._startPositionAtSeaLevel,i)),this._geodesicEndHint.setGeometryFromSegment(new R(this._endPositionAtSeaLevel,s)),this._segmentLabel.geometry={type:"segment",segment:n,sampleLocation:"center"},this._segmentLabel.anchor=t===O.AboveSegment?"top":"bottom"}_updateLabelText({text:e,visualizedMeasurement:t}){h(e)?(this._segmentLabel.text="euclidean"===t?e.euclideanDistance:e.geodesicDistance,this._horizontalLabel.text=e.horizontalDistance,this._verticalLabel.text=e.verticalDistance):(this._segmentLabel.text=null,this._horizontalLabel.text=null,this._verticalLabel.text=null),this.notifyChange("labels")}_updateLabelVisibility({visible:e,viewMode:t}){const i=this._segmentLabel,s=this._horizontalLabel,n=this._verticalLabel;if(i.visible=!1,s.visible=!1,n.visible=!1,e)switch(t){case D.Direct:i.visible=!0;break;case D.Triangle:i.visible=!0,s.visible=!0,n.visible=!0;break;case D.ProjectedGeodesic:i.visible=!0;case D.None:}}get _labelsText(){if(this.destroyed)return null;const e=this.messages,t=this.analysisView.result;if(c(t)||c(e))return null;const{directDistance:i,horizontalDistance:s,verticalDistance:n,geodesicDistance:o}=t,a=this.analysisView.unit,r=e=>({euclideanDistance:"",geodesicDistance:"",horizontalDistance:"",verticalDistance:"",...e});switch(a){case"metric":return r({euclideanDistance:i&&p(e,i),geodesicDistance:o&&p(e,o),horizontalDistance:s&&p(e,s),verticalDistance:n&&_(e,n)});case"imperial":return r({euclideanDistance:i&&u(e,i),geodesicDistance:o&&u(e,o),horizontalDistance:s&&u(e,s),verticalDistance:n&&g(e,n)});default:return r({euclideanDistance:i&&m(e,i,a),geodesicDistance:o&&m(e,o,a),horizontalDistance:s&&m(e,s,a),verticalDistance:n&&m(e,n,a)})}}_updateSegmentStripeLength(e){const t=this._segmentVisualElement;h(e)?(t.stripeLength=e,t.stripesEnabled=!0):t.stripesEnabled=!1}get _actualVisualElementsOrientation(){if(h(this._triangleOrientationOverride))return this._triangleOrientationOverride;const e=this.visualElementOrientation;return e===O.Auto?this.view.state.camera.aboveGround?O.AboveSegment:O.BelowSegment:e}_requiresGeodesicGuideAt(e){const t=this.view;if(!t?.state)return!1;const i=t.state.camera,s=t.renderCoordsHelper,n=i.computeScreenPixelSizeAt(e);return s.getAltitude(e)/n>=10}get _measurementArrowStripeLength(){const{result:e,unit:t}=this.analysisView;if(c(e))return null;let i=null;const s=e.directDistance;switch(t){case"metric":i=s&&v(s,"meters");break;case"imperial":i=s&&v(s,y(s.value,s.unit));break;default:i=s&&v(s,t)}if(c(i))return null;return r(i.value/30)*f(1,i.unit,"meters")}_updateMessageBundle(){this.loadingMessages=!0,q("esri/core/t9n/Units").then((e=>{this.messages=e})).finally((()=>{this.loadingMessages=!1}))}get testData(){return{labels:this.labels,stripeLength:this._segmentVisualElement?.stripeLength}}};function N(e,t,i,s,n){const o=J,a=K;n.projectToRenderScreen(i,o),n.projectToRenderScreen(t,a);const r={segment:"bottom",horizontal:"top",vertical:o[0]<a[0]?"left":"right"};{const s=X,o=Y;if(G(e,i,s,n),G(e,t,o,n),V(s,o)>=I){const e=Math.sign(s[1])===Math.sign(o[1]);r.segment=e?C(r.vertical):r.vertical}else{const e=Z;G(i,t,e,n),V(e,o)>=I&&(r.segment=Math.sign(e[0])===Math.sign(o[0])?C(r.horizontal):r.horizontal)}}if(s===O.BelowSegment){const e=e=>"top"===e?"bottom":"top";r.segment=e(r.segment),r.horizontal=e(r.horizontal),r.vertical=e(r.vertical)}return r}e([A()],W.prototype,"_triangleOrientationOverride",void 0),e([A()],W.prototype,"messages",void 0),e([A()],W.prototype,"view",void 0),e([A()],W.prototype,"analysis",void 0),e([A()],W.prototype,"analysisView",void 0),e([A()],W.prototype,"loadingMessages",void 0),e([A()],W.prototype,"visible",null),e([A()],W.prototype,"viewMode",null),e([A()],W.prototype,"actualVisualizedMeasurement",null),e([A()],W.prototype,"visualElementOrientation",void 0),e([A()],W.prototype,"triangleCollapseRatioThreshold",void 0),e([A()],W.prototype,"allowVisualElementsOrientationChange",null),e([A()],W.prototype,"labels",null),e([A()],W.prototype,"_labelsText",null),e([A()],W.prototype,"_actualVisualElementsOrientation",null),e([A()],W.prototype,"_measurementArrowStripeLength",null),W=e([P("esri.views.3d.analysis.DirectLineMeasurement.DirectLineMeasurementVisualization")],W);const I=Math.cos(l(12)),J=w(),K=w(),X=S(),Y=S(),Z=S();export{W as DirectLineMeasurementVisualization};