@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 12 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import{onLocaleChange as t,substitute as i,fetchMessageBundle as s}from"../../../../intl.js";import{volumeMeasurementConfiguration as o}from"../../../../analysis/VolumeMeasurement/volumeMeasurementConfiguration.js";import r from"../../../../core/Accessor.js";import{equals as l}from"../../../../core/arrayUtils.js";import{cyclicalPI as n}from"../../../../core/Cyclical.js";import{destroyMaybe as a}from"../../../../core/maybe.js";import{formatDecimal as c,preferredVolumePrecision as u}from"../../../../core/quantityFormatUtils.js";import{watch as m,initial as d}from"../../../../core/reactiveUtils.js";import{adaptiveVolumeUnit as h}from"../../../../core/units.js";import{property as p,subclass as g}from"../../../../core/accessorSupport/decorators.js";import{e as y}from"../../../../chunks/earcut.js";import{create as _}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{set as f,normalize as v,subtract as j,cross as b,dot as L}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as C,fromValues as w}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{computeTranslationToOriginAndRotation as G}from"../../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{newDoubleArray as V}from"../../../../geometry/support/DoubleArray.js";import{newIndexArray as P}from"../../../../geometry/support/Indices.js";import{angleAroundAxis as R}from"../../../../geometry/support/vector.js";import{t as F}from"../../../../chunks/vec3.js";import A from"../../../../symbols/support/ElevationInfo.js";import{LabelVisualElement as x}from"../../interactive/visualElements/LabelVisualElement.js";import{LineVisualElement as M}from"../../interactive/visualElements/LineVisualElement.js";import{OutlineVisualElement as O}from"../../interactive/visualElements/OutlineVisualElement.js";import{EuclideanSegment as D}from"../../interactive/visualElements/support/Segment.js";import{ElevationContext as U}from"../../layers/graphics/ElevationContext.js";import{extrudePolygon as S}from"../../layers/graphics/extrudeUtils.js";import{polygonToRenderInfo as E}from"../../support/renderInfoUtils/polygon.js";import{CutFillColor as B,VolumeGeometry as N}from"../../webgl-engine/lib/CutFillColor.js";import{createStipplePatternSimple as H}from"../../webgl-engine/materials/lineStippleUtils.js";let T=class extends r{get visible(){return this.analysisViewData.visible&&null!=this.analysisViewData.elevationAlignedGeometry&&null!=this.analysisViewData.targetGeometry}get updating(){return this.loadingMessages}get hasUnsupportedError(){const{error:e}=this.analysisViewData;return!!e&&["unsupported-coordinate-system","unsupported-layer-transparency"].includes(e.name)}get _extrusionHeights(){const{renderCoordsHelper:e}=this.view,{labelAnchors:t,targetGeometry:i}=this.analysisViewData,{targetElevationRange:s}=o;if(!i||!t)return{cut:s,fill:-s};let r=-1/0;for(const o of i.rings)for(const e of o)r=Math.max(r,e[2]);const l=1,n=e.getAltitude(t.fill);return{cut:s,fill:Math.min(n-r,0)-l}}constructor(e){super(e),this.unitsMessages=null,this.messages=null,this.loadingMessages=!0,this._elevationContext=U.fromElevationInfo(new A({mode:"absolute-height"})),this._projectionLines=[]}initialize(){const{view:e}=this,i={view:e,isDecoration:!0},s=o,r={...i,width:s.geometryOutlineWidth};this._elevationAlignedGeometry=new O({...r,isDraped:!0,color:s.geometryOutlineColor.toUnitRGBA()}),this._targetGeometry=new O(r);const l={...i,attached:!0,width:s.projectionLineWidth,renderOccluded:4,polygonOffset:!0},n={...l,stipplePattern:H(s.projectionLineStippleSize)},a=s.cutProjectionLineColor.toUnitRGBA(),c=s.fillProjectionLineColor.toUnitRGBA();this._cutProjectionLines=new M({...l,color:a}),this._occludedCutProjectionLines=new M({...n,color:a}),this._fillProjectionLines=new M({...l,color:c}),this._occludedFillProjectionLines=new M({...n,color:c});const u={...i,attached:!0};this._cutVolumeLabel=new x({...u,distance:s.labelDistance}),this._fillVolumeLabel=new x({...u,distance:-s.labelDistance}),this._cutFillRenderNode=new B({view:e,cutColor:s.cutColor,fillColor:s.fillColor,borderColor:s.geometryOutlineColor}),this.addHandles([m(()=>({elevationAlignedGeometry:this.analysisViewData.elevationAlignedGeometry,targetGeometry:this.analysisViewData.targetGeometry}),({elevationAlignedGeometry:e,targetGeometry:t})=>{this._elevationAlignedGeometry.geometry=e,this._targetGeometry.geometry=t},d),m(()=>({interactive:this.analysisViewData.interactive,measureType:this.analysis.measureType,visible:this.visible}),({visible:e,interactive:t,measureType:i})=>{this._elevationAlignedGeometry.visible=e&&!t,this._targetGeometry.visible=e&&"cut-fill"===i,this._cutFillRenderNode.measureType=i},d),m(()=>({elevationAlignedGeometry:this.analysisViewData.elevationAlignedGeometry,targetGeometry:this.analysisViewData.targetGeometry,visible:this.visible}),({elevationAlignedGeometry:e,targetGeometry:t,visible:i})=>this._updateProjectionLines(e,t,i),d),m(()=>({interactive:this.analysisViewData.interactive,accentColor:this.view.effectiveTheme.accentColor,hasResult:!!this.analysisViewData.result}),({interactive:e,accentColor:t,hasResult:i})=>{this._updateColors(e,t,i)},d),m(()=>[this.analysisViewData.targetGeometry,this._extrusionHeights],()=>this._updateCutFillGeometry(),d),m(()=>this.visible&&this.view.state.camera.aboveGround&&!this.hasUnsupportedError,e=>this._updateCutFillVisibility(e),d),m(()=>{const{messages:e,unitsMessages:t,visible:i,analysisViewData:s}=this;return{labelAnchors:s.labelAnchors,effectiveDisplayUnits:s.effectiveDisplayUnits,messages:e,unitsMessages:t,result:s.result,visible:i&&!!s.result}},e=>this._updateLabels(e)),m(()=>this.view.state.camera,e=>this._updateProjectionLineOcclusion(e),d),t(()=>this._updateMessageBundle())]),this._updateMessageBundle()}destroy(){this._elevationAlignedGeometry=a(this._elevationAlignedGeometry),this._targetGeometry=a(this._targetGeometry),this._cutProjectionLines=a(this._cutProjectionLines),this._occludedCutProjectionLines=a(this._occludedCutProjectionLines),this._fillProjectionLines=a(this._fillProjectionLines),this._occludedFillProjectionLines=a(this._occludedFillProjectionLines),this._cutVolumeLabel=a(this._cutVolumeLabel),this._fillVolumeLabel=a(this._fillVolumeLabel),this._cutFillRenderNode.destroy()}_updateProjectionLines(e,t,i){if(this._cutProjectionLines.visible=i,this._occludedCutProjectionLines.visible=i,this._fillProjectionLines.visible=i,this._occludedFillProjectionLines.visible=i,!e||!t)return;const{renderCoordsHelper:s}=this.view,o=[],r=[],n=[],a=[],c=[],u=e.spatialReference;for(let m=0;m<e.rings.length;m++){const i=e.rings[m],d=i.length>1&&l(i[0],i[i.length-1]),h=i.length-(d?1:0),p=[];for(let e=0;e<h;++e){const o=i[e],r=f(C(),o[0],o[1],o[2]);s.toRenderCoords(r,u,r);const l=t.rings[m][e],n=f(C(),l[0],l[1],l[2]);s.toRenderCoords(n,u,n);const a=new D(r,n);p.push(a)}e.isClockwise(i)||p.reverse();const g=this.view.state.camera;for(let s=0;s<p.length;++s){const i=p[s],l=p[0===s?p.length-1:s-1],u=p[s===p.length-1?0:s+1],d=e.rings[m][s],h=t.rings[m][s],y=d[2]>h[2],_=new k(i,l,u,y);o.push(_),_.updateOccluded(g);const f=_.isOccluded;y?(f?n:r).push(i):(f?c:a).push(i)}}this._projectionLines=o,this._cutProjectionLines.setGeometryFromSegments(r),this._occludedCutProjectionLines.setGeometryFromSegments(n),this._fillProjectionLines.setGeometryFromSegments(a),this._occludedFillProjectionLines.setGeometryFromSegments(c)}_updateProjectionLineOcclusion(e){const t=[],i=[],s=[],o=[];let r=!1,l=!1;for(const n of this._projectionLines){n.updateOccluded(e)&&(r||=n.isCut,l||=!n.isCut);const a=n.isOccluded;(n.isCut?a?i:t:a?o:s).push(n.segment)}l&&(this._fillProjectionLines.setGeometryFromSegments(s),this._occludedFillProjectionLines.setGeometryFromSegments(o)),r&&(this._cutProjectionLines.setGeometryFromSegments(t),this._occludedCutProjectionLines.setGeometryFromSegments(i))}_updateColors(e,t,i){const{geometryOutlineColor:s,cutColor:r,fillColor:l,cutColorMuted:n,fillColorMuted:a,cutProjectionLineColor:c,fillProjectionLineColor:u}=o;if(this._cutFillRenderNode.cutColor=i?r:n,this._cutFillRenderNode.fillColor=i?l:a,e){const e=t.toUnitRGBA();this._targetGeometry.color=e,this._cutProjectionLines.color=e,this._occludedCutProjectionLines.color=e,this._fillProjectionLines.color=e,this._occludedFillProjectionLines.color=e,this._cutFillRenderNode.borderColor=t}else{this._targetGeometry.color=s.toUnitRGBA();const e=(i?c:n).toUnitRGBA();this._cutProjectionLines.color=e,this._occludedCutProjectionLines.color=e;const t=(i?u:a).toUnitRGBA();this._fillProjectionLines.color=t,this._occludedFillProjectionLines.color=t,this._cutFillRenderNode.borderColor=s}}_updateLabels(e){const{effectiveDisplayUnits:t,labelAnchors:s,messages:o,unitsMessages:r,result:l,visible:n}=e;if(this._cutVolumeLabel.visible=n,this._fillVolumeLabel.visible=n,this._cutVolumeLabel.geometry=s?{type:"point",point:s.cut}:null,this._fillVolumeLabel.geometry=s?{type:"point",point:s.fill}:null,null==l||null==o||null==r)return this._cutVolumeLabel.text="-",void(this._fillVolumeLabel.text="-");const a=t.volume,c=i(o.labels.cut,{volume:I(r,l.cutVolume,a)}),u=i(o.labels.fill,{volume:I(r,l.fillVolume,a)});this._cutVolumeLabel.text=c,this._fillVolumeLabel.text=u}_updateCutFillVisibility(e){e?this._cutFillRenderNode.enable():this._cutFillRenderNode.disable()}_updateCutFillGeometry(){const{renderCoordsHelper:e}=this.view,{targetGeometry:t}=this.analysisViewData,{cut:i,fill:s}=this._extrusionHeights;if(!t?.extent)return;const{center:o}=t.extent,r=w(o.x,o.y,0),l=C();e.toRenderCoords(r,t.spatialReference,l);const n=this._getExtrudedVolumes(t,i,r,l),a=this._getExtrudedVolumes(t,s,r,l);this._cutFillRenderNode.updateGeometries(n,a,l)}_getExtrudedVolumes(e,t,i,s){const{renderCoordsHelper:o,spatialReference:r,elevationProvider:l}=this.view,n=C(),a=1===o.viewingMode;o.worldUpAtPosition(s,n);const c=E(e,l,o,this._elevationContext),{polygons:u,mapPositions:m,position:d}=c;return u.map(e=>{const s=e.count,l=y(e.mapPositions,e.holeIndices,3),c=l.length,u=6*s,h=P(u+c),p=P(c),g=V(3*u),f=V(3*u);S(d,m,l,e,g,null,f,null,h,p,t,n,a);const v=_(),j=_();if(G(r,i,v,o.spatialReference),j[12]=-v[12],j[13]=-v[13],j[14]=-v[14],F(g,g,j),"stockpile"===this.analysis.measureType)for(let t=0;t<f.length;t+=3)f[t]=n[0],f[t+1]=n[1],f[t+2]=n[2];return new N(g,p,h,f)})}async _updateMessageBundle(){this.loadingMessages=!0;try{this.unitsMessages=await s("esri/core/t9n/Units"),this.messages=await s("esri/views/3d/analysis/VolumeMeasurement/t9n/VolumeMeasurementAnalysis")}finally{this.loadingMessages=!1}}};function I(e,t,i){if(!t||!e)return null;const s=h(t.value,t.unit,i),o=u(s);return c(e,t,s,o)}e([p({constructOnly:!0})],T.prototype,"view",void 0),e([p({constructOnly:!0})],T.prototype,"analysis",void 0),e([p({constructOnly:!0})],T.prototype,"analysisViewData",void 0),e([p()],T.prototype,"unitsMessages",void 0),e([p()],T.prototype,"messages",void 0),e([p()],T.prototype,"loadingMessages",void 0),e([p({readOnly:!0})],T.prototype,"visible",null),e([p()],T.prototype,"updating",null),e([p()],T.prototype,"hasUnsupportedError",null),e([p()],T.prototype,"_extrusionHeights",null),T=e([g("esri.views.3d.analysis.VolumeMeasurement.VolumeMeasurementCutFillVisualization")],T);class k{constructor(e,t,i,s){this.segment=e,this.previous=t,this.next=i,this.isCut=s,this._isOccluded=!1,this._n1=C(),this._n2=C();const o=v(z,j(z,e.endRenderSpace,e.startRenderSpace));v(this._n1,b(this._n1,o,v(W,j(W,t.startRenderSpace,e.startRenderSpace)))),v(this._n2,b(this._n2,o,v(W,j(W,e.startRenderSpace,i.startRenderSpace)))),this._isConvex=n.normalize(R(this._n1,this._n2,o))<0}get isOccluded(){return this._isOccluded}updateOccluded(e){j(z,this.segment.startRenderSpace,e.eye);const t=L(this._n1,z)<0,i=L(this._n2,z)<0,s=this._isOccluded;return this._isOccluded=this._isConvex?t&&i:t||i,this._isOccluded!==s}}const z=C(),W=C();export{T as VolumeMeasurementCutFillVisualization};