@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 6 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{watch as e}from"../../../../core/reactiveUtils.js";import{createScreenPointArray as t,castScreenPointArray as r}from"../../../../core/screenUtils.js";import{normalize as i,subtract as s,scale as a,set as o,add as c}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{q as d,c as h,n as l,d as m,f as u}from"../../../../chunks/vec32.js";import{create as p,fromValues as _}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{a as f,c as g}from"../../../../chunks/vec42.js";import{fromValues as b}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{makeDehydratedPoint as y}from"../../../../layers/graphics/dehydratedPoint.js";import{EngineVisualElement as j}from"./EngineVisualElement.js";import{drapedZ as D}from"../../terrain/OverlayRenderer.js";import{createPolylineGeometry as O}from"../../webgl-engine/lib/GeometryUtil.js";import{RenderOccludedFlag as w}from"../../webgl-engine/lib/Material.js";import{RenderGeometry as G}from"../../webgl-engine/lib/RenderGeometry.js";import{VertexAttribute as R}from"../../webgl-engine/lib/VertexAttribute.js";import{RibbonLineMaterial as x}from"../../webgl-engine/materials/RibbonLineMaterial.js";class v extends j{constructor(e){super(e),this._location=p(),this._direction=_(1,0,0),this._width=1,this._offset=1,this._length=18,this._color=b(1,0,1,1),this._renderOccluded=w.OccludeAndTransparent,this.applyProperties(e)}createObject3DResourceFactory(e){return{view:e,createResources:e=>this._createObject3DResources(e),destroyResources:M,recreateGeometry:(e,t)=>this._recreateObject3DGeometry(e,t),cameraChanged:()=>this._updateGeometry(),forEachMaterial:(e,t)=>t(e.material)}}createDrapedResourceFactory(e){return{view:e,createResources:()=>this._createDrapedResources(),destroyResources:A,recreateGeometry:e=>this._recreateDrapedGeometry(e),forEachMaterial:(e,t)=>t(e.material)}}get location(){return this._location}set location(e){d(this._location,e)||(h(this._location,e),this._updateGeometry())}get direction(){return this._direction}set direction(e){d(this._direction,e)||(h(this._direction,e),this._updateGeometry())}setDirectionFromPoints(e,t){l(this._direction,m(this._direction,t,e)),this._updateGeometry()}get width(){return this._width}set width(e){e!==this._width&&(this._width=e,this._updateMaterial())}get offset(){return this._offset}set offset(e){e!==this._offset&&(this._offset=e,this._updateGeometry())}get length(){return this._length}set length(e){e!==this._length&&(this._length=e,this._updateGeometry())}get color(){return this._color}set color(e){f(e,this._color)||(g(this._color,e),this._updateMaterial())}get renderOccluded(){return this._renderOccluded}set renderOccluded(e){e!==this._renderOccluded&&(this._renderOccluded=e,this._updateMaterial())}get isDecoration(){return this._isDecoration}set isDecoration(e){this._isDecoration=e,this._updateMaterial()}_createObject3DResources(e){const t=new x(this.materialParameters),r=new Array;return this._createObject3DGeometry(t,e,r),{material:t,geometries:r}}_recreateObject3DGeometry(e,t){e.geometries.length=0,this._createObject3DGeometry(e.material,t,e.geometries)}_createObject3DGeometry(e,t,r){const[i,s]=P(e);t.addGeometry(i),t.addGeometry(s),r.push(i),r.push(s),this._updateVerticesObject3D(t)}_createDrapedResources(){const t=new x(this.materialParameters),r=e((()=>this.view.state.contentPixelRatio),(()=>this.drapedResources.recreateGeometry()));return{material:t,geometries:this._createDrapedGeometry(t),pixelRatioHandle:r}}_recreateDrapedGeometry(e){e.geometries=this._createDrapedGeometry(e.material)}_createDrapedGeometry(e){const t=P(e);return this._updateVerticesDraped(t),t.map((e=>new G(e)))}_updateMaterial(){const{materialParameters:e}=this;this.object3dResources.resources?.material.setParameters(e),this.drapedResources.resources?.material.setParameters(e)}get materialParameters(){return{width:this._width,color:this._color,renderOccluded:this._renderOccluded,isDecoration:this.isDecoration}}_updateGeometry(){if(this.isDraped)this.drapedResources.recreateGeometry();else{const e=this.object3dResources.object;e&&this._updateVerticesObject3D(e)}}_updateVerticesObject3D(e){const t=this.view.state.camera;t.projectToScreen(this.location,U),u(I,this.location,this.direction),t.projectToScreen(I,E),i(E,s(E,E,U)),this._updateVertexAttributesObject3D(t,e,0,U,E,1),this._updateVertexAttributesObject3D(t,e,1,U,E,-1)}_updateVertexAttributesObject3D(e,t,i,s,a,o){const c=t.geometries[i],n=c.getMutableAttribute(R.POSITION)?.data;if(!n)return;const{start:d,end:h}=V(a,s,o,this.offset,this.width,this.length);e.unprojectFromScreen(r(d),I),n[0]=I[0],n[1]=I[1],n[2]=I[2],e.unprojectFromScreen(r(h),I),n[3]=I[0],n[4]=I[1],n[5]=I[2],t.geometryVertexAttributeUpdated(c,R.POSITION)}_updateVerticesDraped(e){const{view:{basemapTerrain:{overlayManager:t},state:{contentPixelRatio:r}}}=this,{location:i,width:s,length:a,offset:o}=this,c=N;c.spatialReference=t.renderer.spatialReference,c.x=i[0],c.y=i[1];const n=this.view.overlayPixelSizeInMapUnits(c)*r,d=s*n,h=a*n,l=o*n;this._updateVertexAttributesDraped(e[0],d,h,l,-1),this._updateVertexAttributesDraped(e[1],d,h,l,1)}_updateVertexAttributesDraped(e,t,r,i,s){const a=e.getMutableAttribute(R.POSITION)?.data;if(!a)return;const{location:o,direction:c}=this,{start:n,end:d}=V(c,o,s,i,t,r);a[0]=n[0],a[1]=n[1],a[2]=D,a[3]=d[0],a[4]=d[1],a[5]=D,e.invalidateBoundingInfo()}}function P(e){return[O(e,[p(),p()]),O(e,[p(),p()])]}function V(e,t,r,i,s,n){const d=a(S,o(S,e[1]*r,e[0]*-r),i+s/2),h=c(T,c(T,c(T,t,a(T,e,n/2)),d),d);return{start:h,end:c(F,h,a(F,e,-n))}}function M(e){e.geometries.length=0}function A(e){e.pixelRatioHandle.remove(),e.geometries=[]}const I=p(),S=n(),T=n(),F=n(),U=t(),E=t(),N=y(0,0,void 0,null);export{v as ParallelLineVisualElement};