UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 4.43 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{colorVectorEquals as e}from"../../../../core/colorUtils.js";import t from"../../../../core/Handles.js";import{destroyMaybe as r}from"../../../../core/maybe.js";import{watch as s}from"../../../../core/reactiveUtils.js";import{create as o}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{c as i,d as a,a as n,h as l,H as h}from"../../../../chunks/vec32.js";import{create as c}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{c as d}from"../../../../chunks/vec42.js";import{create as m}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{sv3d as _}from"../../../../geometry/support/vectorStacks.js";import{Object3DVisualElement as p}from"./Object3DVisualElement.js";import{headingTiltToDirectionUp as g}from"../../support/cameraUtils.js";import{createDirectionUp as u}from"../../support/cameraUtilsInternal.js";import{createPolylineGeometry as w}from"../../webgl-engine/lib/GeometryUtil.js";import{RenderOccludedFlag as f}from"../../webgl-engine/lib/Material.js";import{MeasurementArrowMaterial as C}from"../../webgl-engine/materials/MeasurementArrowMaterial.js";class y extends p{constructor(e){super(e),this._arrowWidth=16,this._arrowSubdivisions=128,this._origin=c(),this._originTransform=o(),this._arrowCenter=c(),this._renderOccluded=f.OccludeAndTransparent,this._geometry=null,this._stripeLength=1,this._stripesEnabled=!0,this._color=m(),this._contrastColor=m(),this.applyProperties(e)}get renderOccluded(){return this._renderOccluded}set renderOccluded(e){e!==this._renderOccluded&&(this._renderOccluded=e,this._arrowMaterial?.setParameters({renderOccluded:e}))}get geometry(){return this._geometry}set geometry(e){this._geometry=e,this._geometryChanged()}get stripeLength(){return this._stripeLength}set stripeLength(e){this._stripeLength=e,this.attached&&this._arrowMaterial.setParameters({stripeLength:this._stripeLength})}get stripesEnabled(){return this._stripesEnabled}set stripesEnabled(e){if(this._stripesEnabled=e,this.attached){const e=this._stripesEnabled?this._contrastColor:this._color;this._arrowMaterial.setParameters({stripeEvenColor:e})}}get color(){return this._color}set color(t){e(t,this._color)||(d(this._color,t),this._updateArrowColor())}get contrastColor(){return this._contrastColor}set contrastColor(t){e(t,this._color)||(d(this._contrastColor,t),this._updateArrowColor())}createExternalResources(){const e=this._color,r=this._contrastColor,o=this._stripesEnabled?r:e;this._arrowMaterial=new C({outlineColor:e,stripeEvenColor:o,stripeOddColor:e,renderOccluded:this.renderOccluded,polygonOffset:!0,isDecoration:this.isDecoration}),this._handles=new t,this._handles.add(s((()=>this.view.state.camera),(()=>{this._viewChanged()})))}destroyExternalResources(){this._arrowMaterial=null,this._handles=r(this._handles)}forEachMaterial(e){e(this._arrowMaterial)}createGeometries(e){if(null==this._geometry?.startRenderSpace||null==this._geometry.endRenderSpace)return;const t=this._createArrowGeometry(this._geometry.startRenderSpace,this._geometry.endRenderSpace,this._origin,this._geometry);t.transformation=this._originTransform,e.addGeometry(t),this._viewChanged()}_createArrowGeometry(e,t,r,s){const o=this.view,n=o.renderCoordsHelper,l=[],h=[],c=(e,t)=>{const s=_.get();a(s,e,r),l.push(s),h.push(t)};if("euclidean"===s.type){s.eval(.5,this._arrowCenter);const r=_.get();if(n.worldUpAtPosition(this._arrowCenter,r),v(e,t,r)){const{heading:t,tilt:s}=o.camera,{direction:a}=g(o,e,t,s,j);i(r,a)}c(e,r),c(t,r)}else{s.eval(.5,this._arrowCenter);const e=this._arrowSubdivisions+1&-2;for(let t=0;t<e;++t){const r=t/(e-1),o=_.get(),i=_.get();s.eval(r,o),n.worldUpAtPosition(o,i),c(o,i)}}return w(this._arrowMaterial,l,h)}_geometryChanged(){this.recreateGeometry()}_viewChanged(){if(this.view.ready&&this.attached&&null!=this._geometry){const e=this.view.state.camera.computeScreenPixelSizeAt(this._arrowCenter);this._arrowMaterial.setParameters({width:this._arrowWidth*e})}}_updateArrowColor(){if(!this.attached)return;const e=this._color,t=this._contrastColor,r=this._stripesEnabled?t:e,s=e,o=e;this._arrowMaterial.setParameters({stripeEvenColor:r,outlineColor:s,stripeOddColor:o})}}function v(e,t,r){const s=n(b,t,e),o=l(b,s,r);return 0===h(o)}const b=c(),j=u();export{y as MeasurementArrowVisualElement};