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