MapImageLayerView.js 7.6 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{_ as e}from"../../chunks/tslib.es6.js";import"../../symbols.js";import t from"../../core/Error.js";import has from"../../core/has.js";import{getOrCreateMapValue as r}from"../../core/MapUtils.js";import{isNone as s,isSome as i}from"../../core/maybe.js";import{debounce as o,eachAlways as a}from"../../core/promiseUtils.js";import{on as n}from"../../core/reactiveUtils.js";import{getMetersPerUnitForSR as l}from"../../core/unitUtils.js";import{property as p}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as u}from"../../core/accessorSupport/decorators/subclass.js";import h from"../../geometry/Extent.js";import{getResolutionForScale as c}from"../../geometry/support/scaleUtils.js";import{combinedViewLayerTimeExtentProperty as m}from"../../layers/support/commonProperties.js";import{ExportImageParameters as y}from"../../layers/support/ExportImageParameters.js";import{getLayerFloorFilterClause as d}from"../../layers/support/floorFilterUtils.js";import{calculateTolerance as f}from"../../renderers/support/clickToleranceUtils.js";import{identify as g}from"../../rest/identify.js";import w from"../../rest/support/IdentifyParameters.js";import{loadArcade as b}from"../../support/arcadeOnDemand.js";import{GraphicsCollection as x}from"../../support/GraphicsCollection.js";import{getRequiredFields as v,getFetchPopupTemplate as P}from"./support/popupUtils.js";import j from"../../symbols/SimpleMarkerSymbol.js";let _=null;const F=F=>{let I=class extends F{constructor(){super(...arguments),this._featuresResolutions=new WeakMap,this.highlightGraphics=new x,this.updateHighlightedFeatures=o((async e=>{this.destroyed||this.updatingHandles.addPromise(this._updateHighlightedFeaturesGeometries(e).catch((()=>{})))}))}initialize(){this.exportImageParameters=new y({layer:this.layer}),this.handles.add([n((()=>this.highlightGraphics),"change",(e=>{this.updatingHandles.addPromise(this._updateHighlightedFeaturesSymbols(e.added).catch((()=>{}))),this.updateHighlightedFeatures(this._highlightGeometriesResolution)}))])}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,r){const{layer:s}=this;if(!e)throw new t("mapimagelayer:fetchPopupFeatures","Nothing to fetch without area",{layer:s});const i=this.layer.capabilities?.operations?.supportsQuery??!0;if(!((this.layer.capabilities?.operations?.supportsIdentify??!0)&&this.layer.version>=10.5)&&!i)throw new t("mapimagelayer:fetchPopupFeatures-not-supported","query operation is disabled for this service",{layer:s});return i?this._fetchPopupFeaturesUsingQueries(e,r):this._fetchPopupFeaturesUsingIdentify(e,r)}canResume(){return!!super.canResume()&&!this.timeExtent?.isEmpty}async _updateHighlightedFeaturesSymbols(e){for(const t of e){const e="renderer"in t.sourceLayer&&t.sourceLayer.renderer;"geometryType"in t.sourceLayer&&"point"===t.sourceLayer.geometryType&&e&&"getSymbolAsync"in e&&e.getSymbolAsync(t).then((async r=>{let s="width"in r&&"height"in r&&null!=r.width&&null!=r.height?Math.max(r.width,r.height):"size"in r?r.size:null;const i="visualVariables"in e&&e.visualVariables?.find((e=>"size"===e.type));i&&(_||(_=(await import("../../renderers/visualVariables/support/visualVariableUtils.js")).getSize),s=_(i,t,{view:this.view.type,scale:this.view.scale,shape:"simple-marker"===r.type?r.style:null})),this.highlightGraphics.includes(t)&&(t.symbol=new j({style:"square",size:s,xoffset:"xoffset"in r?r.xoffset:0,yoffset:"yoffset"in r?r.yoffset:0}),t.visible=!0,this.highlightGraphicUpdated(t,"symbol"))}))}}async _updateHighlightedFeaturesGeometries(e){this._highlightGeometriesResolution=e;const t=this.highlightGraphics;if(!t.length||!this.layer.capabilities.operations.supportsQuery)return;const s=this._getTargetResolution(e),i=new Map;for(const n of t)if(!this._featuresResolutions.has(n)||this._featuresResolutions.get(n)>s){const e=n.sourceLayer;r(i,e,(()=>new Map)).set(n.getObjectId(),n)}const o=Array.from(i,(([e,t])=>{const r=e.createQuery();return r.objectIds=[...t.keys()],r.outFields=[e.objectIdField],r.returnGeometry=!0,r.maxAllowableOffset=s,r.outSpatialReference=this.view.spatialReference,e.queryFeatures(r)})),a=await Promise.all(o);if(!this.destroyed)for(const{features:r}of a)for(const e of r){const t=e.sourceLayer,r=i.get(t).get(e.getObjectId());r&&this.highlightGraphics.includes(r)&&(r.geometry=e.geometry,this.highlightGraphicUpdated(r,"geometry"),this._featuresResolutions.set(r,s))}}_getTargetResolution(e){const t=e*l(this.view.spatialReference),r=t/16;return r<=10?0:e/t*r}async _fetchPopupFeaturesUsingIdentify(e,t){const r=await this._createIdentifyParameters(e,t);if(s(r))return[];const{results:i}=await g(this.layer.parsedUrl,r);return i.map((e=>e.feature))}async _createIdentifyParameters(e,t){const{floors:r,spatialReference:s,scale:o}=this.view,a=i(t)?t.event:null,n=await this._collectPopupProviders(this.layer.sublayers,o,t);if(!n.length)return null;await Promise.all(n.map((({sublayer:e})=>e.load().catch((()=>{})))));const l=Math.min(has("mapimagelayer-popup-identify-max-tolerance"),this.layer.allSublayers.reduce(((e,t)=>t.renderer?f({renderer:t.renderer,event:a}):e),2)),p=this.createFetchPopupFeaturesQueryGeometry(e,l),u=c(o,s),m=Math.round(p.width/u),y=new h({xmin:p.center.x-u*m,ymin:p.center.y-u*m,xmax:p.center.x+u*m,ymax:p.center.y+u*m,spatialReference:p.spatialReference});return new w({floors:r,gdbVersion:this.layer.gdbVersion,geometry:e,height:m,layerOption:"popup",mapExtent:y,returnGeometry:!0,spatialReference:s,sublayers:this.layer.sublayers,timeExtent:this.timeExtent,tolerance:l,width:m})}async _fetchPopupFeaturesUsingQueries(e,t){const r=await this._collectPopupProviders(this.layer.sublayers,this.view.scale,t),s=i(t)?t.event:null,o=r.map((async({sublayer:t,popupTemplate:r})=>{await t.load().catch((()=>{}));const o=t.createQuery(),a=f({renderer:t.renderer,event:s}),n=this.createFetchPopupFeaturesQueryGeometry(e,a);if(o.geometry=n,o.outFields=await v(t,r),o.timeExtent=this.timeExtent,"floors"in this.view){const e=this.view?.floors?.clone(),r=d(e,t);i(r)&&(o.where=o.where?`(${o.where}) AND (${r})`:r)}const l=this._getTargetResolution(n.width/a),p=await this._loadArcadeModules(r),u="point"===t.geometryType||p&&p.arcadeUtils.hasGeometryOperations(r);u||(o.maxAllowableOffset=l);const{features:h}=await t.queryFeatures(o),c=u?0:l;for(const e of h)this._featuresResolutions.set(e,c);return h}));return(await a(o)).reverse().reduce(((e,t)=>t.value?[...e,...t.value]:e),[]).filter((e=>null!=e))}async _collectPopupProviders(e,t,r){const s=[],o=async e=>{const a=0===e.minScale||t<=e.minScale,n=0===e.maxScale||t>=e.maxScale;if(e.visible&&a&&n)if(e.sublayers)e.sublayers.forEach(o);else if(e.popupEnabled){const t=P(e,{...r,defaultPopupTemplateEnabled:!1});i(t)&&s.unshift({sublayer:e,popupTemplate:t})}},a=e.toArray().reverse().map(o);return await Promise.all(a),s}_loadArcadeModules(e){if(e.expressionInfos?.length||Array.isArray(e.content)&&e.content.some((e=>"expression"===e.type)))return b()}};return e([p()],I.prototype,"highlightGraphics",void 0),e([p()],I.prototype,"exportImageParameters",void 0),e([p({readOnly:!0})],I.prototype,"exportImageVersion",null),e([p()],I.prototype,"layer",void 0),e([p()],I.prototype,"suspended",void 0),e([p(m)],I.prototype,"timeExtent",void 0),I=e([u("esri.views.layers.MapImageLayerView")],I),I};export{F as default};