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