@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 4.78 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as e}from"../../../../chunks/tslib.es6.js";import{destroyMaybe as t,removeMaybe as i}from"../../../../core/maybe.js";import{initial as s,watch as r,sync as a}from"../../../../core/reactiveUtils.js";import"../../../../core/Logger.js";import"../../../../core/has.js";import"../../../../core/RandomLCG.js";import"../../../../core/Error.js";import{subclass as o}from"../../../../core/accessorSupport/decorators/subclass.js";import{t as c}from"../../../../chunks/boundedPlane.js";import{Deconflictor as n,DeconflictorGraphic as h}from"./Deconflictor.js";import{VisibilityGroup as l,VisibilityFlag as d}from"./enums.js";import{LabelDeconflictor as p}from"./LabelDeconflictor.js";import{TaskPriority as m}from"../../../support/Scheduler.js";let u=class extends n{constructor(){super(...arguments),this._contexts=new Map,this.visibilityGroup=l.GRAPHIC,this._marginFactor=-.1,this.test={overrideMarginFactor:e=>{this._marginFactor=e,this.setDirty()}}}get labels(){return this._labels}get viewState(){return this._viewState}initialize(){this._updatingHandles.add((()=>this.view?.state?.camera),(()=>{this._updateViewState(),this.setDirty()})),this._updatingHandles.add((()=>this.view?.slice?.plane),(()=>{this._updateSlicePlane(),this._slicePlaneChanged()}),s),this.addHandles(r((()=>this.view.basemapTerrain?.updating||this.view.graphicsView?.updating||this.view.allLayerViews.some((e=>e.updating))),((e,t)=>{!e&&t&&this.setDirty()}),a)),this._frameTask=this.view.resourceController.scheduler.registerTask(m.GRAPHICS_DECONFLICTOR,this),this._labels=new p({view:this.view,parent:this})}destroy(){this._labels=t(this._labels),this._frameTask=i(this._frameTask)}get marginFactor(){return this._marginFactor}setDirty(){this._contexts.size>0&&(super.setDirty(),this._labels.setDirty())}runTask(e){const t=super.runTask(e);return this.running||this._labels.setDirty(),t}_updateViewState(){this.view?.state&&(this._viewState.camera.copyFrom(this.view.state.camera),this._updateSlicePlane())}_updateSlicePlane(){const e=this.view?.slice?.plane;null!=e&&c(e,this._viewState.camera.viewMatrix,this._viewState.slicePlane),this._viewState.slicePlaneEnabled=null!=e}_slicePlaneChanged(){for(const e of this._contexts.keys())if(e.symbolCreationContext.slicePlaneEnabled)return void this.setDirty()}addGraphicsOwner(e){const t=this._getGraphicsContext(e);return{addGraphic:i=>this._addGraphic(e,t,i),removeGraphic:e=>this._removeGraphic(t,e),labelingInfoChange:()=>this._labelsEnabledChanged(e,t),featureReductionChange:()=>this._enabledChanged(e,t),slicePlaneEnabledChange:()=>this._slicePlaneEnabledChanged(e,t),clear:()=>t.forEach((e=>this._removeGraphic(t,e.graphics3DGraphic))),remove:()=>this._removeGraphicsOwner(e),setDirty:()=>this.setDirty()}}_removeGraphicsOwner(e){const t=this._contexts.get(e);t&&(t.forEach((e=>this._removeGraphic(t,e.graphics3DGraphic))),this._contexts.delete(e),this.setDirty())}_addGraphic(e,t,i){const s=i.graphic.uid,r=new h(i,e.symbolCreationContext.slicePlaneEnabled);t.set(s,r),this.addToCheckOcclusion(r),_(e)&&this.addToActiveGraphics(r),e.labelsEnabled&&(this._labels.addToCheckOcclusion(r),this._labels.addToActiveGraphics(r));const a=!this._graphicSupportsDeconfliction(i)||!_(e);i.setVisibilityFlag(l.GRAPHIC,d.DECONFLICTION,a)}_removeGraphic(e,t){const i=t.graphic.uid,s=e.get(i);s&&(this.removeFromActiveGraphics(s),this.removeFromCheckOcclusion(s),this._labels.removeFromActiveGraphics(s),this._labels.removeFromCheckOcclusion(s),e.delete(i),this.setDirty())}_enabledChanged(e,t){_(e)?t.forEach((e=>this.addToActiveGraphics(e))):(t.forEach((e=>this.removeFromActiveGraphics(e))),b(e))}_labelsEnabledChanged(e,t){e.labelsEnabled?(t.forEach((e=>this._labels.addToCheckOcclusion(e))),t.forEach((e=>this._labels.addToActiveGraphics(e)))):(t.forEach((e=>this._labels.removeFromCheckOcclusion(e))),t.forEach((e=>this._labels.removeFromActiveGraphics(e))))}_slicePlaneEnabledChanged(e,t){const i=e.symbolCreationContext.slicePlaneEnabled;t.forEach((e=>e.slicePlaneEnabled=i)),this.setDirty()}_graphicSupportsDeconfliction(e){if(e.isDraped)return!1;const t=e.layers;if(!t?.length)return!1;for(const i of t)if(this.layerSupportsDeconfliction(i))return!0;return!1}_getGraphicsContext(e){const t=this._contexts.get(e);if(t)return t;const i=new Map;return this._contexts.set(e,i),this.setDirty(),i}};function _(e){const t=e.layer;return!(!t?.featureReduction||"selection"!==t.featureReduction.type)}function b(e){const t=e.graphics3DGraphics;t&&t.forEach((e=>e.setVisibilityFlag(l.GRAPHIC,d.DECONFLICTION,!0)))}u=e([o("esri.views.3d.layers.graphics.GraphicsDeconflictor")],u);export{u as GraphicsDeconflictor};