UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 6.3 kB
import{_ as e}from"../../../../chunks/tslib.es6.js";import{HandleOwner as i}from"../../../../core/HandleOwner.js";import t from"../../../../core/Logger.js";import{isSome as r,isNone as a}from"../../../../core/maybe.js";import{property as s}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import"../../../../core/arrayUtils.js";import{subclass as l}from"../../../../core/accessorSupport/decorators/subclass.js";import{projectBoundingRect as n}from"../../../../geometry/projection.js";import{create as c}from"../../../../geometry/support/aaBoundingRect.js";import{VisibilityFlag as o,VisibilityGroup as h}from"./enums.js";import{scaleBoundsPredicate as p}from"../../../support/layerViewUtils.js";import{TaskPriority as y,Task as d}from"../../../support/Scheduler.js";const u=t.getLogger("esri.views.3d.layers.graphics.Graphics3DScaleVisibility");let g=class extends i{constructor(e){super(e),this._scaleRangeActive=!1,this._layerScaleRangeVisibilityQuery=!1,this._extent=null,this.graphicsCoreOwner=null,this.layer=null,this.queryGraphicUIDsInExtent=null,this.graphicsCore=null,this.basemapTerrain=null,this.layerScaleEnabled=!0,this.suspended=!1,this._dirty=!0}initialize(){this.updateScaleRangeActive();const e=this.graphicsCoreOwner.view.resourceController.scheduler;this.handles.add(e.registerTask(y.SCALE_VISIBILITY,this)),this.updatingHandles.add((()=>this.layer.effectiveScaleRange),(()=>this.layerMinMaxScaleChangeHandler()))}destroy(){this.updatingHandles.removeAll(),this.handles.removeAll(),this._dirty=!1,this._extent=null,this.graphicsCoreOwner=null,this.layer=null,this.queryGraphicUIDsInExtent=null,this.graphicsCore=null,this.basemapTerrain=null}get updating(){return this._dirty||this.updatingHandles.updating}_setDirty(){this._dirty=!0}setExtent(e){const i=this.graphicsCoreOwner.view.spatialReference,t=this.graphicsCoreOwner.view.basemapTerrain.spatialReference;if(i===t)this._extent=e??null;else{const r=c();n(e,i,r,t)?this._extent=r:this._extent=null}this._setDirty()}scaleRangeActive(){return this._scaleRangeActive}updateScaleRangeActive(){const e=this.layer,i=e.effectiveScaleRange;let t=this.layerScaleEnabled&&null!=i&&b(i.minScale,i.maxScale);e.labelingInfo&&!t&&(t=e.labelingInfo.some((e=>e&&b(e.minScale??0,e.maxScale??0))));const r=this._scaleRangeActive!==t;return this._scaleRangeActive=t,t&&!this.handles.has(m)&&this.basemapTerrain?(this.handles.add(this.basemapTerrain.on("scale-change",(e=>this._scaleUpdateHandler(e))),m),this.layerScaleEnabled&&this.handles.add(this.basemapTerrain.on("tiles-visibility-changed",(()=>this._setDirty())),m)):!t&&this.handles.has(m)&&this.handles.remove(m),r}get running(){return!(!this.graphicsCoreOwner.view.basemapTerrain||!this.updating)}runTask(e){const i=this.graphicsCoreOwner.view.basemapTerrain;if(this._extent&&i&&i.ready&&this._scaleRangeActive&&this.layerScaleEnabled){if(this._layerScaleRangeVisibilityQuery)return d.YIELD;{this._layerScaleRangeVisibilityQuery=!0;const{minScale:e,maxScale:t}=this.layer.effectiveScaleRange;i.queryVisibleScaleRange(this._extent,e,t,(e=>this._finishUpdate(e)))}}else this._finishUpdate(!0);e.madeProgress()}_finishUpdate(e){this._layerScaleRangeVisibilityQuery=!1,this._set("suspended",!e),this._dirty=!1}_visibleAtLayerScale(e){const i=this.layer.effectiveScaleRange;return!this.layerScaleEnabled||p(e,i.minScale||0,i.maxScale||0)}_visibleAtLabelScale(e,i){return p(e,i.minScale||0,i.maxScale||0)}_graphicScale(e){let i;if(r(e.centroid)?i=e.centroid:r(e.graphic.geometry)&&"point"===e.graphic.geometry.type&&(i=e.graphic.geometry),i){return this.graphicsCoreOwner.view.basemapTerrain?this.graphicsCoreOwner.view.basemapTerrain.getScale(i):1}return null}_graphicVisible(e){if(!this.layerScaleEnabled)return!0;const i=this._graphicScale(e);return this._visibleAtLayerScale(i)}updateVisibility(e){if(this._scaleRangeActive){const i=this._graphicVisible(e);return e.setVisibilityFlag(o.SCALE_RANGE,i,h.GRAPHIC)}return!1}updateGraphicLabelScaleVisibility(e){if(!this._scaleRangeActive)return!1;if(!e.labelLayers||0===e.labelLayers.length)return!1;const i=this._graphicScale(e),t=this._updateLabelScaleVisibility(e,i);return t&&(this.graphicsCoreOwner.view.deconflictor.setDirty(),this.graphicsCoreOwner.view.labeler.setDirty()),t}_updateLabelScaleVisibility(e,i){if(!e.labelLayers||0===e.labelLayers.length)return!1;const t=e.labelLayers[0]._labelClass;if(t&&null!=t.minScale&&null!=t.maxScale){const r=this._visibleAtLabelScale(i,t);if(e.setVisibilityFlag(o.SCALE_RANGE,r,h.LABEL))return!0}return!1}_scaleUpdateHandler(e){if(this._setDirty(),!this.graphicsCore.visible)return;const i=e.extent,t=e.scale,s=this._visibleAtLayerScale(t);let l=!1;const c=this.graphicsCoreOwner.view.spatialReference,p=e.spatialReference;if(a(p))return void u.error("scaleUpdate: Internal error, no SpatialReference given for tiles");const y=!p.equals(c);if(y){if(!n(i,p,S,c))return void u.error("scaleUpdate: Internal error, cannot project AABR from "+p+" to wkid "+c)}const d=y?S:i;this.queryGraphicUIDsInExtent(d,c,(e=>{const n=this.graphicsCore.getGraphics3DGraphicById(e);if(a(n))return;const c=n.centroid;r(c)&&(i[0]>c.x||i[1]>c.y||i[2]<c.x||i[3]<c.y)||(n.setVisibilityFlag(o.SCALE_RANGE,s,h.GRAPHIC)&&(l=!0),this._updateLabelScaleVisibility(n,t)&&(l=!0))})),l&&(this.graphicsCoreOwner.view.deconflictor.setDirty(),this.graphicsCoreOwner.view.labeler.setDirty())}layerMinMaxScaleChangeHandler(){this.updateScaleRangeActive()&&!this._scaleRangeActive?this.graphicsCore.modifyGraphics3DGraphicVisibilities((e=>e.clearVisibilityFlag(o.SCALE_RANGE))):this._scaleRangeActive&&this.graphicsCore.updateAllGraphicsVisibility(),this._setDirty()}};function b(e,i){return e>0||i>0}e([s()],g.prototype,"graphicsCoreOwner",void 0),e([s()],g.prototype,"layer",void 0),e([s()],g.prototype,"queryGraphicUIDsInExtent",void 0),e([s()],g.prototype,"graphicsCore",void 0),e([s()],g.prototype,"basemapTerrain",void 0),e([s({constructOnly:!0})],g.prototype,"layerScaleEnabled",void 0),e([s({readOnly:!0})],g.prototype,"suspended",void 0),e([s({readOnly:!0})],g.prototype,"updating",null),e([s()],g.prototype,"_dirty",void 0),g=e([l("esri.views.3d.layers.graphics.Graphics3DScaleVisibility")],g);const m="terrain-events",S=c(),_=g;export{_ as default};