UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 1.61 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{isIntegratedMeshLayer as e}from"../../../layers/support/layerUtils.js";import{LayerClass as a}from"../terrain/LayerClass.js";import{hitTestSelectSimilarDistance as r}from"../../support/hitTestSelectUtils.js";async function t(a,t){const{results:o,ground:l}=await r(a,t),p=(!l.layer||!e(l.layer.type))&&l.mapPoint,y=[],c=i(a),u=p?s(a,c):n;let d=0,f=0;const m=()=>{const e=u.layerViews[f];p&&e&&"fetchPopupFeaturesAtLocation"in e&&y.push({mapPoint:l.mapPoint,layerView:e}),++f};let h=null;for(;d<o.length||f<u.layerViews.length;){const e=o[d];if(e&&"graphic"!==e.type)++d;else if("scene"!==e?.layer?.type||e?.layer?.parent!==a?.map?.basemap)if(e){const a=e.layer?.uid,r=u.layerUids.has(a)&&e.distance===l.distance,t=c.get(e.layer?.uid);if(h??=e.mapPoint,f<u.layerViews.length&&(r||(e.distance??0)>l.distance)&&u.layerViews[f]!==t){m();continue}y.push({graphic:e.graphic,layerView:t}),++d}else m();else++d}return h??=l.mapPoint,{hits:y,location:h}}function s(e,r){const t=new Set,s=[];for(let i=e.basemapTerrain.numLayers(a.MAP)-1;i>=0;i--){const r=e.basemapTerrain.layerViewByIndex(i,a.MAP);t.add(r.layer.uid),s.push(r)}const n=e.basemapTerrain.overlayManager.renderer.layers;for(const{uid:a}of n){const e=r.get(a);e&&(t.add(a),s.push(e))}return s.reverse(),{layerUids:t,layerViews:s}}const n={layerUids:new Set,layerViews:[]};function i(e){const a=new Map;for(const r of e.allLayerViews){const e=r.layer.uid;a.set(e,r)}return a}export{t as popupHitTest};