/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as e}from"tslib";import{isSome as t}from"../../core/arrayUtils.js";import r from"../../core/Logger.js";import{abortMaybe as o}from"../../core/maybe.js";import{unwrapUpdating as i,updating as n,isUpdating as l}from"../../core/maybeUpdating.js";import{throwIfAbortError as s,throwIfNotAbortError as a}from"../../core/promiseUtils.js";import{whenOnce as m}from"../../core/reactiveUtils.js";import{property as p,subclass as y}from"../../core/accessorSupport/decorators.js";import{project as u,canProjectWithoutEngine as c,isLoaded as g,load as d}from"../../geometry/projectionUtils.js";import h from"../../layers/support/FeatureFilter.js";import{SceneLayerViewFilter as f}from"../../layers/support/SceneLayerViewFilter.js";import w from"./LayerView.js";let x=class extends w{constructor(e){super(e),this.layer=null,this.filter=null,this._geometryOperators=null,this._projectionEngineLoaded=!1,this._abortController=new AbortController}get availableFields(){return[]}get maximumNumberOfFeatures(){return 0}set maximumNumberOfFeatures(e){throw new Error("Not implemented")}get maximumNumberOfFeaturesExceeded(){return!1}get layerFilter(){return i(this._layerFilter)}get _layerFilter(){const e=this.layer?.filter;if(null==e||e.geometries.length<1)return null;if(!this._geometryOperators||!this._projectionEngineLoaded&&this._filterNeedsProjectionEngine)return n;const[o,i,l]=this._geometryOperators,s=e.geometries.at(0).spatialReference,a=e.geometries.toArray().map(e=>{let t;try{t=i.execute(e)}catch(o){return r.getLogger(this).warnOncePerTick("Failed to simplify scene filter mask polygon. Polygon will be ignored."),null}if(!t)return null;if(t.spatialReference.equals(s))return t;try{return u(t,s)}catch(o){return r.getLogger(this).warnOncePerTick("Failed to project scene filter mask polygon. Polygon will be ignored."),null}}).filter(t).sort((e,t)=>e.extent.xmin-t.extent.xmin),m=new Set,p=new Array,y=new Array;for(let t of a){const e=t.extent.xmin;if(p.length=0,m.forEach(r=>{if(e>=r.extent.xmax)return y.push(r),void m.delete(r);t.extent.ymin<=r.extent.ymax&&t.extent.ymax>=r.extent.ymin&&o.execute(t,r)&&p.push(r)}),p.length>0){let e;p.push(t);try{e=l.executeMany(p)}catch(c){r.getLogger(this).warnOncePerTick("Failed to unify filter mask polygons. Polygon will be ignored.");continue}p.pop(),e&&(p.forEach(e=>m.delete(e)),t=e)}m.add(t)}return m.forEach(e=>y.push(e)),y.length>0?new f(y,e.spatialRelationship):null}get _filterNeedsProjectionEngine(){const e=this.layer.filter;if(null==e||e.geometries.length<=1)return!1;const t=e.geometries.at(0).spatialReference;return e.geometries.some(({spatialReference:e})=>!e.equals(t)&&!c(e,t))}get layerFilterUpdating(){return l(this._layerFilter)}initialize(){const{signal:e}=this._abortController;m(()=>this.destroyed||!this._geometryOperators&&this.layer?.filter?.geometries?.length,e).then(async()=>{s(e),this._geometryOperators=await Promise.all([import("../../geometry/operators/intersectsOperator.js"),import("../../geometry/operators/simplifyOperator.js"),import("../../geometry/operators/unionOperator.js")])}).catch(a),this._projectionEngineLoaded=g(),m(()=>this.destroyed||!this._projectionEngineLoaded&&this._filterNeedsProjectionEngine,e).then(async()=>{s(e),await d(),this._projectionEngineLoaded=!0}).catch(a)}destroy(){this._abortController=o(this._abortController)}highlight(e,t){throw new Error("Not implemented")}queryFeatures(e,t){throw new Error("Not implemented")}queryObjectIds(e,t){throw new Error("Not implemented")}queryFeatureCount(e,t){throw new Error("Not implemented")}createQuery(){throw new Error("Not implemented")}queryExtent(e,t){throw new Error("Not implemented")}};e([p()],x.prototype,"layer",void 0),e([p()],x.prototype,"availableFields",null),e([p()],x.prototype,"maximumNumberOfFeatures",null),e([p({readOnly:!0})],x.prototype,"maximumNumberOfFeaturesExceeded",null),e([p({type:h})],x.prototype,"filter",void 0),e([p({readOnly:!0})],x.prototype,"layerFilter",null),e([p({readOnly:!0})],x.prototype,"_layerFilter",null),e([p()],x.prototype,"_geometryOperators",void 0),e([p()],x.prototype,"_projectionEngineLoaded",void 0),e([p()],x.prototype,"_filterNeedsProjectionEngine",null),e([p()],x.prototype,"layerFilterUpdating",null),x=e([y("esri.views.layers.SceneLayerView")],x);const j=x;export{j as default};
