@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 4.31 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import"../core/has.js";import{rad2deg as t}from"../core/mathUtils.js";import o from"../geometry/Polygon.js";import r from"../geometry/SpatialReference.js";import{toExtent as n}from"../geometry/support/aaBoundingRect.js";import{earth as e}from"../geometry/support/Ellipsoid.js";import{convertFromPolygon as s}from"../layers/graphics/featureConversionUtils.js";import c from"../layers/graphics/OptimizedGeometry.js";import{project as i}from"../layers/graphics/data/projectionSupport.js";const f=16,a=8,l=4,u=2,h=1,m=new Float64Array(2),p=new Float64Array(2),g=-90,y=90,d=-180,x=180,M="0123456789bcdefghjkmnpqrstuvwxyz",j=64;function S(t,e,f,a){const l=[t.xmin,t.ymin,t.xmax,t.ymax],u=o.fromExtent(n(l,a)),h=i(u,a,r.WGS84,{densificationStep:e*j});if(!h)return null;const m=s(new c,h,!1,!1),p=m.coords.filter(((t,o)=>!(o%2))),g=m.coords.filter(((t,o)=>o%2)),y=Math.min(...p),d=Math.min(...g),x=Math.max(...p),M=Math.max(...g),S=A(y,d,f,r.WGS84),G=A(x,M,f,r.WGS84);return S&&G?{bounds:l,geohashBounds:{xLL:S[0],yLL:S[1],xTR:G[0],yTR:G[1]},level:f}:null}function A(o,n,s,c){if(c.isWebMercator){const r=t(o/e.radius),c=r-360*Math.floor((r+180)/360),i=[0,0];return z(i,0,t(Math.PI/2-2*Math.atan(Math.exp(-n/e.radius))),c,s),i}const f=i({x:o,y:n},c,r.WGS84);if(!f)return null;const a=[0,0];return z(a,0,f.y,f.x,s),a}function G(t){return t<=57?t-48:t<=104?t-88:t<=107?t-89:t<=110?t-90:t-91}function W(t){return M[t]}function w(t){return(t[0]+t[1])/2}function C(t,o,r){return t[0]=o,t[1]=r,t}function L(t,o){const r=w(t),n=o,e=!o;t[0]=e*t[0]+n*r,t[1]=e*r+n*t[1]}function R(t,o){const r=o>w(t);return L(t,r),r}function b(t,o){const r=C(m,g,y),n=C(p,d,x);for(let e=0;e<o.length;e++){const t=G(o.charCodeAt(e));e%2==0?(L(n,!!(f&t)),L(n,!!(l&t)),L(n,!!(h&t)),L(r,!!(a&t)),L(r,!!(u&t))):(L(r,!!(f&t)),L(r,!!(l&t)),L(r,!!(h&t)),L(n,!!(a&t)),L(n,!!(u&t)))}return t[0]=w(r),t[1]=w(n),t}function v(t,o){let r=0,n=0,e=30,s=30;for(let c=0;c<o.length;c++){const t=G(o.charCodeAt(c)),i=c%2==0;e-=i?3:2,s-=i?2:3,r|=F(t,i)<<e,n|=P(t,i)<<s}return{geohashX:r,geohashY:n}}function X(t,o){let r=-90,n=90,e=-180,s=180;for(let c=0;c<o;c++){const o=Math.ceil((c+1)/2),i=Math.floor((c+1)/2),f=1-c%2,a=30-(3*o+2*i),l=30-(2*o+3*i),u=3*f+2*(1-f),h=2*f+3*(1-f),m=3*f+7*(1-f)<<l,p=(7*f+3*(1-f)<<a&t.geohashX)>>a,g=(m&t.geohashY)>>l;for(let t=u-1;t>=0;t--){const o=(e+s)/2,r=p&1<<t?1:0;e=(1-r)*e+r*o,s=(1-r)*o+r*s}for(let t=h-1;t>=0;t--){const o=(r+n)/2,e=g&1<<t?1:0;r=(1-e)*r+e*o,n=(1-e)*o+e*n}}return[e,r,s,n]}function Y(t,o,r,n){n%2&&(n+=1);let e=0,s=0,c=-90,i=90,f=-180,a=180;for(let l=0;l<n/2;l++){for(let t=0;t<5;t++){const o=(f+a)/2,n=r>o?1:0;e|=n<<29-(t+5*l),f=(1-n)*f+n*o,a=(1-n)*o+n*a}for(let t=0;t<5;t++){const r=(c+i)/2,n=o>r?1:0;s|=n<<29-(t+5*l),c=(1-n)*c+n*r,i=(1-n)*r+n*i}}t.geohashX=e,t.geohashY=s}function z(t,o,r,n,e){e%2&&(e+=1);let s=0,c=0,i=-90,f=90,a=-180,l=180;for(let u=0;u<e/2;u++){for(let t=0;t<5;t++){const o=(a+l)/2,r=n>o?1:0;s|=r<<29-(t+5*u),a=(1-r)*a+r*o,l=(1-r)*o+r*l}for(let t=0;t<5;t++){const o=(i+f)/2,n=r>o?1:0;c|=n<<29-(t+5*u),i=(1-n)*i+n*o,f=(1-n)*o+n*f}}t[2*o]=s,t[2*o+1]=c}function B(t,o,r){let n="";const e=C(m,-90,90),s=C(p,-180,180);for(let c=0;c<r;c++){let r=0;!(c%2)?(r|=R(s,o)<<4,r|=R(e,t)<<3,r|=R(s,o)<<2,r|=R(e,t)<<1,r|=R(s,o)|0):(r|=R(e,t)<<4,r|=R(s,o)<<3,r|=R(e,t)<<2,r|=R(s,o)<<1,r|=R(e,t)|0),n+=W(r)}return n}function E(t,o,r){return r?t&h|(o&h)<<1|(t&u)<<1|(o&u)<<2|(t&l)<<2:o&h|(t&h)<<1|(o&u)<<1|(t&u)<<2|(o&l)<<2}function F(t,o){return o?h&t|(l&t)>>1|(f&t)>>2:(u&t)>>1|(a&t)>>2}function P(t,o){return o?(u&t)>>1|(a&t)>>2:h&t|(l&t)>>1|(f&t)>>2}function T(t,o,r){const n=!((t.length-1)%2),e=t.slice(0,-1),s=G(t.charCodeAt(t.length-1));let c=0,i=0,m=0,p=0;n?(c=8,i=4,m=h&s|(l&s)>>1|(f&s)>>2,p=(u&s)>>1|(a&s)>>2):(c=4,i=8,p=h&s|(l&s)>>1|(f&s)>>2,m=(u&s)>>1|(a&s)>>2);const g=m+o,y=p+r,d=Math.floor(g/c),x=Math.floor(y/i),M=W(E(g-d*c,y-x*i,n));return t.length>1&&(d||x)?T(e,d,x)+M:e+M}export{v as convertGeohash32ToXY,G as decodeBase32Char,b as decodeGeohash,X as decodeGeohashXY,W as encodeBase32Char,B as encodeGeohash,A as getGeohash,S as getGeohashBounds,T as getRelativeGeohash,z as setGeohashBuf,Y as setGeohashXY,F as unpackXBits,P as unpackYBits};