@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 5.83 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{pt2px as e}from"../../../../core/screenUtils.js";import{create as t}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as r,ZEROS as i}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{RenderingInfo as n}from"../../../../renderers/support/RenderingInfo.js";import{textSymbolLayerSupportsVerticalOffset as s}from"../../../../symbols/callouts/calloutUtils.js";import{perObjectElevationAligner as a}from"./ElevationAligners.js";import{elevationModeChangeUpdateType as o,needsElevationUpdates2D as l}from"./elevationAlignmentUtils.js";import{Graphics3DGraphicCreationContext as c}from"./Graphics3DGraphicCreationContext.js";import{Graphics3DObject3DGraphicLayer as h}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DObjectMetadata as p}from"./Graphics3DObjectMetadata.js";import{Graphics3DSymbolLayer as m}from"./Graphics3DSymbolLayer.js";import{computeCentroid as d}from"./graphicUtils.js";import{createStageObject as f,extendPointGraphicElevationContext as u}from"./pointUtils.js";import{SymbolComplexity as g}from"./SymbolComplexity.js";import{isObjectSymbol3DLayer as v,isTextSymbol3DLayer as y}from"../support/layerUtils.js";import{Attribute as x}from"../../webgl-engine/lib/Attribute.js";import{Geometry as _}from"../../webgl-engine/lib/Geometry.js";import{LineCalloutMaterial as b,Parameters as O,uniqueMaterialIdentifier as C}from"../../webgl-engine/materials/LineCalloutMaterial.js";class P extends m{static{this.elevationModeChangeTypes={definedChanged:1,staysOnTheGround:1,onTheGroundChanged:2}}constructor(e,t){super(e,null,t,E),this._elevationOptions={supportsOffsetAdjustment:!0,supportsOnTheGround:!1},this.ensureDrapedStatus(!1)}async doLoad(){this._materials[0]=new b(this._materialParameters,this._context.spherical)}_perInstanceMaterialParameters(e){const t=this._materialParameters;return t.horizontalScreenOffset=e.horizontalScreenOffset??0,t.centerOffsetUnits=e.centerOffsetUnits||"world",t}get _materialParameters(){const t=new O,r=this.symbol,n=r.callout;if(n.color){const e=n.color.toUnitRGBA();e[3]*=this._getLayerOpacity(),t.color=e}else t.color=i;if(t.size=e(n.size||0),r.verticalOffset){const{screenLength:i,minWorldLength:n,maxWorldLength:s}=r.verticalOffset;t.verticalOffset={screenLength:e(i),minWorldLength:n||0,maxWorldLength:null!=s?s:1/0}}t.borderColor=null!=n.border?.color?n.border.color.toUnitRGBA():null;const s=r.symbolLayers.at(0),a=v(s),o="label-3d"===r.type;return t.useVisibilityPixel=!1,a&&(t.shaderPolygonOffset=0),t.hudDepthAlignStart=o,t.hasSlicePlane=this._context.slicePlaneEnabled,t.screenSizePerspective=this._context.screenSizePerspectiveEnabled?this.view.screenSizePerspective.parameters:null,t}_defaultElevationInfoNoZ(){return w}createGraphics3DGraphic(e,t){const r=e.renderingInfo,i=e.graphic,n=this.createElevationContextForGraphic(i,r.elevationOffset||0),a=r.symbol,o="on-the-ground"===this._elevationContext.mode&&("cim"===a.type||!a.symbolLayers.some(e=>v(e)||y(e)));if("label-3d"!==a.type&&o)return null;if("point-3d"===a.type&&a.symbolLayers.every(e=>"text"===e.type&&!s(e)))return null;const l=d(i.geometry);return null==l?null:this._createAs3DShape(l,n,r,i.uid,t)}layerOpacityChanged(){this._materials[0]?.setParameters(this._materialParameters)}layerScreenSizePerspectiveChanged(){const e=this._context.screenSizePerspectiveEnabled?this.view.screenSizePerspective.parameters:null;this._materials[0]?.setParameters({screenSizePerspective:e})}layerElevationInfoChanged(e,t,r){const i=this._elevationContext.mode,n=o(P.elevationModeChangeTypes,r,i);return 1!==n||e?.forEach(e=>{const r=t(e);null!=r&&this.graphics3DGraphicLayerElevationInfoChanged(e.graphic,r)}),n}slicePlaneEnabledChanged(){return this._materials[0]?.setParameters({hasSlicePlane:this._context.slicePlaneEnabled}),!0}physicalBasedRenderingChanged(){return!0}createElevationContextForGraphic(e,t=0){const r=super.createElevationContextForGraphic(e);return r.addOffsetRenderUnits(t),r}updateElevationContextForGraphic(e,t,r=0){super.updateElevationContextForGraphic(e,t),e.addOffsetRenderUnits(r)}graphics3DGraphicLayerElevationInfoChanged(e,t){const{elevationContext:r,metadata:i}=t;this.updateElevationContextForGraphic(r,e,i?.elevationOffset??0),t.needsElevationUpdates=l(r.mode)}computeComplexity(){return new g({verticesPerFeature:6})}_getOrCreateMaterial(e,t){const r=this._perInstanceMaterialParameters(e),i=C(r);if(i===this._materials[0]?.uniqueMaterialIdentifier)return this._materials[0];if(t){let e=t.get(i);return null==e&&(e=new b(r,this._context.spherical),t.set(i,e)),e}return new b(r,this._context.spherical)}_createAs3DShape(e,t,r,i,n){const s=this._context.layerViewUid,o=this._context.stage.renderView.getObjectAndLayerIdColor({graphicUid:i,layerViewUid:s}),c=this._getOrCreateMaterial(r,n),m=new _(c,j(r),null,1,o),d=f(this._context,e,m,t,i);if(null==d)return null;const g=new h(this,d.object,null,a,t);return g.hiddenIfDeconflicted=!0,g.metadata=new p(r.elevationOffset),g.alignedSampledElevation=d.sampledElevation,g.needsElevationUpdates=l(t.mode),u(g,e,this._context.elevationProvider),g}}function j(e){const{translation:t,centerOffset:r}=e,i=new x(t?[t[0],t[1],t[2]]:[0,0,0],G,3,!0),n=new x(r?[r[0],r[1],r[2],r[3]]:[0,0,0,1],G,4,!0);return[["position",i],["normal",new x([0,0,1],G,3,!0)],["centerOffsetAndDistance",n]]}const G=[0],w={mode:"relative-to-ground",offset:0},E={ignoreDrivers:!0,renderPriority:0,renderPriorityStep:1};class S extends n{constructor(e,i,n=t(),s=r(),a=0,o="world",l=0){super(e,i),this.translation=n,this.centerOffset=s,this.horizontalScreenOffset=a,this.centerOffsetUnits=o,this.elevationOffset=l}}class U extends c{}export{P as Graphics3DLineCalloutSymbolLayer,U as LineCalloutCreationContext,S as LineCalloutSymbolLayerRenderingInfo};