@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 1.64 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{GeohashCell as t}from"./GeohashCell.js";class e{constructor(e){this._fields=e,this._size=0,this._depth=0,this._root=t.create(this._fields,0,0,0)}destroy(){}get size(){return this._size}get depth(){return this._depth}find(t,e,s){return this._root.find(t,e,s,0,0,0)}insert(e,s,i,n,o,h,r){let l=this._root,d=0,c=0,a=0;for(;null!==l;){if(l.insert(e,s,i,n,o,r),d>=h)return;const f=Math.ceil((d+1)/2),u=Math.floor((d+1)/2),x=1-d%2,_=30-(3*f+2*u),p=30-(2*f+3*u),M=(n&7*x+3*(1-x)<<_)>>_,m=(o&3*x+7*(1-x)<<p)>>p,g=M+m*(8*x+4*(1-x));c=c<<3*x+2*(1-x)|M,a=a<<2*x+3*(1-x)|m,null==l.children[g]&&(l.children[g]=t.create(this._fields,c,a,d+1),this._depth=Math.max(this._depth,d+1),this._size+=1),d+=1,l=l.children[g]}}putBins(t,e){for(const s of this.getNodes(e)){const e=t.get(s.id);e?e.merge(s):t.set(s.id,s.clone())}}getNodes(t){const e=[],{geohashBounds:s,level:i}=t;let n=this._root;for(;null!==n;){const t=n.depth,o=n.xNode,h=n.yNode;if(t>=i){e.push(n),n=n.next;continue}const r=Math.ceil((t+1)/2),l=Math.floor((t+1)/2),d=1-t%2,c=30-(3*r+2*l),a=30-(2*r+3*l),f=~((1<<c)-1),u=~((1<<a)-1),x=(s.xLL&f)>>c,_=(s.yLL&u)>>a,p=(s.xTR&f)>>c,M=(s.yTR&u)>>a,m=o<<3*d+2*(1-d),g=h<<2*d+3*(1-d),y=m+8*d+4*(1-d),z=g+4*d+8*(1-d),L=Math.max(m,x),N=Math.max(g,_),B=Math.min(y,p),R=Math.min(z,M);let T=null,j=null;for(let e=N;e<=R;e++)for(let t=L;t<=B;t++){const s=t-m+(e-g)*(8*d+4*(1-d)),i=n.children[s];i&&(T||(T=i,T.next=n.next),j&&(j.next=i),j=i,i.next=n.next)}n=T||n.next}return e}}export{e as GeohashTree};