@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 1.73 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import has from"../../../../../core/has.js";import{hittestSmallSymbolThreshold as t,AttributeDataType as e,hittestToleranceMobile as s,hittestToleranceDesktop as i,hittestToleranceSmallSymbol as o}from"../definitions.js";import{Effect as r}from"./Effect.js";import{FramebufferBit as n,PixelFormat as l,PixelType as c}from"../../../../webgl/enums.js";class a extends r{constructor(){super(...arguments),this.name=this.constructor.name,this.defines=["hittest"]}dispose(){null!=this._fbo&&this._fbo.dispose()}createOptions({pixelRatio:e},r){if(!r.length)return null;const n=r.shift(),l=n.x,c=n.y;this._outstanding=n;const a=has("esri-mobile");return{type:"hittest",distance:(a?s:i)*e,smallSymbolDistance:(a?s:o)*e,smallSymbolSizeThreshold:t,position:[l,c]}}bind(t){const{context:s,attributeView:i}=t;if(!i.size)return;const o=i.getBlock(e.GPGPU);if(null==o)return;const r=o.getFBO(s);s.setViewport(0,0,i.size,i.size),s.bindFramebuffer(r),s.setColorMask(!0,!0,!0,!0),s.setClearColor(0,0,0,0),s.clear(n.COLOR|n.DEPTH)}unbind(){}draw(t){if(null==this._outstanding)return;const e=this._outstanding;this._outstanding=null,this._resolve(t,e.resolvers)}async _resolve(t,s){const{context:i,attributeView:o}=t,r=o.getBlock(e.GPGPU);if(null==r)return void s.forEach((t=>t.resolve([])));const n=r.getFBO(i),a=new Uint8Array(n.width*n.height*4);try{await n.readPixelsAsync(0,0,n.width,n.height,l.RGBA,c.UNSIGNED_BYTE,a)}catch(u){return void s.forEach((t=>t.resolve([])))}const h=[];for(let e=0;e<a.length;e+=4){const t=e/4;a[e]&&h.push(t)}s.forEach((t=>t.resolve(h)))}}export{a as HittestEffect};