UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) • 12.9 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{has}from"../../../../applications/Components/baUtils.js";import e from"../../../../core/Error.js";import{px2pt as t,pt2px as r}from"../../../../core/screenUtils.js";import{fromValues as i}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{copy as a}from"../../../../core/libs/gl-matrix-2/math/vec4.js";import{ZEROS as s,clone as o,ones as l}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import n from"../../../../geometry/Extent.js";import c from"../../../../geometry/Polygon.js";import{create as p,fromBuffer as h,intersectsClippingArea as m,empty as u,expandWithAABB as _,expandWithBuffer as y}from"../../../../geometry/support/aaBoundingBox.js";import{getDriverAxisSizeValueAny as d}from"../../../../renderers/support/renderingInfoUtils.js";import{sharedGeometryElevationAligner as g}from"./ElevationAligners.js";import{elevationModeChangeUpdateType as f,needsElevationUpdates2D as b}from"./elevationAlignmentUtils.js";import{Graphics3DDrapedGraphicLayer as v}from"./Graphics3DDrapedGraphicLayer.js";import{Graphics3DObject3DGraphicLayer as C}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DSymbolLayer as P,nanFallbackColor as M}from"./Graphics3DSymbolLayer.js";import{parseCapType as k,parseLineMarkerStyle as w}from"./lineUtils.js";import{initFastSymbolUpdatesState as S,updateFastSymbolUpdatesState as L,getAttributeValue as x,getSizeAttributeValue as z,ConvertOptions as U}from"../support/FastSymbolUpdates.js";import{debugFlags as j}from"../../support/debugFlags.js";import{createGeometry as V}from"../../support/engineContent/line.js";import{geometryToRenderInfo as O,geometryToRenderInfoDraped as A}from"../../support/renderInfoUtils/line.js";import{Object3D as E}from"../../webgl-engine/lib/Object3D.js";import{RenderGeometry as G}from"../../webgl-engine/lib/RenderGeometry.js";import{LineMarkerMaterial as D}from"../../webgl-engine/materials/LineMarkerMaterial.js";import{getStipplePatternForLinePattern as F}from"../../webgl-engine/materials/lineStippleUtils.js";import{RibbonLineMaterial as R}from"../../webgl-engine/materials/RibbonLineMaterial.js";const I=["polyline","polygon","extent"];class W extends P{static{this.elevationModeChangeTypes={definedChanged:2,staysOnTheGround:0,onTheGroundChanged:2}}constructor(e,t,r,i){super(e,t,r,i,T(t))}async doLoad(){this._fastUpdates=S(this._context.renderer,this._fastVisualVariableConvertOptions());const r=!0;if(this._fastMarkerUpdates=S(this._context.renderer,this._fastVisualVariableConvertOptions(r)),!this._drivenProperties.size){if((null!=this.symbolLayer.size?this.symbolLayer.size:t(1))<0)throw new e("graphics3dlinesymbollayer:invalid-size","Symbol sizes may not be negative values")}}_getMaterialParameters(e,t){const r=this._screenSizePerspective,{symbolLayer:i}=this,a={...this._getMaterialColorParameters(t),width:this._computeMaterialWidth(i?.size),hasPolygonOffset:!0,join:i.join||"miter",cap:k(i.cap||"butt"),hasSlicePlane:this._context.slicePlaneEnabled,isClosed:e,stipplePattern:F(i.pattern??i.imagePattern),emissiveStrength:this._emissiveStrength,screenSizePerspective:r};return 4===t&&this._fastMarkerUpdates?.visualVariables?{...a,...this._fastMarkerUpdates.materialParameters}:this._fastUpdates?.visualVariables?{...a,...this._fastUpdates.materialParameters}:a}_getMaterialColorParameters(e){const t=4===e,r=this._getCombinedOpacityAndColor(t&&this._markerColor||this._materialColor);return this._patternHidesLine&&!t&&(r[3]=0),{color:r}}get _materialColor(){return this.symbolLayer.material?.color}get _emissiveStrength(){if(has("enable-feature:emissive-on-none-volumetrics")){const e=this.symbolLayer.material?.emissive;return("color"===e?.source?e?.strength:void 0)??0}return 0}get _markerColor(){return this.symbolLayer.marker?.color}get _lineMaterial(){return null==this._materials[0]&&(this._materials[0]=new R(this._getMaterialParameters(!1,0),this.view.state.isGlobal)),this._materials[0]}get _ringMaterial(){return null==this._materials[1]&&(this._materials[1]=new R(this._getMaterialParameters(!0,1),this.view.state.isGlobal)),this._materials[1]}get _wireframeLineMaterial(){return null==this._materials[2]&&(this._materials[2]=new R({...this._getMaterialParameters(!1,2),wireframe:!0},this.view.state.isGlobal)),this._materials[2]}get _wireframeRingMaterial(){return null==this._materials[3]&&(this._materials[3]=new R({...this._getMaterialParameters(!0,3),wireframe:!0},this.view.state.isGlobal)),this._materials[3]}get _markerMaterial(){return null==this._materials[4]&&null!=this.symbolLayer.marker&&(this._materials[4]=new D({...this._getMaterialParameters(!1,4),placement:this.symbolLayer.marker.placement,markerPrimitive:w(this.symbolLayer.marker.style)},this.view.state.isGlobal)),this._materials[4]}_getDrivenSize(e){if(this._drivenProperties.size){const t=e.size;return null!=t?r(d(t.output)):this._getFallbackSize()}return 1}_getDrivenColor({color:e,opacity:t}){const r=l();return this._drivenProperties.color&&(a(r,e?.output??this._getFallbackOpacityAndColor(s)),null==t)||this._drivenProperties.opacity&&(e||this._materialColor)&&(r[3]=t?.output??this._getFallbackOpacity()),r}_getDrivenMarkerColor({color:e,opacity:t}){const r=l();return this._drivenProperties.color&&(a(r,e?.output??this._getFallbackMarkerOpacityAndColor(s)),null==t)||this._drivenProperties.opacity&&(e||this._markerColor||this._materialColor)&&(r[3]=t?.output??this._getFallbackMarkerOpacity()),r}createGraphics3DGraphic(e){const t=e.graphic;if(!this._validateGeometry(t.geometry,I,this.symbolLayer.type))return null;const r=this.createElevationContextForGraphic(t);return this.ensureDrapedStatus("on-the-ground"===r.mode),this.draped?this._createAsOverlay(e):this._createAs3DShape(e,r,t.uid)}applyRendererDiff(e,t){for(const r in e.diff){if("visualVariables"!==r)return 0;{const e=this._fastUpdates;if(!L(e,t,this._fastVisualVariableConvertOptions()))return 0;for(const t of this._materials)t instanceof R&&t.setParameters(e.materialParameters);const r=this._fastMarkerUpdates,i=!0;if(!L(r,t,this._fastVisualVariableConvertOptions(i)))return 0;for(const t of this._materials)t instanceof D&&t.setParameters(r.materialParameters)}}return 2}prepareSymbolLayerPatch(e){if("partial"!==e.diff.type)return;const t=e.diff.diff,r={};"complete"===t.size?.type&&(r.width=this._computeMaterialWidth(t.size.newValue),delete t.size),"complete"===t.cap?.type&&(r.cap=k(t.cap.newValue??"butt"),delete t.cap);const i=this._prepareMarkerPatch(e,t);this._prepareMaterialPatch(e,t,i),e.symbolLayerStatePatches.push(()=>{for(const e of this._materials)e?.setParameters(r)})}layerOpacityChanged(){for(let e=0;e<5;e++)this._materials[e]?.setParameters(this._getMaterialColorParameters(e))}get _screenSizePerspective(){return!this.draped&&this._context.screenSizePerspectiveEnabled?this.view.screenSizePerspective.parameters:null}layerScreenSizePerspectiveChanged(){const e=this._screenSizePerspective;for(const t of this._materials)t?.setParameters({screenSizePerspective:e})}layerElevationInfoChanged(e,t,r){const i=this._elevationContext.mode,a=f(W.elevationModeChangeTypes,r,i);if(1!==a)return a;const s=b(i);return this.updateGraphics3DGraphicElevationInfo(e,t,()=>s)}slicePlaneEnabledChanged(){const e={hasSlicePlane:this._context.slicePlaneEnabled};for(const t of this._materials)t?.setParameters(e);return!0}physicalBasedRenderingChanged(){return!0}_createAs3DShape(e,t,r){const i=H(e.graphic.geometry),a="polygon"===i.type?i.rings:i.paths,s=new Array,o=p(),l=O(i,this._context.elevationProvider,this._context.renderCoordsHelper,t),n="polygon"===i.type?"rings":"paths";this._logGeometryCreationWarnings(l,a,n,"LineSymbol3DLayer");for(let p=0;p<l.lines.length;p++){const t=l.lines[p],a=t.position,n=t.mapPositions;if(null!=this._context.clippingExtent&&(h(n,o),!m(o,this._context.clippingExtent)))continue;const c=this._createGeometry("polygon"===i.type?this._ringMaterial:this._lineMaterial,e,a,n,i.type,1,r);if(s.push(c),j.LINE_WIREFRAMES&&s.push(c.instantiate({material:"polygon"===i.type?this._wireframeRingMaterial:this._wireframeLineMaterial})),null!=this._markerMaterial){const t=c.instantiate({material:this._markerMaterial});t.attributes.has("color")&&t.setAttributeData("color",this._getDrivenMarkerColor(e.renderingInfo)),s.push(t)}}if(0===s.length)return null;const c=this._context.layerViewUid,u=new E({geometries:s,castShadow:!1,layerViewUid:c,graphicUid:r}),_=new C(this,u,null,g,t);return _.alignedSampledElevation=l.sampledElevation,_.needsElevationUpdates=b(t.mode),_}_createGeometry(e,t,r,i,a,s,o){const l=0===s?{spatialReference:this._context.overlaySR,renderCoordsHelper:this._context.renderCoordsHelper}:null,n="polygon"===a,c=this._fastUpdates?.visualVariables.color,p=this._fastUpdates?.visualVariables.size,h=this._fastUpdates?.visualVariables.opacity,m=this._context.layerViewUid,u=this._context.stage.renderView.getObjectAndLayerIdColor({graphicUid:o,layerViewUid:m}),{renderingInfo:_}=t,y={position:r,size:p?null:this._getDrivenSize(_),color:c?null:this._getDrivenColor(_),sizeFeature:p?z(p,_.size):null,colorFeature:c?x(c,_.color):null,opacityFeature:h?x(h,_.opacity):null};return V(e,{overlayInfo:l,removeDuplicateStartEnd:n,mapPositions:i,attributeData:y},u)}_createAsOverlay(e){const t=e.graphic,r=H(t.geometry),i="polygon"===r.type?r.rings:r.paths,a="polygon"===r.type?this._ringMaterial:this._lineMaterial;a.renderPriority=this._renderPriority;const s=j.LINE_WIREFRAMES?"polygon"===r.type?this._wireframeRingMaterial:this._wireframeLineMaterial:null,o=this._markerMaterial;null!=s&&(s.renderPriority=this._renderPriority-.001),null!=o&&(o.renderPriority=this._renderPriority-.002);const l=new Array,n=p(),c=u(),d=A(r,this._context.overlaySR),g="polygon"===r.type?"rings":"paths";this._logGeometryCreationWarnings(d,i,g,"LineSymbol3DLayer");for(const p of d.lines){if(h(p.position,n),!m(n,this._context.clippingExtent))continue;_(c,n);const i=this._createGeometry(a,e,p.position,void 0,r.type,0,t.uid),u=e=>{const r=this._context.layerViewUid,i=new G(e,{layerViewUid:r,graphicUid:t.uid});l.push(i)};if(null!=o){const t=i.instantiate({material:o});t.attributes.has("color")&&t.setAttributeData("color",this._getDrivenMarkerColor(e.renderingInfo)),u(t);const r=this.symbolLayer.marker.placement;"begin"!==r&&"begin-end"!==r||y(n,p.position,0,1),"end"!==r&&"begin-end"!==r||y(n,p.position,p.position.length-3,1)}u(i),j.LINE_WIREFRAMES&&u(i.instantiate({material:s}))}return new v(this,l,c,this._context.drapeSourceRenderer)}get _patternHidesLine(){const e=this.symbolLayer.pattern;return null!=e&&"style"===e.type&&"none"===e.style}_computeMaterialWidth(e){return e=e??t(1),this._drivenProperties.size?this._fastUpdates?.visualVariables.size?r(1):1:r(e)}_prepareMaterialPatch(e,t,r){const i=t.material;if(null==i)return void(r.changed&&r.useMaterialColor&&B(this._getCombinedOpacityAndColor(this._materialColor),this._materials[4],e));if("collection"===i.type)return;const a="complete"===i.type?i.newValue?.color:"complete"===i.diff.color?.type?i.diff.color.newValue:null,s=this._getCombinedOpacityAndColor(a);r.useMaterialColor&&B(o(s),this._materials[4],e),this._patternHidesLine&&(s[3]=0),B(s,this._materials[0],e),delete t.material}_prepareMarkerPatch(e,t){const r=t.marker,i=this._markerMaterial;if(null==r||"partial"!==r.type||null==r.diff||null!=r.diff.placement||null!=r.diff.style&&"complete"!==r.diff.style.type||null!=r.diff.color&&"complete"!==r.diff.color.type||null==i)return{changed:!1,useMaterialColor:null==this._markerColor};const a=r.diff.color,s=null!=a,o=s?a.newValue:null,l=null==o&&null==this._markerColor;o&&B(this._getCombinedOpacityAndColor(o),i,e);const n=r.diff.style?.newValue;return n&&e.symbolLayerStatePatches.push(()=>i.setParameters({markerPrimitive:w(n)})),delete t.marker,{changed:s,useMaterialColor:l}}_fastVisualVariableConvertOptions(e=!1){const t=this._getFallbackSize();return new U({supports:{size:!0,color:!0,rotation:!1,opacity:!0},fallbackColor:e?this._getFallbackMarkerOpacityAndColor(M):this._getFallbackOpacityAndColor(M),fallbackSize:i(t,t,t)})}_getFallbackOpacityAndColor(e){return this._materialColor?.toUnitRGBA()??e}_getFallbackOpacity(){return this._materialColor?.a??0}_getFallbackMarkerOpacityAndColor(e){return this.symbolLayer?.marker?.color?.toUnitRGBA()??this._getFallbackOpacityAndColor(e)}_getFallbackMarkerOpacity(){return this.symbolLayer?.marker?.color?.a??this._getFallbackOpacity()}_getFallbackSize(){const e=this.symbolLayer?.size;return null!=e?r(e):1}}function H(e){switch(e.type){case"extent":if(e instanceof n)return c.fromExtent(e);break;case"polygon":case"polyline":return e}return null}function B(e,t,r){null!=t&&r.symbolLayerStatePatches.push(()=>t.setParameters({color:e}))}function T(e){const t=e.material?.color,r=e.marker?.color??t;return 1===(t?.a??0)&&1===(r?.a??0)}export{W as Graphics3DLineSymbolLayer};