@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 6.14 kB
JavaScript
import{forEach as e}from"../../../../core/asyncUtils.js";import{estimateAttributesObjectSize as i}from"../../../../core/byteSizeEstimations.js";import{isSome as t,isNone as r}from"../../../../core/maybe.js";import s from"../../../../core/ObjectPool.js";import{b as a}from"../../../../chunks/vec2.js";import{a as o}from"../../../../chunks/vec2f64.js";import{g as n}from"../../../../chunks/vec3.js";import{c as h}from"../../../../chunks/vec3f64.js";import l from"../../../../geometry/Polygon.js";import{projectBoundingRect as c}from"../../../../geometry/projection.js";import{set as y,ZERO as p,empty as m,expandWithAABB as u,allFinite as d,toRect as f}from"../../../../geometry/support/aaBoundingBox.js";import{create as b,allFinite as g}from"../../../../geometry/support/aaBoundingRect.js";import{equals as _}from"../../../../geometry/support/spatialReferenceUtils.js";import{computeAABR as E,numVertices as G}from"../../../../layers/graphics/dehydratedFeatures.js";import{convertFromGeometry as L}from"../../../../layers/graphics/featureConversionUtils.js";import{VisibilityFlag as x,VisibilityGroup as j}from"./enums.js";import{createFeature as v}from"./featureExpressionInfoUtils.js";const S=new s(Array,(e=>y(e,p)),null,10,5),B=b();class V{get labelLayers(){return this._labelLayers}get extent(){return this._extent}constructor(e,i,r,s,a){this.graphic=e,this.graphics3DSymbol=i,this.layers=r,this._labelLayers=new Array,this._auxiliaryLayers=new Array,this._visibilityFlags=z(j._COUNT,x._COUNT),this._featureExpressionFeature=null,this._optimizedGeometry={geometry:null,hasZ:!1,hasM:!1},this._extent=null,this.isElevationSource=!1,++i.referenced,this._featureExpressionFeature=a?v(a,e,s):null;for(const o of r)t(o)&&(this.isElevationSource=this.isElevationSource||o.isElevationSource)}initialize(e,i){this._layer=i,this._stage=e,this._forEachSymbolLayerGraphic((t=>{t.initialize(e,i),t.setVisibility(this.isVisible())}))}destroy(){this._forEachSymbolLayerGraphic((e=>e.destroy())),this.layers=null,this._auxiliaryLayers=null,--this.graphics3DSymbol.referenced,this.graphics3DSymbol=null}get destroyed(){return null==this.layers}clearLabelGraphics(){this._forEachLabelGraphic((e=>e.destroy())),this._labelLayers.length=0}addLabelGraphic(e,i,t){this._labelLayers.push(e),e.initialize(i,t),e.setVisibility(this.isVisible(j.LABEL))}addAuxiliaryGraphic(e){this._auxiliaryLayers.push(e),this._layer&&(e.initialize(this._stage,this._layer),e.setVisibility(this.isVisible()))}get isDraped(){let e=!1;return this._forEachSymbolLayerGraphic((i=>{"draped"===i.type&&(e=!0)})),e}isVisible(e=j.GRAPHIC,i){for(let t=0;t<=e;t++){const e=this._visibilityFlags[t];for(let t=0;t<e.length;++t)if(!1===e[t]&&t!==i)return!1}return!0}hasVisibilityFlag(e,i){return null!=this._visibilityFlags[i][e]}setVisibilityFlag(e,i,t){const r=this.isVisible(t);this._visibilityFlags[t][e]=i;const s=this.isVisible(t);if(r===s)return!1;if(t===j.LABEL)this._forEachLabelGraphic((e=>e.setVisibility(s)));else{this._forEachSymbolLayerGraphic((e=>e.setVisibility(s)));const e=this.isVisible(j.LABEL);this._forEachLabelGraphic((i=>i.setVisibility(e)))}return!0}clearVisibilityFlag(e,i=j.GRAPHIC){return this.setVisibilityFlag(e,void 0,i)}computeExtent(e){if(!this._extent){const i=this.graphic.geometry;if(r(i))return!1;this._extent=b(),E(i,this._extent);const t=i.spatialReference;if(!_(t,e)&&!c(this._extent,t,this._extent,e))return this._extent=null,!1}return!0}getAsOptimizedGeometry(e,i){return t(this._optimizedGeometry.geometry)&&this._optimizedGeometry.hasZ===e&&this._optimizedGeometry.hasM===i||(this._optimizedGeometry.geometry=this._convertGraphicToOptimizedGeometry(this.graphic,e,i),this._optimizedGeometry.hasZ=e,this._optimizedGeometry.hasM=i),this._optimizedGeometry.geometry}_convertGraphicToOptimizedGeometry(e,i,t){let r=e.geometry;return"mesh"!==r.type&&"extent"!==r.type||(r=l.fromExtent("mesh"===r.type?r.extent:r)),L(r,i,t)}get usedMemory(){let e=i(this.graphic.attributes);return this._forEachSymbolLayerGraphic((i=>{const t=i.graphics3DSymbolLayer.complexity;if(r(t))return;const s="draped"===i.type?t.memory.draped:t.memory;e+=s.bytesPerFeature,s.bytesPerCoordinate&&(e+=G(this.graphic.geometry)*s.bytesPerCoordinate)})),e}computeAttachmentOrigin(){const e={render:{origin:h(),num:0},draped:{origin:o(),num:0}};for(const i of this.layers)r(i)||i.computeAttachmentOrigin(e);return e.render.num>1&&n(e.render.origin,e.render.origin,1/e.render.num),e.draped.num>1&&a(e.draped.origin,e.draped.origin,1/e.draped.num),e}async getProjectedBoundingBox(i,t,s,a,o){return o||(o={boundingBox:null,requiresDrapedElevation:!1,screenSpaceObjects:[]}),o.boundingBox?m(o.boundingBox):o.boundingBox=m(),o.requiresDrapedElevation=!1,await e(this.layers,(async e=>{if(r(e))return;const n="draped"===e.type?t:i,h=S.acquire(),l=await e.getProjectedBoundingBox(n,s,o.screenSpaceObjects,a,h);isFinite(l[2])&&isFinite(l[5])||(o.requiresDrapedElevation=!0),l&&u(o.boundingBox,h),S.release(h)})),d(o.boundingBox)||g(f(o.boundingBox,B))?o:null}needsElevationUpdates(){for(const e of this.layers)if(t(e)&&("object3d"===e.type||"lod-instance"===e.type)&&e.needsElevationUpdates)return!0;for(const e of this._labelLayers)if(e&&e.needsElevationUpdates)return!0;return!1}alignWithElevation(e,i,t){this._forEachRenderedGraphic((r=>{"object3d"!==r.type&&"lod-instance"!==r.type||r.alignWithElevation(e,i,this._featureExpressionFeature,t)}))}alignWithAbsoluteElevation(e,i,t){this._forEachRenderedGraphic((r=>{"object3d"===r.type&&r.alignWithAbsoluteElevation(e,i,t)}))}addObjectStateSet(e,i){this._forEachSymbolLayerGraphic((t=>t.addObjectState(e,i)))}removeObjectState(e){this._forEachSymbolLayerGraphic((i=>i.removeObjectState(e)))}_forEachGraphicList(e,i){e.forEach((e=>e&&i(e)))}_forEachSymbolLayerGraphic(e){this._forEachGraphicList(this.layers,e),this._forEachGraphicList(this._auxiliaryLayers,e)}_forEachLabelGraphic(e){this._forEachGraphicList(this._labelLayers,e)}_forEachRenderedGraphic(e){this._forEachSymbolLayerGraphic(e),this._forEachLabelGraphic(e)}}function z(e,i){const t=new Array(e);for(let r=0;r<t.length;r++)t[r]=new Array(i);return t}export{V as default};