MapImageLayerView.js 5.0 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.24/esri/copyright.txt for details.
  4. */
  5. import{_ as e}from"../../chunks/tslib.es6.js";import r from"../../core/Error.js";import t from"../../core/has.js";import{isNone as s,isSome as a}from"../../core/maybe.js";import{eachAlways as o}from"../../core/promiseUtils.js";import{property as i}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as p}from"../../core/accessorSupport/decorators/subclass.js";import n from"../../geometry/Extent.js";import{getResolutionForScale as l}from"../../geometry/support/scaleUtils.js";import{combinedViewLayerTimeExtentProperty as m}from"../../layers/support/commonProperties.js";import{ExportImageParameters as c}from"../../layers/support/ExportImageParameters.js";import{getLayerFloorFilterClause as u}from"../../layers/support/floorFilterUtils.js";import{calculateTolerance as y}from"../../renderers/support/clickToleranceUtils.js";import{identify as h}from"../../rest/identify.js";import f from"../../rest/support/IdentifyParameters.js";import{loadArcade as d}from"../../support/arcadeOnDemand.js";import{getRequiredFields as w,getFetchPopupTemplate as P}from"./support/popupUtils.js";const x=x=>{let g=class extends x{initialize(){this.exportImageParameters=new c({layer:this.layer})}destroy(){this.exportImageParameters.destroy(),this.exportImageParameters=null}get exportImageVersion(){return this.exportImageParameters?.commitProperty("version"),this.commitProperty("timeExtent"),(this._get("exportImageVersion")||0)+1}async fetchPopupFeatures(e,t){const{layer:s}=this;if(!e)throw new r("mapimagelayer:fetchPopupFeatures","Nothing to fetch without area",{layer:s});const a=this.layer.capabilities?.operations?.supportsQuery??!0;if(!((this.layer.capabilities?.operations?.supportsIdentify??!0)&&this.layer.version>=10.5)&&!a)throw new r("mapimagelayer:fetchPopupFeatures-not-supported","query operation is disabled for this service",{layer:s});return a?this._fetchPopupFeaturesUsingQueries(e,t):this._fetchPopupFeaturesUsingIdentify(e,t)}canResume(){return!!super.canResume()&&!this.timeExtent?.isEmpty}async _fetchPopupFeaturesUsingIdentify(e,r){const t=await this._createIdentifyParameters(e,r);if(s(t))return[];const{results:a}=await h(this.layer.parsedUrl,t);return a.map((e=>e.feature))}async _createIdentifyParameters(e,r){const{floors:s,spatialReference:o,scale:i}=this.view,p=a(r)?r.event:null,m=await this._collectPopupProviders(this.layer.sublayers,i,r);if(!m.length)return null;await Promise.all(m.map((({sublayer:e})=>e.load().catch((()=>{})))));const c=Math.min(t("mapimagelayer-popup-identify-max-tolerance"),this.layer.allSublayers.reduce(((e,r)=>r.renderer?y({renderer:r.renderer,event:p}):e),2)),u=this.createFetchPopupFeaturesQueryGeometry(e,c),h=l(i,o),d=Math.round(u.width/h),w=new n({xmin:u.center.x-h*d,ymin:u.center.y-h*d,xmax:u.center.x+h*d,ymax:u.center.y+h*d,spatialReference:u.spatialReference}),P=!1===this.layer.capabilities?.operations?.supportsQuery||await new Promise((e=>{let r=!1;Promise.all(m.map((async({popupTemplate:t})=>{if(t){const s=await this._loadArcadeModules(t);if(r)return;const a=s?.arcadeUtils.hasGeometryOperations(t);a&&(r=!0,e(!0))}}))).finally((()=>e(!1)))}));return new f({floors:s,gdbVersion:this.layer.gdbVersion,geometry:e,height:d,layerOption:"popup",mapExtent:w,maxAllowableOffset:P?0:h,returnGeometry:!0,spatialReference:o,sublayers:this.layer.sublayers,timeExtent:this.timeExtent,tolerance:c,width:d})}async _fetchPopupFeaturesUsingQueries(e,r){const t=await this._collectPopupProviders(this.layer.sublayers,this.view.scale,r),s=a(r)?r.event:null,i=t.map((async({sublayer:r,popupTemplate:t})=>{await r.load().catch((()=>{}));const o=r.createQuery(),i=y({renderer:r.renderer,event:s}),p=this.createFetchPopupFeaturesQueryGeometry(e,i);if(o.geometry=p,o.outFields=await w(r,t),"floors"in this.view){const e=this.view?.floors?.clone(),t=u(e,r);a(t)&&(o.where=o.where?`(${o.where}) AND (${t})`:t)}const n=await this._loadArcadeModules(t);n&&n.arcadeUtils.hasGeometryOperations(t)||(o.maxAllowableOffset=p.width/i);return(await r.queryFeatures(o)).features}));return(await o(i)).reduce(((e,r)=>r.value?[...e,...r.value]:e),[]).filter((e=>null!=e))}async _collectPopupProviders(e,r,t){const s=[],o=async e=>{const i=0===e.minScale||r<=e.minScale,p=0===e.maxScale||r>=e.maxScale;if(e.visible&&i&&p)if(e.sublayers)e.sublayers.forEach(o);else if(e.popupEnabled){const r=P(e,{...t,defaultPopupTemplateEnabled:!1});a(r)&&s.unshift({sublayer:e,popupTemplate:r})}},i=e.toArray().reverse().map(o);return await Promise.all(i),s}_loadArcadeModules(e){if(e.expressionInfos?.length||Array.isArray(e.content)&&e.content.some((e=>"expression"===e.type)))return d()}};return e([i()],g.prototype,"exportImageParameters",void 0),e([i({readOnly:!0})],g.prototype,"exportImageVersion",null),e([i()],g.prototype,"layer",void 0),e([i()],g.prototype,"suspended",void 0),e([i(m)],g.prototype,"timeExtent",void 0),g=e([p("esri.views.layers.MapImageLayerView")],g),g};export{x as default};