UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 1.61 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ 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}get usedMemory(){return this._size*t.estimatedMemory}find(t,e,s){return this._root.find(t,e,s,0,0,0)}insert(e,s,i,o,n,h,r){let l=this._root,d=0,c=0,a=0;for(;null!==l;){if(l.insert(e,s,i,o,n,r),d>=h)return;const u=Math.ceil((d+1)/2),f=Math.floor((d+1)/2),_=1-d%2,x=30-(3*u+2*f),m=30-(2*u+3*f),M=(o&7*_+3*(1-_)<<x)>>x,p=(n&3*_+7*(1-_)<<m)>>m,g=M+p*(8*_+4*(1-_));c=c<<3*_+2*(1-_)|M,a=a<<2*_+3*(1-_)|p,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 o=this._root;for(;null!==o;){const t=o.depth,n=o.xNode,h=o.yNode;if(t>=i){e.push(o),o=o.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),u=~((1<<c)-1),f=~((1<<a)-1),_=(s.xLL&u)>>c,x=(s.yLL&f)>>a,m=(s.xTR&u)>>c,M=(s.yTR&f)>>a,p=n<<3*d+2*(1-d),g=h<<2*d+3*(1-d),y=p+8*d+4*(1-d),z=g+4*d+8*(1-d),L=Math.max(p,_),N=Math.max(g,x),B=Math.min(y,m),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-p+(e-g)*(8*d+4*(1-d)),i=o.children[s];i&&(T||(T=i,T.next=o.next),j&&(j.next=i),j=i,i.next=o.next)}o=T||o.next}return e}}export{e as GeohashTree};