@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 14.4 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,getContrastColor as r,getTextHaloColor as n,getTextColor as a}from"../../../../../core/analysisThemeUtils.js";import"../../../../../core/has.js";import o from"../../../../../core/Handles.js";import{nextHighestPowerOfTen as l}from"../../../../../core/mathUtils.js";import{destroyMaybe as h,isNone as m,isSome as c,unwrap as p}from"../../../../../core/maybe.js";import{formatDecimal as d}from"../../../../../core/quantityFormatUtils.js";import{toUnit as u}from"../../../../../core/quantityUtils.js";import{watch as g,syncAndInitial as _}from"../../../../../core/reactiveUtils.js";import{convertUnit as L,preferredImperialAreaUnit as b,preferredMetricAreaUnit as v,preferredImperialLengthUnit as f,preferredMetricLengthUnit as S}from"../../../../../core/unitUtils.js";import{property as w}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/accessorSupport/ensureType.js";import"../../../../../core/arrayUtils.js";import{subclass as y}from"../../../../../core/accessorSupport/decorators/subclass.js";import{f as j}from"../../../../../chunks/mat4.js";import{c as A}from"../../../../../chunks/mat4f64.js";import{b as C}from"../../../../../chunks/vec3.js";import{c as P}from"../../../../../chunks/vec3f64.js";import{midpoint as D}from"../../support/viewUtils.js";import{LabelVisualElement as V}from"../../../interactive/visualElements/LabelVisualElement.js";import{LineVisualElement as M}from"../../../interactive/visualElements/LineVisualElement.js";import{MeasurementAreaVisualElement as R}from"../../../interactive/visualElements/MeasurementAreaVisualElement.js";import{GeodesicSegment as U,EuclideanSegment as I}from"../../../interactive/visualElements/support/Segment.js";import{RenderOccludedFlag as O}from"../../../webgl-engine/lib/Material.js";import{createStipplePatternSimple as z}from"../../../webgl-engine/materials/lineStippleUtils.js";import{onLocaleChange as k}from"../../../../../intl/locale.js";import{fetchMessageBundle as q}from"../../../../../intl/messages.js";let x=class extends i{get visible(){return this.analysisViewData.visible}get testData(){return{labels:{area:this._areaLabel,pathLength:this._pathLengthLabel,cursorSegmentLength:this._cursorSegmentLengthLabel,perimeterLength:this._perimeterLengthLabel}}}constructor(e){super(e),this._handles=new o,this._params={pathLineColor:t.toUnitRGBA(s()),pathLineWidth:3,intersectingLineColor:[1,.2,0,1],perimeterLineColor:t.toUnitRGBA(s()),perimeterLineWidth:2,projectionLineColor:t.toUnitRGBA(s()),projectionLineWidth:2,projectionLineStippleSize:5,areaColor1:t.toUnitRGBA(s(.5)),areaColor2:t.toUnitRGBA(r(.5)),labelDistance:25},this._path=null,this._intersectedPath=null,this._perimeter=null,this._intersectedPerimeter=null,this._projectionLines=null,this._measurementArea=null,this._areaLabel=null,this._pathLengthLabel=null,this._cursorSegmentLengthLabel=null,this._perimeterLengthLabel=null,this._pathSegments=[],this._perimeterSegments=[],this._cursorSegment=null,this._origin=P(),this._originTransform=A(),this._cursorPositionRenderSpace=P(),this.messages=null,this.viewData=F,this.areaLabel=null,this.perimeterLengthLabel=null,this.loadingMessages=!0}initialize(){const{analysisViewData:e,_params:t,view:i}=this;this._path=new M({view:i,attached:!0,width:t.pathLineWidth,color:t.pathLineColor,polygonOffset:!0,renderOccluded:O.OccludeAndTransparent}),this._intersectedPath=new M({view:i,attached:!0,width:t.pathLineWidth,color:t.intersectingLineColor,polygonOffset:!0,renderOccluded:O.OccludeAndTransparent}),this._perimeter=new M({view:i,attached:!0,width:t.perimeterLineWidth,color:t.perimeterLineColor,polygonOffset:!0,renderOccluded:O.OccludeAndTransparent}),this._intersectedPerimeter=new M({view:i,attached:!0,width:t.perimeterLineWidth,color:t.intersectingLineColor,polygonOffset:!0,renderOccluded:O.OccludeAndTransparent}),this._projectionLines=new M({view:i,attached:!0,width:t.projectionLineWidth,color:t.projectionLineColor,stipplePattern:z(t.projectionLineStippleSize),polygonOffset:!0,renderOccluded:O.OccludeAndTransparent}),this._measurementArea=new R({view:i,attached:!0,color1:t.areaColor1,color2:t.areaColor2});const s={attached:!0,backgroundColor:n(.6),textColor:a(),view:i};this._areaLabel=new V({...s,fontSize:G.Large}),this._pathLengthLabel=new V({...s,fontSize:G.Small}),this._cursorSegmentLengthLabel=new V({...s,fontSize:G.Small}),this._perimeterLengthLabel=new V({...s,fontSize:G.Small}),this._handles.add([g((()=>[e.mode,this.visible,e.unit,e.measurementData,e.cursorPoint]),(()=>this._update()),_),g((()=>i.state?.camera),(()=>this._updateLabels()),_),k((()=>this._updateMessageBundle()))]),this._updateMessageBundle()}destroy(){this._measurementArea=h(this._measurementArea),this._path=h(this._path),this._intersectedPath=h(this._intersectedPath),this._perimeter=h(this._perimeter),this._intersectedPerimeter=h(this._intersectedPerimeter),this._areaLabel=h(this._areaLabel),this._pathLengthLabel=h(this._pathLengthLabel),this._cursorSegmentLengthLabel=h(this._cursorSegmentLengthLabel),this._perimeterLengthLabel=h(this._perimeterLengthLabel),this._projectionLines=h(this._projectionLines),this._handles=h(this._handles),this.set("view",null)}_update(){if(this.destroyed||!this.view.ready||!this.view.renderCoordsHelper)return;const{analysisViewData:{measurementData:e},analysisViewData:t}=this;m(e)||(this._updateViewData(e,t.path,t.cursorPoint),this._updateOrigin(),this._updatePathSegments(),this._updatePerimeterSegments(),this._updateArea(),this._updateProjectionLines(),this._updateLabels())}_updateViewData(e,t,i){const s=t.isValidPolygon,r="geodesic"===e.actualMeasurementMode,n=r?e.geodesicArea:e.area;let a=1;if(n){const t=this._toPreferredAreaUnit(n,this.analysisViewData.unit);a=l(Math.sqrt(t.value)/Math.sqrt(300)),a*=Math.sqrt(L(1,t.unit,"square-meters")),a/=e.unitNormalizer.normalizeDistance(1)}const o={validMeasurement:s,path:t,pathVersion:t.version,cursorPoint:i,measurementData:e,mode:e.actualMeasurementMode,positionsGeographic:e.positionsGeographic,positionsRenderCoords:e.positionsRenderCoords,positionsProjected:e.positionsProjectedWorldCoords,positionsFittedRenderCoords:e.positionsFittedRenderCoords,intersectingSegments:r?e.geodesicIntersectingSegments:e.intersectingSegments,triangleIndices:r?e.geodesicTriangleIndices:e.triangleIndices,fittingMode:e.fittingMode,areaCentroid:r?e.geodesicAreaCentroidRenderCoords:e.areaCentroidRenderCoords,pathLengthLabelSegmentIndex:s?0:t.numVertices-2,perimeterLengthLabelSegmentIndex:0,checkerSize:a};this._set("viewData",o)}_updateOrigin(){const e=this.viewData;D(e.positionsRenderCoords,this._origin),j(this._originTransform,this._origin),this._measurementArea.transform=this._originTransform,this._projectionLines.transform=this._originTransform}_createSegments(e){const t=this.viewData,i=t.path,s=this.view.renderCoordsHelper.spatialReference,r=t.mode,n=[],a=[],o=[],l=t.validMeasurement?i.numVertices:i.numVertices-1;for(let h=0;h<l;++h){const l=t[e][h],m=t[e][(h+1)%i.numVertices];let c=null;switch(r){case"euclidean":c=new I(l,m);break;case"geodesic":c=new U(l,m,s)}t.intersectingSegments.has(h)?o.push(c):a.push(c),n.push(c)}return{all:n,nonIntersecting:a,intersecting:o}}_updatePathSegments(){const{view:{renderCoordsHelper:e},viewData:t,visible:i}=this,s=this._createSegments("positionsRenderCoords"),{cursorPoint:r,mode:n,path:a}=t,o=!a.isValidPolygon,l=e.spatialReference;if(this._cursorSegment=null,a.numVertices>0&&o&&c(r)){if(e.toRenderCoords(r,this._cursorPositionRenderSpace)){const e=t.positionsRenderCoords[a.numVertices-1],i=this._cursorPositionRenderSpace;let r=null;switch(n){case"euclidean":r=new I(e,i);break;case"geodesic":r=new U(e,i,l)}s.nonIntersecting.push(r),this._cursorSegment=r}}this._path.setGeometryFromSegments(s.nonIntersecting,this._origin),this._path.visible=i,this._intersectedPath.setGeometryFromSegments(s.intersecting,this._origin),this._intersectedPath.visible=i,this._pathSegments=s.all}_updatePerimeterSegments(){const e=this.visible&&"euclidean"===this.viewData.mode,t=this._createSegments("positionsFittedRenderCoords");this._perimeter.setGeometryFromSegments(t.nonIntersecting,this._origin),this._perimeter.visible=e,this._intersectedPerimeter.setGeometryFromSegments(t.intersecting,this._origin),this._intersectedPerimeter.visible=e,this._perimeterSegments=t.all}_updateArea(){const e=this.viewData;switch(e.mode){case"euclidean":this._updateAreaEuclidean(e);break;case"geodesic":this._updateAreaGeodesic()}}_updateAreaEuclidean(e){const t=this.visible;e.validMeasurement&&0===e.intersectingSegments.size&&e.triangleIndices?(this._measurementArea.geometry={uv:e.positionsProjected,position:e.positionsFittedRenderCoords,triangleIndices:e.triangleIndices},this._measurementArea.size=[e.checkerSize,e.checkerSize],this._measurementArea.visible=t):this._measurementArea.visible=!1}_updateAreaGeodesic(){this._measurementArea.visible=!1}_updateProjectionLines(){const e=this.viewData,t=this.visible,i=e.path,s=e.mode;if(i.numVertices>0&&e.validMeasurement&&"euclidean"===s){const s=[];for(let t=0;t<i.numVertices;++t){const i=P();C(i,e.positionsRenderCoords[t],this._origin);const r=P();C(r,e.positionsFittedRenderCoords[t],this._origin),s.push([i,r])}this._projectionLines.geometry=s,this._projectionLines.visible=t}else this._projectionLines.geometry=null,this._projectionLines.visible=!1}_updateLabels(){if(this.destroyed)return;const{viewData:e}=this,{measurementData:t,mode:i,path:s}=e;if(!s)return;const r=!s.isValidPolygon,n=this.visible,a=this._formatAreaLabel(this.messages,"geodesic"===i?t.geodesicArea:t.area,this.analysisViewData.unit);c(a)?(this._areaLabel.geometry={type:"point",point:e.areaCentroid},this._areaLabel.text=a,this._areaLabel.visible=e.validMeasurement&&0===e.intersectingSegments.size&&n):this._areaLabel.visible=!1,this._set("areaLabel",p(a));const o=this._formatLengthLabel(this.messages,"geodesic"===i?t.geodesicPathLength:t.pathLength,this.analysisViewData.unit);if(c(o)&&e.pathLengthLabelSegmentIndex>=0&&e.pathLengthLabelSegmentIndex<this._pathSegments.length){const t=this._pathSegments[e.pathLengthLabelSegmentIndex],i=c(this._cursorSegment)?this._cursorSegment:T;this._pathLengthLabel.distance=this._params.labelDistance,this._pathLengthLabel.geometry={type:"corner",left:t,right:i},this._pathLengthLabel.text=o,this._pathLengthLabel.visible=r&&s.numVertices>0&&n}else this._pathLengthLabel.visible=!1;const l="geodesic"===i?e.measurementData.geodesicCursorSegmentLength:e.measurementData.cursorSegmentLength;if(c(l)){const e=this._formatLengthLabel(this.messages,l,this.analysisViewData.unit);this._cursorSegmentLengthLabel.distance=this._params.labelDistance,this._cursorSegmentLengthLabel.geometry=c(this._cursorSegment)?{type:"segment",segment:this._cursorSegment,sampleLocation:"end"}:null,this._cursorSegmentLengthLabel.anchor="bottom",this._cursorSegmentLengthLabel.text=p(e),this._cursorSegmentLengthLabel.visible=r&&0!==l.value&&n}else this._cursorSegmentLengthLabel.visible=!1;this._cursorSegmentLengthLabel.overlaps(this._pathLengthLabel)&&(this._cursorSegmentLengthLabel.visible=!1),this._pathLengthLabel.overlaps(this._areaLabel)&&(this._pathLengthLabel.visible=!1);const h="geodesic"===e.mode,m=h?t.geodesicPathLength:t.perimeterLength,d=this._formatLengthLabel(this.messages,m,this.analysisViewData.unit);if(this._set("perimeterLengthLabel",p(d)),e.validMeasurement&&0===e.intersectingSegments.size){this._perimeterLengthLabel.distance=this._params.labelDistance,this._perimeterLengthLabel.anchor="top",this._perimeterLengthLabel.text=p(d),this._perimeterLengthLabel.visible=!0;let t=!0;for(let i=0;i<e.path.numVertices;++i){const s=(e.perimeterLengthLabelSegmentIndex+i)%e.path.numVertices,r=h?this._pathSegments[s]:this._perimeterSegments[s];if(t=!0,this._perimeterLengthLabel.geometry={type:"segment",segment:r,sampleLocation:"center"},!this._perimeterLengthLabel.overlaps(this._areaLabel))break;t=!1}this._perimeterLengthLabel.visible=t&&n}else this._perimeterLengthLabel.visible=!1}_toPreferredAreaUnit(e,t){return u(e,this._preferredAreaUnit(e,t))}_preferredAreaUnit(e,t){switch(t){case"metric":return v(e.value,e.unit);case"imperial":return b(e.value,e.unit);default:return t}}_preferredLengthUnit(e,t){const i=this._deriveLengthUnitFromAreaUnit(t);switch(i){case"metric":return S(e.value,e.unit);case"imperial":return f(e.value,e.unit);default:return i}}_deriveLengthUnitFromAreaUnit(e){switch(e){case"metric":case"ares":case"hectares":return"metric";case"imperial":case"acres":return"imperial";case"square-inches":return"inches";case"square-feet":return"feet";case"square-yards":return"yards";case"square-miles":return"miles";case"square-us-feet":return"us-feet";case"square-millimeters":return"millimeters";case"square-centimeters":return"centimeters";case"square-decimeters":return"decimeters";case"square-meters":return"meters";case"square-kilometers":return"kilometers"}throw new Error("unhandled area unit")}_formatAreaLabel(e,t,i){return e&&t&&d(e,t,this._preferredAreaUnit(t,i))}_formatLengthLabel(e,t,i){return e&&t&&d(e,t,this._preferredLengthUnit(t,i))}_updateMessageBundle(){this.loadingMessages=!0,q("esri/core/t9n/Units").then((e=>{this.messages=e,this.view&&this._update()})).finally((()=>{this.loadingMessages=!1}))}};var G;e([w()],x.prototype,"view",void 0),e([w()],x.prototype,"messages",void 0),e([w()],x.prototype,"analysis",void 0),e([w()],x.prototype,"viewData",void 0),e([w()],x.prototype,"analysisViewData",void 0),e([w({readOnly:!0})],x.prototype,"areaLabel",void 0),e([w({readOnly:!0})],x.prototype,"perimeterLengthLabel",void 0),e([w()],x.prototype,"loadingMessages",void 0),e([w()],x.prototype,"visible",null),x=e([y("esri.views.3d.analysis.AreaMeasurement.support.AreaMeasurementVisualization")],x),function(e){e[e.Small=12]="Small",e[e.Large=16]="Large"}(G||(G={}));const F={validMeasurement:!1,path:null,pathVersion:-1,cursorPoint:null,measurementData:null,mode:null,positionsGeographic:null,positionsRenderCoords:null,positionsProjected:null,positionsFittedRenderCoords:null,intersectingSegments:null,triangleIndices:null,fittingMode:null,areaCentroid:null,pathLengthLabelSegmentIndex:null,perimeterLengthLabelSegmentIndex:null,checkerSize:null},T=new I(P(),P());export{x as AreaMeasurementVisualization};