UNPKG

@arcgis/core

Version:

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

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