UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 1.55 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import has from"../../../../../core/has.js";import{hittestSmallSymbolThreshold as t,hittestToleranceMobile as e,hittestToleranceDesktop as s,hittestToleranceSmallSymbol as i}from"../definitions.js";import{Effect as o}from"./Effect.js";import{PixelType as r}from"../../../../webgl/enums.js";class n extends o{constructor(){super(...arguments),this.name=this.constructor.name,this.defines=["hittest"]}dispose(){null!=this._fbo&&this._fbo.dispose()}createOptions({pixelRatio:o},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)*o,smallSymbolDistance:(a?e:i)*o,smallSymbolSizeThreshold:t,position:[l,c]}}bind(t){const{context:e,attributeView:s}=t;if(!s.size)return;const i=s.getBlock(2);if(null==i)return;const o=i.getFBO(e);e.setViewport(0,0,s.size,s.size),e.bindFramebuffer(o),e.setColorMask(!0,!0,!0,!0),e.setClearColor(0,0,0,0),e.clear(16640)}unbind(){}draw(t){if(null==this._outstanding)return;const e=this._outstanding;this._outstanding=null,this._resolve(t,e.resolvers)}async _resolve(t,e){const{context:s,attributeView:i}=t,o=i.getBlock(2);if(null==o)return void e.forEach(t=>t.resolve([]));const n=o.getFBO(s),l=new Uint8Array(n.width*n.height*4);try{await n.readPixelsAsync(0,0,n.width,n.height,6408,r.UNSIGNED_BYTE,l)}catch(a){return void e.forEach(t=>t.resolve([]))}const c=[];for(let r=0;r<l.length;r+=4){const t=r/4;l[r]&&c.push(t)}e.forEach(t=>t.resolve(c))}}export{n as HittestEffect};