UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 6.4 kB
/* 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 i from"../../../../core/Accessor.js";import t from"../../../../core/Logger.js";import{property as r}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/RandomLCG.js";import{subclass as s}from"../../../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as a}from"../../../../core/support/UpdatingHandles.js";import{projectBoundingRect as l}from"../../../../geometry/projection/projectBoundingRect.js";import{create as n}from"../../../../geometry/support/aaBoundingRect.js";import{VisibilityGroup as c,VisibilityFlag as o}from"./enums.js";import{scaleBoundsPredicate as h}from"../../../support/layerViewUtils.js";import{TaskPriority as p}from"../../../support/Scheduler.js";import{Yield as d}from"../../../support/Yield.js";let u=class extends i{constructor(e){super(e),this._scaleRangeActive=!1,this._layerScaleRangeVisibilityQuery=!1,this._extent=null,this._updatingHandles=new a,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.addHandles(e.registerTask(p.SCALE_VISIBILITY,this)),this._updatingHandles.add((()=>this.layer.effectiveScaleRange),(()=>this.layerMinMaxScaleChangeHandler()))}destroy(){this._updatingHandles.destroy(),this.removeHandles(),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=n();l(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&&g(i.minScale,i.maxScale);e.labelingInfo&&!t&&(t=e.labelingInfo.some((e=>e&&g(e.minScale??0,e.maxScale??0))));const r=this._scaleRangeActive!==t;return this._scaleRangeActive=t,t&&!this.hasHandles(y)&&this.basemapTerrain?(this.addHandles(this.basemapTerrain.on("scale-change",(e=>this._scaleUpdateHandler(e))),y),this.layerScaleEnabled&&this.addHandles(this.basemapTerrain.on("tiles-visibility-changed",(()=>this._setDirty())),y)):!t&&this.hasHandles(y)&&this.removeHandles(y),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;{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||h(e,i.minScale||0,i.maxScale||0)}_visibleAtLabelScale(e,i){return h(e,i.minScale||0,i.maxScale||0)}_graphicScale(e){let i;if(null!=e.centroid?i=e.centroid:null!=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)return!1;const i=this._graphicVisible(e);return e.setVisibilityFlag(c.GRAPHIC,o.SCALE_RANGE,i)}updateGraphicLabelScaleVisibility(e){if(!this._scaleRangeActive)return!1;if(!e.labelLayers.length)return!1;const i=this._graphicScale(e),t=this._updateLabelScaleVisibility(e,i);return t&&(this.graphicsCore.deconflictor?.setDirty(),this.graphicsCore.labeler?.setDirty()),t}_updateLabelScaleVisibility(e,i){if(!e.labelLayers.length)return!1;const t=e.labelLayers[0].labelClass;if(null!=t?.minScale&&null!=t.maxScale){const r=this._visibleAtLabelScale(i,t);if(e.setVisibilityFlag(c.LABEL,o.SCALE_RANGE,r))return!0}return!1}_scaleUpdateHandler(e){if(this._setDirty(),!this.graphicsCore.visible)return;const i=e.extent,r=e.scale,s=this._visibleAtLayerScale(r);let a=!1;const n=this.graphicsCoreOwner.view.spatialReference,h=e.spatialReference;if(null==h)return void t.getLogger(this).error("scaleUpdate: Internal error, no SpatialReference given for tiles");const p=!h.equals(n);if(p){if(!l(i,h,m,n))return void t.getLogger(this).error("scaleUpdate: Internal error, cannot project AABR from "+h+" to wkid "+n)}const d=p?m:i;this.queryGraphicUIDsInExtent(d,n,(e=>{const t=this.graphicsCore.getGraphics3DGraphicById(e);if(null==t)return;const l=t.centroid;null!=l&&(i[0]>l.x||i[1]>l.y||i[2]<l.x||i[3]<l.y)||(t.setVisibilityFlag(c.GRAPHIC,o.SCALE_RANGE,s)&&(a=!0),this._updateLabelScaleVisibility(t,r)&&(a=!0))})),a&&(this.graphicsCore.deconflictor?.setDirty(),this.graphicsCore.labeler?.setDirty())}layerMinMaxScaleChangeHandler(){this.updateScaleRangeActive()&&!this._scaleRangeActive?this.graphicsCore.modifyGraphics3DGraphicVisibilities((e=>e.setVisibilityFlag(c.GRAPHIC,o.SCALE_RANGE,!0))):this._scaleRangeActive&&this.graphicsCore.updateGraphicsVisibilities(),this._setDirty()}};function g(e,i){return e>0||i>0}e([r()],u.prototype,"graphicsCoreOwner",void 0),e([r()],u.prototype,"layer",void 0),e([r()],u.prototype,"queryGraphicUIDsInExtent",void 0),e([r()],u.prototype,"graphicsCore",void 0),e([r()],u.prototype,"basemapTerrain",void 0),e([r({constructOnly:!0})],u.prototype,"layerScaleEnabled",void 0),e([r({readOnly:!0})],u.prototype,"suspended",void 0),e([r({readOnly:!0})],u.prototype,"updating",null),e([r()],u.prototype,"_dirty",void 0),u=e([s("esri.views.3d.layers.graphics.Graphics3DScaleVisibility")],u);const y="terrain-events",m=n();export{u as Graphics3DScaleVisibility};