@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 5.56 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{emptyArray as e}from"../../../../core/arrayUtils.js";import{forEach as t}from"../../../../core/asyncUtils.js";import"../../../../core/has.js";import{estimateAttributesMemory as i}from"../../../../core/memoryEstimations.js";import r from"../../../../core/ObjectPool.js";import{scale as s}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{scale as o}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as l}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import n from"../../../../geometry/Polygon.js";import{projectBoundingRect as c}from"../../../../geometry/projection/projectBoundingRect.js";import{empty as h,expandWithAABB as p,allFinite as d,toRect as m,create as y,set as u,zero as g}from"../../../../geometry/support/aaBoundingBox.js";import{create as b,allFinite as f}from"../../../../geometry/support/aaBoundingRect.js";import{equals as _}from"../../../../geometry/support/spatialReferenceUtils.js";import{computeAABR as E}from"../../../../layers/graphics/dehydratedFeatures.js";import{convertFromGeometry as v}from"../../../../layers/graphics/featureConversionUtils.js";const L=new r(()=>y(),e=>u(e,g),null,10,5),G=b();class j{get labelLayers(){return this._labelLayers||e}get extent(){return this._extent}get isElevationSource(){return this.layers.some(e=>e?.isElevationSource)}constructor(e,t,i){this.graphic=e,this.graphics3DSymbol=t,this.layers=i,this._visibleFlags=255,++t.referenced;i.every(e=>e&&"hiddenIfDeconflicted"in e&&e.hiddenIfDeconflicted)&&(this._visibleFlags|=256)}initialize(e){this._layer=e,this._forEachSymbolLayerGraphic(t=>{t.initialize(e),x(this._visibleFlags,1,t)})}destroy(){this._forEachSymbolLayerGraphic(e=>e.destroy()),this._calloutLayer=null,--this.graphics3DSymbol.referenced,this.graphics3DSymbol=null}get destroyed(){return null==this.layers}clearLabelGraphics(){this._forEachLabelGraphic(e=>e.destroy()),this._labelLayers=null}addLabelGraphic(e,t){this._labelLayers||(this._labelLayers=new Array),this._labelLayers.push(e),e.initialize(t),x(this._visibleFlags,16,e)}setCalloutGraphic(e){this._calloutLayer=e,this._layer&&(e.initialize(this._layer),x(this._visibleFlags,1,e))}get calloutLayer(){return this._calloutLayer}get isDraped(){let e=!1;return this._forEachSymbolLayerGraphic(t=>{"draped"===t.type&&(e=!0)}),e}isVisible(e=1,t=0){const i=this._visibleFlags;return S(i,e,t|16*t|(256&i?0:8))}setVisibilityFlag(e,t,i){const r=e*t;return i!==((this._visibleFlags&r)===r)&&(i?this._visibleFlags|=r:this._visibleFlags&=~r,1===e&&this._forEachSymbolLayerGraphic(e=>x(this._visibleFlags,1,e)),this._forEachLabelGraphic(e=>x(this._visibleFlags,16,e)),!0)}getVisibilityFlag(e,t){return 0!==(this._visibleFlags&e*t)}computeExtent(e){if(!this._extent){const t=this.graphic.geometry;if(null==t)return!1;this._extent=b(),E(t,this._extent);const i=t.spatialReference;if(!_(i,e)&&!c(this._extent,i,this._extent,e))return this._extent=null,!1}return!0}getAsOptimizedGeometry(e,t){return this._optimizedGeometry||(this._optimizedGeometry=this._convertGraphicToOptimizedGeometry(this.graphic,e,t)),this._optimizedGeometry}_convertGraphicToOptimizedGeometry(e,t,i){let r=e.geometry;return"mesh"!==r.type&&"extent"!==r.type||(r=n.fromExtent("mesh"===r.type?r.extent:r)),v(r,t,i)}get usedMemory(){let e=i(this.graphic.attributes);return this._forEachSymbolLayerGraphic(t=>e+=t.usedMemory),e}computeAttachmentOrigin(){const e={render:{origin:l(),num:0},draped:{origin:a(),num:0}};for(const t of this.layers)null!=t&&t.computeAttachmentOrigin(e);return e.render.num>1&&o(e.render.origin,e.render.origin,1/e.render.num),e.draped.num>1&&s(e.draped.origin,e.draped.origin,1/e.draped.num),e}async getProjectedBoundingBox(e,i,r,s,a){return a||(a={boundingBox:null,requiresDrapedElevation:!1,screenSpaceObjects:[]}),a.boundingBox?h(a.boundingBox):a.boundingBox=h(),a.requiresDrapedElevation=!1,await t(this.layers,async t=>{if(null==t)return;const o="draped"===t.type?i:e,l=L.acquire(),n=await t.getProjectedBoundingBox(o,r,a.screenSpaceObjects,s,l);isFinite(n[2])&&isFinite(n[5])||(a.requiresDrapedElevation=!0),n&&p(a.boundingBox,l),L.release(l)}),d(a.boundingBox)||f(m(a.boundingBox,G))?a:null}needsElevationUpdates(){for(const e of this.layers)if(null!=e&&("object3d"===e.type||"lod-instance"===e.type)&&e.needsElevationUpdates)return!0;return this._labelLayers?.some(e=>e?.needsElevationUpdates??!1)??!1}alignWithElevation(e,t,i){this._forEachRenderedGraphic(r=>{"object3d"!==r.type&&"lod-instance"!==r.type||r.alignWithElevation(e,t,i)})}alignWithAbsoluteElevation(e,t,i){this._forEachRenderedGraphic(r=>{"object3d"===r.type&&r.alignWithAbsoluteElevation(e,t,i)})}addObjectStateSet(e){this._forEachSymbolLayerGraphic(t=>t.addObjectState(e))}removeObjectState(e){this._forEachSymbolLayerGraphic(t=>t.removeObjectState(e))}updateHighlights(e){this._forEachSymbolLayerGraphic(t=>t.updateHighlights(e))}_forEachGraphicList(e,t){e?.forEach(e=>e&&t(e))}_forEachSymbolLayerGraphic(e){this._forEachGraphicList(this.layers,e),this._calloutLayer&&e(this._calloutLayer)}_forEachLabelGraphic(e){this._forEachGraphicList(this.labelLayers,e)}_forEachRenderedGraphic(e){this._forEachSymbolLayerGraphic(e),this._forEachLabelGraphic(e)}get test(){}}function x(e,t,i){const r=1===t?"hiddenIfDeconflicted"in i&&i.hiddenIfDeconflicted?0:8:256&e?0:8;i.setVisibility(S(e,t,r))}function S(e,t,i=0){const r=(1===t?15:255)&~i;return(e&r)===r}export{j as Graphics3DGraphic};