UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) • 8.47 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import{isSome as r}from"../../../core/arrayUtils.js";import s from"../../../core/Error.js";import has from"../../../core/has.js";import{getOrCreateMapValue as i}from"../../../core/MapUtils.js";import{debounce as o,throwIfAborted as a}from"../../../core/promiseUtils.js";import{on as n}from"../../../core/reactiveUtils.js";import{sqlAnd as l}from"../../../core/sql.js";import{getMetersPerUnitForSR as p}from"../../../core/unitUtils.js";import{property as c}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import{subclass as u}from"../../../core/accessorSupport/decorators/subclass.js";import y from"../../../geometry/Extent.js";import{getResolutionForScale as h}from"../../../geometry/support/scaleUtils.js";import{collectFields as m}from"../../../layers/support/fieldUtils.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 v from"../../../symbols/SimpleMarkerSymbol.js";import{getRequiredFields as x,getFetchPopupTemplate as j}from"./popupUtils.js";let F=null;function P(e,t){return"tile"===t.type||"map-image"===t.type}let S=class extends t{constructor(e){super(e),this._featuresResolutions=new WeakMap,this.highlightGraphics=null,this.highlightGraphicUpdated=null,this.updateHighlightedFeatures=o((async e=>{this.destroyed||this.updatingHandles.addPromise(this._updateHighlightedFeaturesGeometries(e).catch((()=>{})))}))}initialize(){const e=e=>{for(const t of e){const{sourceLayer:e}=t;null!=e&&"geometryType"in e&&"point"===e.geometryType&&(t.visible=!1)}this.updatingHandles.addPromise(this._updateHighlightedFeaturesSymbols(e).catch((()=>{}))),this.updateHighlightedFeatures(this._highlightGeometriesResolution)};this.addHandles([n((()=>this.highlightGraphics),"change",(t=>e(t.added)),{onListenerAdd:t=>e(t)})])}async fetchPopupFeaturesAtLocation(e,t){const{layerView:{layer:r,view:{scale:i}}}=this;if(!e)throw new s("fetchPopupFeatures:invalid-area","Nothing to fetch without area",{layer:r});const o=U(r.sublayers,i,t);if(!o.length)return[];const a=await G(r,o);if(!((r.capabilities?.operations?.supportsIdentify??!0)&&r.version>=10.5)&&!a)throw new s("fetchPopupFeatures:not-supported","query operation is disabled for this service",{layer:r});return a?this._fetchPopupFeaturesUsingQueries(e,o,t):this._fetchPopupFeaturesUsingIdentify(e,o,t)}clearHighlights(){this.highlightGraphics?.removeAll()}async _updateHighlightedFeaturesSymbols(e){const{layerView:{view:t},highlightGraphics:r,highlightGraphicUpdated:s}=this;if(r&&s)for(const i of e){const e=i.sourceLayer&&"renderer"in i.sourceLayer&&i.sourceLayer.renderer;i.sourceLayer&&"geometryType"in i.sourceLayer&&"point"===i.sourceLayer.geometryType&&e&&"getSymbolAsync"in e&&e.getSymbolAsync(i).then((async o=>{o||=new v;let a=null;const n="visualVariables"in e?e.visualVariables?.find((e=>"size"===e.type)):void 0;n&&(F||(F=(await import("../../../renderers/visualVariables/support/visualVariableUtils.js")).getSize),a=F(n,i,{view:t.type,scale:t.scale,shape:"simple-marker"===o.type?o.style:null})),a||="width"in o&&"height"in o&&null!=o.width&&null!=o.height?Math.max(o.width,o.height):"size"in o?o.size:16,r.includes(i)&&(i.symbol=new v({style:"square",size:a,xoffset:"xoffset"in o?o.xoffset:0,yoffset:"yoffset"in o?o.yoffset:0}),s(i,"symbol"),i.visible=!0)}))}}async _updateHighlightedFeaturesGeometries(e){const{layerView:{layer:t,view:r},highlightGraphics:s,highlightGraphicUpdated:o}=this;if(this._highlightGeometriesResolution=e,!o||!s?.length||!t.capabilities.operations.supportsQuery)return;const a=this._getTargetResolution(e),n=new Map;for(const c of s)if(!this._featuresResolutions.has(c)||this._featuresResolutions.get(c)>a){const e=c.sourceLayer;i(n,e,(()=>new Map)).set(c.getObjectId(),c)}const l=Array.from(n,(([e,t])=>{const s=e.createQuery();return s.objectIds=[...t.keys()],s.outFields=[e.objectIdField],s.returnGeometry=!0,s.maxAllowableOffset=a,s.outSpatialReference=r.spatialReference,e.queryFeatures(s)})),p=await Promise.all(l);if(!this.destroyed)for(const{features:i}of p)for(const e of i){const t=e.sourceLayer,r=n.get(t).get(e.getObjectId());r&&s.includes(r)&&(r.geometry=e.geometry,o(r,"geometry"),this._featuresResolutions.set(r,a))}}_getTargetResolution(e){const t=e*p(this.layerView.view.spatialReference),r=t/16;return r<=10?0:e/t*r}async _fetchPopupFeaturesUsingIdentify(e,t,r){const s=await this._createIdentifyParameters(e,t,r);if(null==s)return[];const{results:i}=await g(this.layerView.layer.parsedUrl,s,r);return i.map((e=>e.feature))}async _createIdentifyParameters(e,t,r){const{floors:s,layer:i,timeExtent:o,view:{spatialReference:a,scale:n}}=this.layerView;if(!t.length)return null;await Promise.all(t.map((({sublayer:e})=>e.load(r).catch((()=>{})))));const l=Math.min(has("mapservice-popup-identify-max-tolerance"),i.allSublayers.reduce(((e,t)=>t.renderer?f({renderer:t.renderer,pointerType:r?.pointerType}):e),2)),p=this.createFetchPopupFeaturesQueryGeometry(e,l),c=h(n,a),u=Math.round(p.width/c),m=new y({xmin:p.center.x-c*u,ymin:p.center.y-c*u,xmax:p.center.x+c*u,ymax:p.center.y+c*u,spatialReference:p.spatialReference});return new w({floors:s,gdbVersion:"gdbVersion"in i?i.gdbVersion:void 0,geometry:e,height:u,layerOption:"popup",mapExtent:m,returnGeometry:!0,spatialReference:a,sublayers:i.sublayers,timeExtent:o,tolerance:l,width:u})}async _fetchPopupFeaturesUsingQueries(e,t,s){const{layerView:{floors:i,timeExtent:o}}=this,n=t.map((async({sublayer:t,popupTemplate:r})=>{if(await t.load(s).catch((()=>{})),t.capabilities&&!t.capabilities.operations.supportsQuery)return[];const n=t.createQuery(),p=f({renderer:t.renderer,pointerType:s?.pointerType}),c=this.createFetchPopupFeaturesQueryGeometry(e,p),u=new Set,[y]=await Promise.all([x(t,r),t.renderer?.collectRequiredFields(u,t.fieldsIndex)]);a(s),m(u,t.fieldsIndex,y);const h=Array.from(u).sort();n.geometry=c,n.outFields=h,n.timeExtent=o;const g=d(i,t);if(n.where=l(n.where,g),t.capabilities?.query.supportsOrderBy&&t.orderBy?.[0]){const e=t.orderBy[0],r=!e.valueExpression&&e.field,s="ascending"===e.order?"asc":"desc";r&&(n.orderByFields=[`${r} ${s}`])}const w=this._getTargetResolution(c.width/p),b=await _(r);a(s);const v="point"===t.geometryType||b&&b.arcadeUtils.hasGeometryOperations(r);v||(n.maxAllowableOffset=w);let{features:j}=await t.queryFeatures(n,s);const F=v?0:w;j=await R(t,j,s);for(const e of j)this._featuresResolutions.set(e,F);return j}));return(await Promise.allSettled(n)).reduce(((e,t)=>"fulfilled"===t.status?[...e,...t.value]:e),[]).filter(r)}};function U(e,t,r){const s=[];if(!e)return s;const i=e=>{const o=0===e.minScale||t<=e.minScale,a=0===e.maxScale||t>=e.maxScale;if(e.visible&&o&&a)if(e.sublayers)e.sublayers.forEach(i);else if(e.popupEnabled){const t=j(e,{...r,defaultPopupTemplateEnabled:!1});null!=t&&s.unshift({sublayer:e,popupTemplate:t})}};return e.map(i),s}function _(e){return e.expressionInfos?.length||Array.isArray(e.content)&&e.content.some((e=>"expression"===e.type))?b():Promise.resolve()}async function G(e,t){if(e.capabilities?.operations?.supportsQuery)return!0;try{return await Promise.any(t.map((({sublayer:e})=>e.load().then((()=>e.capabilities.operations.supportsQuery)))))}catch{return!1}}async function R(e,t,r){const s=e.renderer;return s&&"defaultSymbol"in s&&!s.defaultSymbol&&(t=s.valueExpression?await Promise.all(t.map((e=>s.getSymbolAsync(e,r).then((t=>t?e:null))))).then((e=>e.filter((e=>null!=e)))):t.filter((e=>null!=s.getSymbol(e)))),t}e([c({constructOnly:!0})],S.prototype,"createFetchPopupFeaturesQueryGeometry",void 0),e([c({constructOnly:!0})],S.prototype,"layerView",void 0),e([c({constructOnly:!0})],S.prototype,"highlightGraphics",void 0),e([c({constructOnly:!0})],S.prototype,"highlightGraphicUpdated",void 0),e([c({constructOnly:!0})],S.prototype,"updatingHandles",void 0),S=e([u("esri.views.layers.support.MapServiceLayerViewHelper")],S);export{S as MapServiceLayerViewHelper,U as collectPopupProviders,P as isMapServiceLayerView};