12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.24/esri/copyright.txt for details.
- */
- const t=16,n=8,o=4,e=2,r=1,c=new Float64Array(2),h=new Float64Array(2),f=-90,l=90,a=-180,u=180,s="0123456789bcdefghjkmnpqrstuvwxyz";function i(t){return t<=57?t-48:t<=104?t-88:t<=107?t-89:t<=110?t-90:t-91}function M(t){return s[t]}function g(t){return(t[0]+t[1])/2}function b(t,n,o){return t[0]=n,t[1]=o,t}function A(t,n){const o=g(t),e=n,r=!n;t[0]=r*t[0]+e*o,t[1]=r*o+e*t[1]}function m(t,n){const o=n>g(t);return A(t,o),o}function d(s,M){const m=b(c,f,l),d=b(h,a,u);for(let c=0;c<M.length;c++){const h=i(M.charCodeAt(c));c%2==0?(A(d,!!(t&h)),A(d,!!(o&h)),A(d,!!(r&h)),A(m,!!(n&h)),A(m,!!(e&h))):(A(m,!!(t&h)),A(m,!!(o&h)),A(m,!!(r&h)),A(d,!!(n&h)),A(d,!!(e&h)))}return s[0]=g(m),s[1]=g(d),s}function w(t,n){let o=0,e=0,r=30,c=30;for(let h=0;h<n.length;h++){const t=i(n.charCodeAt(h)),f=h%2==0;r-=f?3:2,c-=f?2:3,o|=j(t,f)<<r,e|=k(t,f)<<c}return{geohashX:o,geohashY:e}}function x(t,n){let o=-90,e=90,r=-180,c=180;for(let h=0;h<n;h++){const n=Math.ceil((h+1)/2),f=Math.floor((h+1)/2),l=1-h%2,a=30-(3*n+2*f),u=30-(2*n+3*f),s=3*l+2*(1-l),i=2*l+3*(1-l),M=3*l+7*(1-l)<<u,g=(7*l+3*(1-l)<<a&t.geohashX)>>a,b=(M&t.geohashY)>>u;for(let t=s-1;t>=0;t--){const n=(r+c)/2,o=g&1<<t?1:0;r=(1-o)*r+o*n,c=(1-o)*n+o*c}for(let t=i-1;t>=0;t--){const n=(o+e)/2,r=b&1<<t?1:0;o=(1-r)*o+r*n,e=(1-r)*n+r*e}}return[r,o,c,e]}function y(t,n,o,e){e%2&&(e+=1);let r=0,c=0,h=-90,f=90,l=-180,a=180;for(let u=0;u<e/2;u++){for(let t=0;t<5;t++){const n=(l+a)/2,e=o>n?1:0;r|=e<<29-(t+5*u),l=(1-e)*l+e*n,a=(1-e)*n+e*a}for(let t=0;t<5;t++){const o=(h+f)/2,e=n>o?1:0;c|=e<<29-(t+5*u),h=(1-e)*h+e*o,f=(1-e)*o+e*f}}t.geohashX=r,t.geohashY=c}function p(t,n,o,e,r){r%2&&(r+=1);let c=0,h=0,f=-90,l=90,a=-180,u=180;for(let s=0;s<r/2;s++){for(let t=0;t<5;t++){const n=(a+u)/2,o=e>n?1:0;c|=o<<29-(t+5*s),a=(1-o)*a+o*n,u=(1-o)*n+o*u}for(let t=0;t<5;t++){const n=(f+l)/2,e=o>n?1:0;h|=e<<29-(t+5*s),f=(1-e)*f+e*n,l=(1-e)*n+e*l}}t[2*n]=c,t[2*n+1]=h}function C(t,n,o){let e="";const r=b(c,-90,90),f=b(h,-180,180);for(let c=0;c<o;c++){let o=0;!(c%2)?(o|=m(f,n)<<4,o|=m(r,t)<<3,o|=m(f,n)<<2,o|=m(r,t)<<1,o|=m(f,n)<<0):(o|=m(r,t)<<4,o|=m(f,n)<<3,o|=m(r,t)<<2,o|=m(f,n)<<1,o|=m(r,t)<<0),e+=M(o)}return e}function X(t){const n=Math.floor(5*t/2);return(l-f)/2**n}function Y(t){const n=Math.ceil(5*t/2);return(u-a)/2**n}function F(t,n,c){return c?t&r|(n&r)<<1|(t&e)<<1|(n&e)<<2|(t&o)<<2:n&r|(t&r)<<1|(n&e)<<1|(t&e)<<2|(n&o)<<2}function j(c,h){return h?r&c|(o&c)>>1|(t&c)>>2:(e&c)>>1|(n&c)>>2}function k(c,h){return h?(e&c)>>1|(n&c)>>2:r&c|(o&c)>>1|(t&c)>>2}function q(c,h,f){const l=!((c.length-1)%2),a=c.substring(0,c.length-1),u=i(c.charCodeAt(c.length-1));let s=0,g=0,b=0,A=0;l?(s=8,g=4,b=r&u|(o&u)>>1|(t&u)>>2,A=(e&u)>>1|(n&u)>>2):(s=4,g=8,A=r&u|(o&u)>>1|(t&u)>>2,b=(e&u)>>1|(n&u)>>2);const m=b+h,d=A+f,w=Math.floor(m/s),x=Math.floor(d/g),y=M(F(m-w*s,d-x*g,l));return c.length>1&&(w||x)?q(a,w,x)+y:a+y}function v(t,n,o,e,r){const c=Math.abs(o-t),h=Math.abs(e-n),f=X(r),l=Y(r),a=Math.ceil(h/l),u=Math.ceil(c/f),s=C(t,n,r),i=new Array;for(let M=0;M<a;M++)for(let t=0;t<u;t++)i.push(q(s,M,t));return i}function z(t,n,o,e,r,c){const h=Math.abs(o-t),f=Math.abs(e-n),l=X(r),a=Y(r),u=Math.ceil(f/a),s=Math.ceil(h/l),i=C(t,n,r);for(let M=0;M<u;M++)for(let r=0;r<s;r++){const h=q(i,M,r),[f,u]=d([0,0],h),s=f-l/2,g=u-a/2,b=f+l/2,A=u+a/2,m=l*a,w=Math.max(t,s),x=Math.max(n,g),y=Math.min(o,b)-w,p=Math.min(e,A)-x;c(h,Math.abs(y*p)/m)}}export{w as convertGeohash32ToXY,i as decodeBase32Char,d as decodeGeohash,x as decodeGeohashXY,M as encodeBase32Char,C as encodeGeohash,z as forEachIntersectingGeohash,v as getIntersectingGeohashes,q as getRelativeGeohash,X as latDistPerGeohash,Y as lonDistPerGeohash,p as setGeohashBuf,y as setGeohashXY,j as unpackXBits,k as unpackYBits};
|