UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) • 12.7 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import e from"../../../../Color.js";import t from"../../../../core/Error.js";import{px2pt as r,pt2px as i}from"../../../../core/screenUtils.js";import{fromValues as a}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{c as s}from"../../../../chunks/vec42.js";import{fromValues as o,ones as n,clone as l,ZEROS as c}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import p from"../../../../geometry/Extent.js";import m from"../../../../geometry/Polygon.js";import{create as h,fromBuffer as y,intersectsClippingArea as u,empty as d,expandWithAABB as f,expandWithBuffer as _}from"../../../../geometry/support/aaBoundingBox.js";import{getDriverAxisSizeValueAny as g}from"../../../../renderers/support/renderingInfoUtils.js";import{sharedGeometryElevationAligner as b}from"./ElevationAligners.js";import{SymbolUpdateType as L,elevationModeChangeUpdateType as M,needsElevationUpdates2D as k}from"./elevationAlignmentUtils.js";import{Graphics3DDrapedGraphicLayer as C}from"./Graphics3DDrapedGraphicLayer.js";import{Graphics3DObject3DGraphicLayer as v}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DSymbolLayer as P}from"./Graphics3DSymbolLayer.js";import{ApplyRendererDiffResult as E}from"./interfaces.js";import{parseCapType as w,parseLineMarkerStyle as R}from"./lineUtils.js";import{initFastSymbolUpdatesState as A,updateFastSymbolUpdatesState as D,getAttributeValue as V,ConvertOptions as O}from"../support/FastSymbolUpdates.js";import{debugFlags as S}from"../../support/debugFlags.js";import{createGeometry as U}from"../../support/engineContent/line.js";import{geometryToRenderInfo as j,geometryToRenderInfoDraped as x}from"../../support/renderInfoUtils/line.js";import{Object3D as z}from"../../webgl-engine/lib/Object3D.js";import{RenderGeometry as F}from"../../webgl-engine/lib/RenderGeometry.js";import{VertexAttribute as G}from"../../webgl-engine/lib/VertexAttribute.js";import{LineMarkerMaterial as W}from"../../webgl-engine/materials/LineMarkerMaterial.js";import{getStipplePatternForLinePattern as I}from"../../webgl-engine/materials/lineStippleUtils.js";import{RibbonLineMaterial as T}from"../../webgl-engine/materials/RibbonLineMaterial.js";const H=["polyline","polygon","extent"];class B extends P{static{this.elevationModeChangeTypes={definedChanged:L.RECREATE,staysOnTheGround:L.NONE,onTheGroundChanged:L.RECREATE}}constructor(e,t,r,i){super(e,t,r,i,J(t))}async doLoad(){this._fastUpdates=A(this._context.renderer,this._fastVisualVariableConvertOptions());const e=!0;if(this._fastMarkerUpdates=A(this._context.renderer,this._fastVisualVariableConvertOptions(e)),!this._drivenProperties.size){if((null!=this.symbolLayer.size?this.symbolLayer.size:r(1))<0)throw new t("graphics3dlinesymbollayer:invalid-size","Symbol sizes may not be negative values")}}_getMaterialParameters(e,t=!1){const r=this._getCombinedOpacityAndColor(t&&this._markerColor||this._materialColor);this._patternHidesLine&&!t&&(r[3]=0);const i={width:this._computeMaterialWidth(this.symbolLayer?.size),color:r,hasPolygonOffset:!0,join:this.symbolLayer.join||"miter",cap:w(this.symbolLayer.cap||"butt"),hasSlicePlane:this._context.slicePlaneEnabled,isClosed:e,stipplePattern:I(this.symbolLayer.pattern)};return t&&this._fastMarkerUpdates?.visualVariables?{...i,...this._fastMarkerUpdates.materialParameters}:this._fastUpdates?.visualVariables?{...i,...this._fastUpdates.materialParameters}:i}get _materialColor(){return this.symbolLayer.material?.color}get _markerColor(){return this.symbolLayer.marker?.color}get _lineMaterial(){return null==this._materials[Q.Line]&&(this._materials[Q.Line]=new T(this._getMaterialParameters(!1))),this._materials[Q.Line]}get _ringMaterial(){return null==this._materials[Q.Ring]&&(this._materials[Q.Ring]=new T(this._getMaterialParameters(!0))),this._materials[Q.Ring]}get _wireframeLineMaterial(){return null==this._materials[Q.LineWireframe]&&(this._materials[Q.LineWireframe]=new T({...this._getMaterialParameters(!1),wireframe:!0})),this._materials[Q.LineWireframe]}get _wireframeRingMaterial(){return null==this._materials[Q.RingWireframe]&&(this._materials[Q.RingWireframe]=new T({...this._getMaterialParameters(!0),wireframe:!0})),this._materials[Q.RingWireframe]}get _markerMaterial(){return null==this._materials[Q.Marker]&&null!=this.symbolLayer.marker&&(this._materials[Q.Marker]=new W({...this._getMaterialParameters(!1,!0),placement:this.symbolLayer.marker.placement,markerPrimitive:R(this.symbolLayer.marker.style)})),this._materials[Q.Marker]}_getDrivenSize(e){if(this._drivenProperties.size){const t=e.size;return null!=t?i(g(t)):this._getFallbackSize()}return 1}_getDrivenColor({color:e,opacity:t}){const r=o(1,1,1,1);return this._drivenProperties.color&&s(r,e??this._getFallbackOpacityAndColor()),this._drivenProperties.opacity&&(r[3]=t??this._getFallbackOpacity()),r}_getDrivenMarkerColor({color:e,opacity:t}){const r=n();return this._drivenProperties.color&&s(r,e??this._getFallbackMarkerOpacityAndColor()),this._drivenProperties.opacity&&(r[3]=t??this._getFallbackMarkerOpacity()),r}createGraphics3DGraphic(e){const t=e.graphic;if(!this._validateGeometry(t.geometry,H,this.symbolLayer.type))return null;const r=this.setGraphicElevationContext(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 E.RecreateSymbol;{const e=this._fastUpdates;if(!D(e,t,this._fastVisualVariableConvertOptions()))return E.RecreateSymbol;for(const t of this._materials)t instanceof T&&t.setParameters(e.materialParameters);const r=this._fastMarkerUpdates,i=!0;if(!D(r,t,this._fastVisualVariableConvertOptions(i)))return E.RecreateSymbol;for(const t of this._materials)t instanceof W&&t.setParameters(r.materialParameters)}}return E.FastUpdate}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=w(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(const e of this._materials)this._updateMaterialLayerOpacity(e,e instanceof W)}_updateMaterialLayerOpacity(e,t=!1){if(null==e)return;const r=e.parameters.color,i=this.symbolLayer?.material?.color,a=this._patternHidesLine&&!t?0:this._getCombinedOpacity(i),s=o(r[0],r[1],r[2],a);e.setParameters({color:s})}layerElevationInfoChanged(e,t,r){const i=this._elevationContext.mode,a=M(B.elevationModeChangeTypes,r,i);if(a!==L.UPDATE)return a;const s=k(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=N(e.graphic.geometry),a="polygon"===i.type?i.rings:i.paths,s=new Array,o=h(),n=j(i,this._context.elevationProvider,this._context.renderCoordsHelper,t),l="polygon"===i.type?"rings":"paths";this._logGeometryCreationWarnings(n,a,l,"LineSymbol3DLayer");for(let h=0;h<n.lines.length;h++){const t=n.lines[h],a=t.position,l=t.mapPositions;if(null!=this._context.clippingExtent&&(y(l,o),!u(o,this._context.clippingExtent)))continue;const c=this._createGeometry("polygon"===i.type?this._ringMaterial:this._lineMaterial,e,a,l,i.type,K.ELEVATED,r);if(s.push(c),S.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.setAttributeData(G.COLOR,this._getDrivenMarkerColor(e.renderingInfo)),s.push(t)}}if(0===s.length)return null;const c=this._context.layerViewUid,p=new z({geometries:s,castShadow:!1,layerViewUid:c,graphicUid:r}),m=new v(this,p,null,b,t);return m.alignedSampledElevation=n.sampledElevation,m.needsElevationUpdates=k(t.mode),m}_createGeometry(e,t,r,i,a,s,o){const n=s===K.DRAPED?{spatialReference:this._context.overlaySR,renderCoordsHelper:this._context.renderCoordsHelper}:null,l="polygon"===a,c=this._fastUpdates?.visualVariables.color,p=this._fastUpdates?.visualVariables.size,m=this._fastUpdates?.visualVariables.opacity,h=this._context.layerViewUid,y=this._context.stage.renderView.getObjectAndLayerIdColor({graphicUid:o,layerViewUid:h}),u={position:r,size:p?null:this._getDrivenSize(t.renderingInfo),color:c?null:this._getDrivenColor(t.renderingInfo),sizeFeature:p?V(p.field,t.graphic):null,colorFeature:c?V(c.field,t.graphic):null,opacityFeature:m?V(m.field,t.graphic):null};return U(e,{overlayInfo:n,removeDuplicateStartEnd:l,mapPositions:i,attributeData:u},y)}_createAsOverlay(e){const t=e.graphic,r=N(t.geometry),i="polygon"===r.type?r.rings:r.paths,a="polygon"===r.type?this._ringMaterial:this._lineMaterial;a.renderPriority=this._renderPriority;const s=S.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 n=new Array,l=h(),c=d(),p=x(r,this._context.overlaySR),m="polygon"===r.type?"rings":"paths";this._logGeometryCreationWarnings(p,i,m,"LineSymbol3DLayer");for(const h of p.lines){if(y(h.position,l),!u(l,this._context.clippingExtent))continue;f(c,l);const i=i=>{const a=this._createGeometry(i,e,h.position,void 0,r.type,K.DRAPED,t.uid),s=this._context.layerViewUid,o=new F(a,{layerViewUid:s,graphicUid:t.uid});n.push(o)};if(null!=o){i(o);const e=this.symbolLayer.marker.placement;"begin"!==e&&"begin-end"!==e||_(l,h.position,0,1),"end"!==e&&"begin-end"!==e||_(l,h.position,h.position.length-3,1)}i(a),S.LINE_WIREFRAMES&&i(s)}return new C(this,n,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??r(1),this._drivenProperties.size?this._fastUpdates?.visualVariables.size?i(1):1:i(e)}_prepareMaterialPatch(e,t,r){const i=t.material;if(null==i)return void(r.changed&&r.useMaterialColor&&q(this._getCombinedOpacityAndColor(this._materialColor),this._materials[Q.Marker],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&&q(l(s),this._materials[Q.Marker],e),this._patternHidesLine&&(s[3]=0),q(s,this._materials[Q.Line],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,n=null==o&&null==this._markerColor;o&&q(this._getCombinedOpacityAndColor(o),i,e);const l=r.diff.style?.newValue;return l&&e.symbolLayerStatePatches.push((()=>i.setParameters({markerPrimitive:R(l)}))),delete t.marker,{changed:s,useMaterialColor:n}}_fastVisualVariableConvertOptions(e=!1){const t=this._getFallbackSize();return new O({supports:{size:!0,color:!0,rotation:!1,opacity:!0},fallbackColor:e?this._getFallbackMarkerOpacityAndColor():this._getFallbackOpacityAndColor(),fallbackSize:a(t,t,t)})}_getFallbackOpacityAndColor(){const t=this.symbolLayer?.material?.color;return e.toUnitRGBA(t)??c}_getFallbackOpacity(){return this.symbolLayer?.material?.color?.a??0}_getFallbackMarkerOpacityAndColor(){const t=this.symbolLayer?.marker?.color;return e.toUnitRGBA(t)??c}_getFallbackMarkerOpacity(){return this.symbolLayer?.marker?.color?.a??0}_getFallbackSize(){const e=this.symbolLayer?.size;return null!=e?i(e):1}}function N(e){switch(e.type){case"extent":if(e instanceof p)return m.fromExtent(e);break;case"polygon":case"polyline":return e}return null}function q(e,t,r){null!=t&&r.symbolLayerStatePatches.push((()=>t.setParameters({color:e})))}function J(e){return 1===(e.material?.color?.a??1)&&1===(e.marker?.color?.a??1)}var K,Q;!function(e){e[e.DRAPED=0]="DRAPED",e[e.ELEVATED=1]="ELEVATED"}(K||(K={})),function(e){e[e.Line=0]="Line",e[e.Ring=1]="Ring",e[e.LineWireframe=2]="LineWireframe",e[e.RingWireframe=3]="RingWireframe",e[e.Marker=4]="Marker"}(Q||(Q={}));export{B as Graphics3DLineSymbolLayer};