UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 6.04 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import i from"../../../../core/Accessor.js";import t from"../../../../core/Logger.js";import{property as r,subclass as a}from"../../../../core/accessorSupport/decorators.js";import{UpdatingHandles as s}from"../../../../core/support/UpdatingHandles.js";import{projectBoundingRect as l}from"../../../../geometry/projection/projectBoundingRect.js";import{create as n}from"../../../../geometry/support/aaBoundingRect.js";import{scaleBoundsPredicate as c}from"../../../support/layerViewUtils.js";import{TaskPriority as h}from"../../../support/Scheduler.js";import{Yield as o}from"../../../support/Yield.js";let p=class extends i{constructor(e){super(e),this._scaleRangeActive=!1,this._layerScaleRangeVisibilityQuery=!1,this._extent=null,this._updatingHandles=new s,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(h.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&&d(i.minScale,i.maxScale);e.labelingInfo&&!t&&(t=e.labelingInfo.some(e=>e&&d(e.minScale??0,e.maxScale??0)));const r=this._scaleRangeActive!==t;return this._scaleRangeActive=t,t&&!this.hasHandles(g)&&this.basemapTerrain?(this.addHandles(this.basemapTerrain.on("scale-change",e=>this._scaleUpdateHandler(e)),g),this.layerScaleEnabled&&this.addHandles(this.basemapTerrain.on("tiles-visibility-changed",()=>this._setDirty()),g)):!t&&this.hasHandles(g)&&this.removeHandles(g),r}get readyToRun(){return!(!this.graphicsCoreOwner.view.basemapTerrain||!this.updating)}runTask(e){const{groundView:i}=this.graphicsCoreOwner.view;if(this._extent&&i&&i.ready&&this._scaleRangeActive&&this.layerScaleEnabled){if(this._layerScaleRangeVisibilityQuery)return o;{this._layerScaleRangeVisibilityQuery=!0;const{minScale:e,maxScale:i}=this.layer.effectiveScaleRange;this.graphicsCoreOwner.view.basemapTerrain.queryVisibleScaleRange(this._extent,e,i,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||c(e,i.minScale||0,i.maxScale||0)}_visibleAtLabelScale(e,i){return c(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(1,2,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(16,2,r))return!0}return!1}_scaleUpdateHandler(e){if(this._setDirty(),!this.graphicsCore.visible)return;const i=e.extent,r=e.scale,a=this._visibleAtLayerScale(r);let s=!1;const n=this.graphicsCoreOwner.view.spatialReference,c=e.spatialReference;if(null==c)return void t.getLogger(this).error("scaleUpdate: Internal error, no SpatialReference given for tiles");const h=!c.equals(n);if(h){if(!l(i,c,u,n))return void t.getLogger(this).error("scaleUpdate: Internal error, cannot project AABR from "+c+" to wkid "+n)}const o=h?u:i;this.queryGraphicUIDsInExtent(o,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(1,2,a)&&(s=!0),this._updateLabelScaleVisibility(t,r)&&(s=!0))}),s&&(this.graphicsCore.deconflictor?.setDirty(),this.graphicsCore.labeler?.setDirty())}layerMinMaxScaleChangeHandler(){this.updateScaleRangeActive()&&!this._scaleRangeActive?this.graphicsCore.modifyGraphics3DGraphicVisibilities(e=>e.setVisibilityFlag(1,2,!0)):this._scaleRangeActive&&this.graphicsCore.updateGraphicsVisibilities(),this._setDirty()}};function d(e,i){return e>0||i>0}e([r()],p.prototype,"graphicsCoreOwner",void 0),e([r()],p.prototype,"layer",void 0),e([r()],p.prototype,"queryGraphicUIDsInExtent",void 0),e([r()],p.prototype,"graphicsCore",void 0),e([r()],p.prototype,"basemapTerrain",void 0),e([r({constructOnly:!0})],p.prototype,"layerScaleEnabled",void 0),e([r({readOnly:!0})],p.prototype,"suspended",void 0),e([r({readOnly:!0})],p.prototype,"updating",null),e([r()],p.prototype,"_dirty",void 0),p=e([a("esri.views.3d.layers.graphics.Graphics3DScaleVisibility")],p);const g="terrain-events",u=n();export{p as Graphics3DScaleVisibility};