UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 11.5 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 e}from"../../../../../chunks/tslib.es6.js";import"../../../../../intl.js";import t from"../../../../../core/Accessor.js";import{unitRGBAFromColor as i,multiplyOpacityToUnitRGBA as s,getContrast as r,BrightnessThreshold as n,multiplyOpacity as a}from"../../../../../core/colorUtils.js";import"../../../../../core/has.js";import{nextHighestPowerOfTen as o}from"../../../../../core/mathUtils.js";import{destroyMaybe as l}from"../../../../../core/maybe.js";import{formatDecimal as h}from"../../../../../core/quantityFormatUtils.js";import{watch as c,syncAndInitial as m,initial as d}from"../../../../../core/reactiveUtils.js";import{lengthUnitFromSpatialReference as p,convertUnit as u,adaptiveAreaUnit as g}from"../../../../../core/unitUtils.js";import{property as _}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/Logger.js";import"../../../../../core/RandomLCG.js";import{subclass as v}from"../../../../../core/accessorSupport/decorators/subclass.js";import{fromTranslation as L}from"../../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as b}from"../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{d as f}from"../../../../../chunks/vec32.js";import{create as w}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{toPreferredAreaUnit as S,preferredLengthUnit as y}from"./utils.js";import{LabelVisualElement as j}from"../../../interactive/visualElements/LabelVisualElement.js";import{LineVisualElement as C}from"../../../interactive/visualElements/LineVisualElement.js";import{MeasurementAreaVisualElement as D}from"../../../interactive/visualElements/MeasurementAreaVisualElement.js";import{GeodesicSegment as A,EuclideanSegment as M}from"../../../interactive/visualElements/support/Segment.js";import{midpoint3d as V}from"../../../support/mathUtils.js";import{RenderOccludedFlag as x}from"../../../webgl-engine/lib/Material.js";import{createStipplePatternSimple as P}from"../../../webgl-engine/materials/lineStippleUtils.js";import{onLocaleChange as O}from"../../../../../intl/locale.js";import{fetchMessageBundle as R}from"../../../../../intl/messages.js";let F=class extends t{get _parameters(){const{accentColor:e,textColor:t}=this.view.effectiveTheme,o=i(e),l=s(e,.5),h=s(r(e),.5),c=r(t,n.Low);return{accentColor:o,transparentAccentColor:l,transparentContrastColor:h,intersectingLineColor:[1,.2,0,1],textColor:t,textBackgroundColor:a(c,.6),textCalloutColor:a(c,.5),pathLineWidth:3,perimeterLineWidth:2,projectionLineWidth:2,projectionLineStippleSize:5,labelDistance:25}}get visible(){return this.analysisViewData.visible}get _renderUnits(){const e=this.view.renderCoordsHelper.spatialReference;return p(e)??"meters"}get testData(){}constructor(e){super(e),this._path=null,this._intersectedPath=null,this._perimeter=null,this._intersectedPerimeter=null,this._projectionLines=null,this._measurementArea=null,this._areaLabel=null,this._perimeterLengthLabel=null,this._pathSegments=[],this._perimeterSegments=[],this._origin=w(),this._originTransform=b(),this.messages=null,this.viewData=W,this.areaLabel=null,this.perimeterLengthLabel=null,this.loadingMessages=!0}initialize(){const{analysisViewData:e,_parameters:t,view:i}=this;this._path=new C({view:i,attached:!0,width:t.pathLineWidth,polygonOffset:!0,renderOccluded:x.OccludeAndTransparent,isDecoration:!0}),this._intersectedPath=new C({view:i,attached:!0,width:t.pathLineWidth,polygonOffset:!0,renderOccluded:x.OccludeAndTransparent,isDecoration:!0}),this._perimeter=new C({view:i,attached:!0,width:t.perimeterLineWidth,polygonOffset:!0,renderOccluded:x.OccludeAndTransparent,isDecoration:!0}),this._intersectedPerimeter=new C({view:i,attached:!0,width:t.perimeterLineWidth,color:t.intersectingLineColor,polygonOffset:!0,renderOccluded:x.OccludeAndTransparent,isDecoration:!0}),this._projectionLines=new C({view:i,attached:!0,width:t.projectionLineWidth,stipplePattern:P(t.projectionLineStippleSize),polygonOffset:!0,renderOccluded:x.OccludeAndTransparent,isDecoration:!0}),this._measurementArea=new D({view:i,attached:!0,isDecoration:!0});const s={attached:!0,view:i,isDecoration:!0};this._areaLabel=new j({...s,fontSize:k.Large}),this._perimeterLengthLabel=new j({...s,fontSize:k.Small}),this.addHandles([c((()=>[e.mode,this.visible,e.unit,e.measurementData,e.stagedPoint]),(()=>this._update()),m),c((()=>i.state?.camera),(()=>this._updateLabels()),m),O((()=>this._updateMessageBundle())),c((()=>this._parameters),(({accentColor:e,transparentAccentColor:t,transparentContrastColor:i,textColor:s,textBackgroundColor:r,textCalloutColor:n})=>{const{_path:a,_intersectedPath:o,_perimeter:l,_projectionLines:h,_measurementArea:c,_areaLabel:m,_perimeterLengthLabel:d}=this;a.color=e,o.color=e,l.color=e,h.color=e,c.color1=t,c.color2=i,m.textColor=s,m.backgroundColor=r,m.calloutColor=n,d.textColor=s,d.backgroundColor=r,d.calloutColor=n}),d)]),this._updateMessageBundle()}destroy(){this._measurementArea=l(this._measurementArea),this._path=l(this._path),this._intersectedPath=l(this._intersectedPath),this._perimeter=l(this._perimeter),this._intersectedPerimeter=l(this._intersectedPerimeter),this._areaLabel=l(this._areaLabel),this._perimeterLengthLabel=l(this._perimeterLengthLabel),this._projectionLines=l(this._projectionLines),this.set("view",null)}_update(){if(this.destroyed||!this.view.ready||!this.view.renderCoordsHelper)return;const{analysisViewData:{measurementData:e},analysisViewData:t}=this;null!=e&&(this._updateViewData(e,t.path),this._updateOrigin(),this._updatePathSegments(),this._updatePerimeterSegments(),this._updateArea(),this._updateProjectionLines(),this._updateLabels())}_updateViewData(e,t){const i=e.validMeasurement,s="geodesic"===e.actualMeasurementMode,r=s?e.geodesicArea:e.area;let n=1;if(r){const e=S(r,this.analysisViewData.unit);n=o(Math.sqrt(e.value)/Math.sqrt(300)),n*=Math.sqrt(u(1,e.unit,"square-meters")),n=u(n,"meters",this._renderUnits)}const a={validMeasurement:i,numVertices:e.numVertices,hasStagedVertex:e.hasStagedVertex,path:t,mode:e.actualMeasurementMode,positionsRender:e.positionsRender,positionsFittedWorld:e.positionsFittedWorld,positionsFittedRender:e.positionsFittedRender,intersectingSegments:s?e.geodesicIntersectingSegments:e.intersectingSegments,triangleIndices:s?e.geodesicTriangleIndices:e.triangleIndices,areaCentroid:s?e.geodesicAreaCentroidRenderCoords:e.areaCentroidRenderCoords,perimeterLengthLabelSegmentIndex:0,area:s?e.geodesicArea:e.area,pathLength:s?e.geodesicPathLength:e.pathLength,perimeterLength:e.perimeterLength,checkerSize:n};this._set("viewData",a)}_updateOrigin(){const e=this.viewData;V(e.positionsRender,this._origin),L(this._originTransform,this._origin),this._measurementArea.transform=this._originTransform,this._projectionLines.transform=this._originTransform}_createSegments(e){const t=this.viewData,i=this.view.renderCoordsHelper.spatialReference,s=t.mode,r=[],n=[],a=[],o=t.numVertices,l=t.validMeasurement?o:o-1;for(let c=0;c<l;++c){const l=t[e][c],h=t[e][(c+1)%o];let m=null;switch(s){case"euclidean":m=new M(l,h);break;case"geodesic":m=new A(l,h,i)}t.intersectingSegments.has(c)?a.push(m):n.push(m),r.push(m)}let h=null;return t.validMeasurement&&t.hasStagedVertex&&l>=2?h=r[r.length-2]:t.hasStagedVertex&&l>=1&&(h=r[r.length-1]),{all:r,nonIntersecting:n,intersecting:a,stagedSegment:h}}_updatePathSegments(){const{visible:e}=this,t=this._createSegments("positionsRender");this._path.setGeometryFromSegments(t.nonIntersecting,this._origin),this._path.visible=e,this._intersectedPath.setGeometryFromSegments(t.intersecting,this._origin),this._intersectedPath.visible=e,this._pathSegments=t.all}_updatePerimeterSegments(){const e=this.visible&&"euclidean"===this.viewData.mode&&this.viewData.path.numVertices>2,t=this._createSegments("positionsFittedRender");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.positionsFittedWorld,position:e.positionsFittedRender,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.mode,s=e.numVertices;if(s>0&&e.validMeasurement&&"euclidean"===i){const i=[];for(let t=0;t<s;++t){const s=w();f(s,e.positionsRender[t],this._origin);const r=w();f(r,e.positionsFittedRender[t],this._origin),i.push([s,r])}this._projectionLines.geometry=i,this._projectionLines.visible=t}else this._projectionLines.geometry=null,this._projectionLines.visible=!1}_updateLabels(){if(this.destroyed)return;const{viewData:e}=this,{area:t,path:i}=e;if(!i)return;const s=this.visible,r=this._areaLabel,n=this._perimeterLengthLabel,a=e.validMeasurement;r.visible=!0,n.visible=!0;let o=!1;const l=z(this.messages,t,this.analysisViewData.unit);if(null!=l&&s&&(r.geometry={type:"point",point:e.areaCentroid},r.text=l,o=e.validMeasurement&&0===e.intersectingSegments.size),this._set("areaLabel",l),s&&a&&0===e.intersectingSegments.size){const t="geodesic"===e.mode,i=t?e.pathLength:e.perimeterLength,s=I(this.messages,i,this.analysisViewData.unit);this._set("perimeterLengthLabel",s),n.distance=this._parameters.labelDistance,n.anchor="top",n.text=s;let r=!0;for(let a=0;a<e.numVertices;++a){const i=(e.perimeterLengthLabelSegmentIndex+a)%e.numVertices,s=t?this._pathSegments[i]:this._perimeterSegments[i];if(r=!0,n.geometry={type:"segment",segment:s,sampleLocation:"center"},!n.overlaps(this._areaLabel))break;r=!1}n.visible=r}else n.visible=!1;r.visible=o}_updateMessageBundle(){this.loadingMessages=!0,R("esri/core/t9n/Units").then((e=>{this.messages=e,this.view&&this._update()})).finally((()=>{this.loadingMessages=!1}))}};function z(e,t,i){return e&&t&&h(e,t,g(t.value,t.unit,i))}function I(e,t,i){return e&&t&&h(e,t,y(t,i))}var k;e([_()],F.prototype,"_parameters",null),e([_()],F.prototype,"view",void 0),e([_()],F.prototype,"messages",void 0),e([_()],F.prototype,"analysis",void 0),e([_()],F.prototype,"viewData",void 0),e([_()],F.prototype,"analysisViewData",void 0),e([_({readOnly:!0})],F.prototype,"areaLabel",void 0),e([_({readOnly:!0})],F.prototype,"perimeterLengthLabel",void 0),e([_()],F.prototype,"loadingMessages",void 0),e([_()],F.prototype,"visible",null),e([_()],F.prototype,"_renderUnits",null),F=e([v("esri.views.3d.analysis.AreaMeasurement.support.AreaMeasurementVisualization")],F),function(e){e[e.Small=12]="Small",e[e.Large=16]="Large"}(k||(k={}));const W={validMeasurement:!1,numVertices:0,hasStagedVertex:!1,path:null,mode:null,positionsRender:null,positionsFittedWorld:null,positionsFittedRender:null,intersectingSegments:null,triangleIndices:null,areaCentroid:null,perimeterLengthLabelSegmentIndex:null,checkerSize:null,area:null,pathLength:null,perimeterLength:null};export{F as AreaMeasurementVisualization};