cynx-lib 1.3.115 → 1.3.117
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/gen.js +77 -77
- package/package.json +1 -1
- package/ui/components/ActionsMenu.jsx +357 -357
- package/ui/components/BrandingCard.jsx +6 -6
- package/ui/components/Drawer.jsx +208 -208
- package/ui/components/Globe.jsx +764 -764
- package/ui/components/HoverCard.jsx +85 -85
- package/ui/components/PrivacyBlur.jsx +603 -603
- package/utils/index.js +24 -24
- package/utils/utils/db.cjs +6 -6
- package/utils/utils/db.js +8 -8
- package/utils/utils/duration.js +139 -139
- package/utils/utils/oidc.js +214 -214
- package/utils/utils/realtime.js +1634 -1634
- package/utils/utils/server.js +371 -371
- package/utils/utils/session.js +131 -131
- package/utils/utils/session_manager.js +580 -580
- package/utils/utils/sso_manager.js +702 -702
- package/utils/utils/storage.js +393 -393
- package/utils/utils/ui.js +111 -111
- package/vue/components/Badge.vue +79 -79
- package/vue/components/Button.vue +209 -209
- package/vue/components/Checkbox.vue +103 -103
- package/vue/components/CircularProgress.vue +383 -383
- package/vue/components/Divider.vue +94 -94
- package/vue/components/Drawer.vue +243 -243
- package/vue/components/InfoBadge.vue +223 -223
- package/vue/components/Input.vue +341 -341
- package/vue/components/LinearProgress.vue +268 -268
- package/vue/components/Modal.vue +226 -226
- package/vue/components/Pagination.vue +199 -199
- package/vue/components/Select.vue +713 -713
- package/vue/components/Sidebar.vue +955 -955
- package/vue/components/Skeleton.vue +91 -91
- package/vue/components/Spinner.vue +263 -263
- package/vue/components/StatusTag.vue +89 -89
- package/vue/components/TabBar.vue +176 -176
- package/vue/components/Table.vue +393 -393
- package/vue/components/TimePicker.vue +399 -399
- package/vue/components/Toggle.vue +115 -115
- package/vue/components/XTable.vue +140 -140
- package/vue/composables/useAutoSkeletonRows.ts +71 -71
- package/vue/index.d.ts +67 -67
- package/vue/index.js +86 -86
package/ui/components/Globe.jsx
CHANGED
|
@@ -1,764 +1,764 @@
|
|
|
1
|
-
import { useEffect, useRef, useCallback } from 'react';
|
|
2
|
-
|
|
3
|
-
// WebGL Shaders & Constants
|
|
4
|
-
const VS_QUAD = `attribute vec2 a;void main(){gl_Position=vec4(a,0.0,1.0);}`;
|
|
5
|
-
|
|
6
|
-
const FS_GLOBE = `precision highp float;
|
|
7
|
-
uniform vec2 t,v,s;
|
|
8
|
-
uniform vec3 F,w;
|
|
9
|
-
uniform vec4 n;
|
|
10
|
-
uniform float k,x,y;
|
|
11
|
-
uniform sampler2D z;
|
|
12
|
-
float u;
|
|
13
|
-
mat3 A(float a,float b){
|
|
14
|
-
float c=cos(a),d=cos(b),e=sin(a),f=sin(b);
|
|
15
|
-
return mat3(d,f*e,-f*c,0.0,c,e,f,d*-e,d*c);
|
|
16
|
-
}
|
|
17
|
-
vec3 B(vec3 c,out float G){
|
|
18
|
-
c=c.xzy;
|
|
19
|
-
float q=max(2.0,floor(log2(2.236068*k*3.141593*(1.0-c.z*c.z))*0.72021));
|
|
20
|
-
vec2 g=floor(pow(1.618034,q)/2.236068*vec2(1.0,1.618034)+0.5);
|
|
21
|
-
vec2 d=fract((g+1.0)*0.618034)*6.283185-3.883222;
|
|
22
|
-
vec2 e=-2.0*g;
|
|
23
|
-
vec2 f=vec2(atan(c.y,c.x),c.z-1.0);
|
|
24
|
-
vec2 r=floor(vec2(e.y*f.x-d.y*(f.y*k+1.0),-e.x*f.x+d.x*(f.y*k+1.0))/(d.x*e.y-e.x*d.y));
|
|
25
|
-
float o=3.141593;
|
|
26
|
-
vec3 C;
|
|
27
|
-
for(float h=0.0;h<4.0;h+=1.0){
|
|
28
|
-
vec2 D=vec2(mod(h,2.0),floor(h*0.5));
|
|
29
|
-
float j=dot(g,r+D);
|
|
30
|
-
if(j>k) continue;
|
|
31
|
-
float a=j,b=0.0;
|
|
32
|
-
if(a>=16384.0){a-=16384.0;b+=0.868872;}
|
|
33
|
-
if(a>=8192.0){a-=8192.0;b+=0.934436;}
|
|
34
|
-
if(a>=4096.0){a-=4096.0;b+=0.467218;}
|
|
35
|
-
if(a>=2048.0){a-=2048.0;b+=0.733609;}
|
|
36
|
-
if(a>=1024.0){a-=1024.0;b+=0.866804;}
|
|
37
|
-
if(a>=512.0){a-=512.0;b+=0.433402;}
|
|
38
|
-
if(a>=256.0){a-=256.0;b+=0.216701;}
|
|
39
|
-
if(a>=128.0){a-=128.0;b+=0.108351;}
|
|
40
|
-
if(a>=64.0){a-=64.0;b+=0.554175;}
|
|
41
|
-
if(a>=32.0){a-=32.0;b+=0.777088;}
|
|
42
|
-
if(a>=16.0){a-=16.0;b+=0.888544;}
|
|
43
|
-
if(a>=8.0){a-=8.0;b+=0.944272;}
|
|
44
|
-
if(a>=4.0){a-=4.0;b+=0.472136;}
|
|
45
|
-
if(a>=2.0){a-=2.0;b+=0.236068;}
|
|
46
|
-
if(a>=1.0){a-=1.0;b+=0.618034;}
|
|
47
|
-
float l=fract(b)*6.283185;
|
|
48
|
-
float i=1.0-2.0*j*u;
|
|
49
|
-
float m=sqrt(1.0-i*i);
|
|
50
|
-
vec3 p=vec3(cos(l)*m,sin(l)*m,i);
|
|
51
|
-
float E=length(c-p);
|
|
52
|
-
if(E<o){o=E;C=p;}
|
|
53
|
-
}
|
|
54
|
-
G=o;
|
|
55
|
-
return C.xzy;
|
|
56
|
-
}
|
|
57
|
-
void main(){
|
|
58
|
-
u=1.0/k;
|
|
59
|
-
vec2 c=1.0/t;
|
|
60
|
-
vec2 b=(gl_FragCoord.xy*c*2.0-1.0)/x-v*vec2(1.0,-1.0)*c;
|
|
61
|
-
b.x*=t.x*c.y;
|
|
62
|
-
float a=dot(b,b);
|
|
63
|
-
float f=0.0;
|
|
64
|
-
vec4 l=vec4(0.0);
|
|
65
|
-
if(a<=0.64){
|
|
66
|
-
float g;
|
|
67
|
-
vec4 m=vec4(0.0);
|
|
68
|
-
vec3 h=normalize(vec3(b,sqrt(0.64-a)));
|
|
69
|
-
mat3 o=A(s.y,s.x);
|
|
70
|
-
float i=h.z;
|
|
71
|
-
vec3 d=B(h*o,g);
|
|
72
|
-
float j=asin(d.y);
|
|
73
|
-
float e=acos(-d.x/cos(j));
|
|
74
|
-
e=d.z<0.0?-e:e;
|
|
75
|
-
float p=max(texture2D(z,vec2(e*0.5/3.141593,-(j/3.141593+0.5))).x,y);
|
|
76
|
-
float q=p*smoothstep(0.008,0.0,g)*pow(i,n.y)*n.x;
|
|
77
|
-
m+=vec4(F*(mix((1.0-q)*pow(i,0.4),q,n.z)+0.1)+pow(1.0-i,4.0)*w,1.0);
|
|
78
|
-
l+=m*(1.0+n.w)*0.5;
|
|
79
|
-
f=(1.0-a)*(1.0-a)*smoothstep(0.0,1.0,0.2/(a-0.64));
|
|
80
|
-
}else{
|
|
81
|
-
float r=sqrt(0.2/(a-0.64));
|
|
82
|
-
f=smoothstep(0.5,1.0,r/(r+1.0));
|
|
83
|
-
}
|
|
84
|
-
gl_FragColor=l+vec4(f*w,f);
|
|
85
|
-
}`;
|
|
86
|
-
|
|
87
|
-
const VS_MARKER = `varying vec2 m;
|
|
88
|
-
varying vec3 g;
|
|
89
|
-
varying float h;
|
|
90
|
-
attribute vec2 n;
|
|
91
|
-
attribute vec3 p,w;
|
|
92
|
-
attribute float q,x;
|
|
93
|
-
uniform vec2 b,r;
|
|
94
|
-
uniform float i,j,k,s;
|
|
95
|
-
void main(){
|
|
96
|
-
float c=cos(j),d=sin(j),e=cos(i),f=sin(i);
|
|
97
|
-
vec3 a=p*(0.8+s);
|
|
98
|
-
vec3 l=vec3(e*a.x+f*a.z,f*d*a.x+c*a.y-e*d*a.z,-f*c*a.x+d*a.y+e*c*a.z);
|
|
99
|
-
if(l.z<0.0&&length(l.xy)<0.8){
|
|
100
|
-
gl_Position=vec4(2.0,2.0,0.0,1.0);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
float t=b.y/b.x;
|
|
104
|
-
vec2 y=(l.xy+n*q*2.0)*vec2(t,1.0)*k+r*vec2(1.0,-1.0)*k/b;
|
|
105
|
-
gl_Position=vec4(y,0.0,1.0);
|
|
106
|
-
m=n;
|
|
107
|
-
g=w;
|
|
108
|
-
h=x;
|
|
109
|
-
}`;
|
|
110
|
-
|
|
111
|
-
const FS_MARKER = `precision highp float;
|
|
112
|
-
varying vec2 m;
|
|
113
|
-
varying vec3 g;
|
|
114
|
-
varying float h;
|
|
115
|
-
uniform vec3 v;
|
|
116
|
-
void main(){
|
|
117
|
-
if(length(m)>0.25) discard;
|
|
118
|
-
vec3 a=h>0.5?g:v;
|
|
119
|
-
gl_FragColor=vec4(a,1.0);
|
|
120
|
-
}`;
|
|
121
|
-
|
|
122
|
-
const VS_ARC = `varying vec3 i;
|
|
123
|
-
varying float j,s,t;
|
|
124
|
-
attribute vec2 k;
|
|
125
|
-
attribute vec3 l,m,N;
|
|
126
|
-
attribute float v,w,O;
|
|
127
|
-
uniform vec2 g,x;
|
|
128
|
-
uniform float y,z,h,A;
|
|
129
|
-
mat3 B(float a,float b){
|
|
130
|
-
float c=cos(a),d=cos(b),e=sin(a),f=sin(b);
|
|
131
|
-
return mat3(d,f*e,-f*c,0.0,c,e,f,d*-e,d*c);
|
|
132
|
-
}
|
|
133
|
-
vec3 C(vec3 c,vec3 d,vec3 e,float a){
|
|
134
|
-
float b=1.0-a;
|
|
135
|
-
return b*b*c+2.0*b*a*d+a*a*e;
|
|
136
|
-
}
|
|
137
|
-
vec3 D(vec3 c,vec3 b,vec3 d,float a){
|
|
138
|
-
float e=1.0-a;
|
|
139
|
-
return 2.0*e*(b-c)+2.0*a*(d-b);
|
|
140
|
-
}
|
|
141
|
-
void main(){
|
|
142
|
-
mat3 b=B(z,y);
|
|
143
|
-
float c=0.8+A;
|
|
144
|
-
vec3 d=l*c,e=m*c,f=l+m;
|
|
145
|
-
float n=length(f);
|
|
146
|
-
vec3 E=n>0.001?f/n:vec3(0.0,1.0,0.0);
|
|
147
|
-
vec3 o=E*(0.8+v);
|
|
148
|
-
float p=k.x;
|
|
149
|
-
vec3 F=C(d,o,e,p);
|
|
150
|
-
vec3 q=b*F;
|
|
151
|
-
vec3 G=D(d,o,e,p);
|
|
152
|
-
vec3 H=b*G;
|
|
153
|
-
vec2 a=H.xy;
|
|
154
|
-
float r=length(a);
|
|
155
|
-
vec2 I=r>0.001?vec2(-a.y,a.x)/r:vec2(1.0,0.0);
|
|
156
|
-
float J=g.x/g.y;
|
|
157
|
-
vec2 K=q.xy*vec2(1.0/J,1.0)*h+x*vec2(1.0,-1.0)*h/g;
|
|
158
|
-
vec2 P=K+I*w*k.y*h;
|
|
159
|
-
gl_Position=vec4(P,0.0,1.0);
|
|
160
|
-
i=N;
|
|
161
|
-
j=O;
|
|
162
|
-
s=q.z;
|
|
163
|
-
t=length(q.xy);
|
|
164
|
-
}`;
|
|
165
|
-
|
|
166
|
-
const FS_ARC = `precision highp float;
|
|
167
|
-
varying vec3 i;
|
|
168
|
-
varying float j,s,t;
|
|
169
|
-
uniform vec3 M;
|
|
170
|
-
void main(){
|
|
171
|
-
if(s<0.0&&t<0.8) discard;
|
|
172
|
-
vec3 a=j>0.5?i:M;
|
|
173
|
-
gl_FragColor=vec4(a,1.0);
|
|
174
|
-
}`;
|
|
175
|
-
|
|
176
|
-
const SPHERE_BASE_RADIUS = 0.8;
|
|
177
|
-
const LANDMASS_IMAGE =
|
|
178
|
-
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAACAAQAAAADMzoqnAAAECklEQVR42u3VsW4jRRzH8d94gzfF4Q0VQaC4vBLTRTp0mze4ggfAPAE5XQEFsGNAVIjwBrmW7h7gJE+giKjyABTZE4g06LKJETdRJvtD65kdz6yduKABiW+TVfzRf2bXYxtcE/59YJCz6YdbgQF6ACSRrwYKYImmh5PbwOewlV3wlQNbAN6SEExjUOO+BU0aCSnxReHABUlK4YFQeJeUT3da8IIkZ6NGoSnFY5KsMoVzMKfECUnqxgPYRArarmUCndHwzIEaQEpg5xVdBXROl8mpAQx5dUgPiHoYAAkg5w3JABR06byGAVgcRGAz5bznj6phBQNRFwyqgdxebH6gshJAesWoFhgYpApAFoG8BIZ/fEhSox5jDjQXmV0Ar5XJfAIrALi3URVs09gHIL4XJCkLC5LH9JWiArABFCSrQjdgkBzRJ0WJeUOSNyQAfJJwUSWUBRlJQ8oGHATACGlBynnzy2kEYLNjrxouigD8BZcgOeVPqh12RtufaCN5wCPVDpvQ9lsIrqndsJtDcWqBCpf4hWN7OdWHBw58FwIaNOU/n1TpMW2DFaD48cmr4185T8NHkpUFX749pQPVdgRKC/DGoQPVeAEKv+WHvY8OOWNTPRp5kHuwSf8wzXtVBKR7YwEH9H3lQUaypUfSATOALyVNu5vZJW31Bnx98nkLfDUWJaz6ixvm+RIQRdl3kmRxxiaDoGnZW4CpPfkaQadlcPim1xOSvETQo7Lv75enVAXJ3xGUlony4KQBBWUM1NiDc6qhyS8RgQs18OCMMtPDaAUIyg0PZkRWDqs+wnKJBTDI1Js6BolegOsKmUxNDBAAKqQyMQmidhegBlLZ+wwKYdv5M/8x1khkb1cgKqP2H+MKyV5vS+whrE8DQDgAlUAoRBX056EElJCjJVACeJBZgNfVp+iCCm4RBWCgKsRxASSA9KgDhDtCiTuMyfHsKXzhC6wNAIjjWb8LKAOA2ctk3FmCOlgKFy8f1N0JJtgsxinYnVAHt4t3gPzZXSCTyCWCQmBT91QE3B5yarSN40dNHYPka4TlDhTUI8zLvl0JSL3vZn6DsCFZOeB2yROEpR68sECQQA++xIGCR2X7DwlEoLRgUrZrqlUg50S1uy43YqDcN6UFBVkhAjWiCV2Q0jgQPdplMKxvBXodcOfAwJYvgdL+1etA1YJJfBcZlQV7sO1i2gHoNiyxtQ5sBsCgWyoxCHiFFd2L5nUTCqMAqGUgsQ9f5kCcCiZgRYkMgMTd5WsB1rTzj0Em14BE4r+QxN1lCEsVur2PoF5Wbg8RJXR4djgvBgauhLywoEZQrt1KKRdVS4CdlJ8qafyP+9KIj/nE/d7kKwH9jgS72e9DV+kvfTWgct4ZyP8Byb8BPG7MaaIIkAQAAAAASUVORK5CYII=';
|
|
179
|
-
|
|
180
|
-
function createShader(gl, type, source) {
|
|
181
|
-
const shader = gl.createShader(type);
|
|
182
|
-
gl.shaderSource(shader, source);
|
|
183
|
-
gl.compileShader(shader);
|
|
184
|
-
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
185
|
-
gl.deleteShader(shader);
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
return shader;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function createProgram(gl, vsSource, fsSource) {
|
|
192
|
-
const vs = createShader(gl, gl.VERTEX_SHADER, vsSource);
|
|
193
|
-
const fs = createShader(gl, gl.FRAGMENT_SHADER, fsSource);
|
|
194
|
-
if (!vs || !fs) return null;
|
|
195
|
-
const program = gl.createProgram();
|
|
196
|
-
gl.attachShader(program, vs);
|
|
197
|
-
gl.attachShader(program, fs);
|
|
198
|
-
gl.linkProgram(program);
|
|
199
|
-
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
200
|
-
gl.deleteShader(vs);
|
|
201
|
-
gl.deleteShader(fs);
|
|
202
|
-
gl.deleteProgram(program);
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
|
-
return program;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function getUniforms(gl, program, names) {
|
|
209
|
-
const map = {};
|
|
210
|
-
for (const name of names) {
|
|
211
|
-
map[name] = gl.getUniformLocation(program, name);
|
|
212
|
-
}
|
|
213
|
-
return map;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function getAttributes(gl, program, names) {
|
|
217
|
-
const map = {};
|
|
218
|
-
for (const name of names) {
|
|
219
|
-
map[name] = gl.getAttribLocation(program, name);
|
|
220
|
-
}
|
|
221
|
-
return map;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
function locationToSphere([lat, lon]) {
|
|
225
|
-
const phi = (lat * Math.PI) / 180;
|
|
226
|
-
const theta = (lon * Math.PI) / 180 - Math.PI;
|
|
227
|
-
const cosPhi = Math.cos(phi);
|
|
228
|
-
return [-cosPhi * Math.cos(theta), Math.sin(phi), cosPhi * Math.sin(theta)];
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function setupVertexAttrib(gl, location, size, stride, offset, divisor, isWebGL2, ext) {
|
|
232
|
-
if (location < 0) return;
|
|
233
|
-
gl.enableVertexAttribArray(location);
|
|
234
|
-
gl.vertexAttribPointer(location, size, gl.FLOAT, false, stride, offset);
|
|
235
|
-
if (isWebGL2) {
|
|
236
|
-
gl.vertexAttribDivisor(location, divisor);
|
|
237
|
-
} else if (ext) {
|
|
238
|
-
ext.vertexAttribDivisorANGLE(location, divisor);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Creates and renders a standalone WebGL 3D globe.
|
|
244
|
-
*
|
|
245
|
-
* @param {HTMLCanvasElement} canvas
|
|
246
|
-
* @param {Object} opts
|
|
247
|
-
* @returns {{ update: (opts: Object) => void, destroy: () => void }}
|
|
248
|
-
*/
|
|
249
|
-
export function createGlobe(canvas, opts) {
|
|
250
|
-
const contextAttrs = {
|
|
251
|
-
alpha: true,
|
|
252
|
-
stencil: false,
|
|
253
|
-
antialias: true,
|
|
254
|
-
depth: false,
|
|
255
|
-
preserveDrawingBuffer: false,
|
|
256
|
-
...opts.context,
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
let gl = canvas.getContext('webgl2', contextAttrs);
|
|
260
|
-
const isWebGL2 = !!gl;
|
|
261
|
-
if (!gl) {
|
|
262
|
-
gl = canvas.getContext('webgl', contextAttrs);
|
|
263
|
-
}
|
|
264
|
-
if (!gl) {
|
|
265
|
-
return { destroy: () => {}, update: () => {} };
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
const ext = isWebGL2 ? null : gl.getExtension('ANGLE_instanced_arrays');
|
|
269
|
-
const dpr = opts.devicePixelRatio || (typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1);
|
|
270
|
-
|
|
271
|
-
canvas.width = (opts.width || 500) * dpr;
|
|
272
|
-
canvas.height = (opts.height || 500) * dpr;
|
|
273
|
-
|
|
274
|
-
let phi = opts.phi || 0;
|
|
275
|
-
let theta = opts.theta || 0;
|
|
276
|
-
let markers = opts.markers || [];
|
|
277
|
-
let arcs = opts.arcs || [];
|
|
278
|
-
let mapSamples = opts.mapSamples || 16000;
|
|
279
|
-
let mapBrightness = opts.mapBrightness ?? 6;
|
|
280
|
-
let mapBaseBrightness = opts.mapBaseBrightness ?? 0;
|
|
281
|
-
let baseColor = opts.baseColor || [0.8, 0.85, 0.9];
|
|
282
|
-
let markerColor = opts.markerColor || [0.15, 0.5, 1.0];
|
|
283
|
-
let glowColor = opts.glowColor || [1, 1, 1];
|
|
284
|
-
let arcColor = opts.arcColor || [0.3, 0.6, 1.0];
|
|
285
|
-
let arcWidth = opts.arcWidth ?? 1;
|
|
286
|
-
let arcHeight = opts.arcHeight ?? 0.2;
|
|
287
|
-
let diffuse = opts.diffuse ?? 1.2;
|
|
288
|
-
let dark = opts.dark ?? 0;
|
|
289
|
-
let opacity = opts.opacity ?? 1;
|
|
290
|
-
let offset = opts.offset || [0, 0];
|
|
291
|
-
let scale = opts.scale ?? 1;
|
|
292
|
-
let markerElevation = opts.markerElevation ?? 0.05;
|
|
293
|
-
|
|
294
|
-
const globeProgram = createProgram(gl, VS_QUAD, FS_GLOBE);
|
|
295
|
-
const markerProgram = createProgram(gl, VS_MARKER, FS_MARKER);
|
|
296
|
-
const arcProgram = createProgram(gl, VS_ARC, FS_ARC);
|
|
297
|
-
|
|
298
|
-
if (!globeProgram) {
|
|
299
|
-
return { destroy: () => {}, update: () => {} };
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// Buffers
|
|
303
|
-
const quadBuffer = gl.createBuffer();
|
|
304
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, quadBuffer);
|
|
305
|
-
gl.bufferData(
|
|
306
|
-
gl.ARRAY_BUFFER,
|
|
307
|
-
new Float32Array([-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1]),
|
|
308
|
-
gl.STATIC_DRAW
|
|
309
|
-
);
|
|
310
|
-
|
|
311
|
-
const arcStripBuffer = gl.createBuffer();
|
|
312
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, arcStripBuffer);
|
|
313
|
-
const stripPoints = [];
|
|
314
|
-
for (let i = 0; i <= 32; i++) {
|
|
315
|
-
const t = i / 32;
|
|
316
|
-
stripPoints.push(t, -1, t, 1);
|
|
317
|
-
}
|
|
318
|
-
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(stripPoints), gl.STATIC_DRAW);
|
|
319
|
-
|
|
320
|
-
const markerBuffer = gl.createBuffer();
|
|
321
|
-
const arcBuffer = gl.createBuffer();
|
|
322
|
-
|
|
323
|
-
const globeUniforms = getUniforms(gl, globeProgram, ['t', 's', 'k', 'x', 'v', 'F', 'w', 'n', 'y', 'z']);
|
|
324
|
-
const markerUniforms = markerProgram ? getUniforms(gl, markerProgram, ['i', 'j', 'b', 'k', 'r', 'v', 's']) : {};
|
|
325
|
-
const markerAttribs = markerProgram ? getAttributes(gl, markerProgram, ['n', 'p', 'q', 'w', 'x']) : {};
|
|
326
|
-
const arcUniforms = arcProgram ? getUniforms(gl, arcProgram, ['y', 'z', 'g', 'h', 'x', 'M', 'A']) : {};
|
|
327
|
-
const arcAttribs = arcProgram ? getAttributes(gl, arcProgram, ['k', 'l', 'm', 'v', 'w', 'N', 'O']) : {};
|
|
328
|
-
const globePosAttrib = gl.getAttribLocation(globeProgram, 'a');
|
|
329
|
-
|
|
330
|
-
// Landmass Texture
|
|
331
|
-
const texture = gl.createTexture();
|
|
332
|
-
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
333
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, 1, 1, 0, gl.RGB, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0]));
|
|
334
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
335
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
336
|
-
|
|
337
|
-
const img = new Image();
|
|
338
|
-
img.onload = () => {
|
|
339
|
-
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
340
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, img);
|
|
341
|
-
gl.generateMipmap(gl.TEXTURE_2D);
|
|
342
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
343
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
344
|
-
gl.activeTexture(gl.TEXTURE0);
|
|
345
|
-
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
346
|
-
};
|
|
347
|
-
img.src = LANDMASS_IMAGE;
|
|
348
|
-
|
|
349
|
-
let arcCount = 0;
|
|
350
|
-
|
|
351
|
-
function updateMarkers(list) {
|
|
352
|
-
markers = list;
|
|
353
|
-
const data = new Float32Array(8 * markers.length);
|
|
354
|
-
markers.forEach((m, idx) => {
|
|
355
|
-
data.set(
|
|
356
|
-
[
|
|
357
|
-
...locationToSphere(m.location),
|
|
358
|
-
m.size,
|
|
359
|
-
...(m.color || [0, 0, 0]),
|
|
360
|
-
m.color ? 1 : 0,
|
|
361
|
-
],
|
|
362
|
-
8 * idx
|
|
363
|
-
);
|
|
364
|
-
});
|
|
365
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, markerBuffer);
|
|
366
|
-
gl.bufferData(gl.ARRAY_BUFFER, data, gl.DYNAMIC_DRAW);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
function updateArcs(list) {
|
|
370
|
-
arcs = list;
|
|
371
|
-
arcCount = arcs.length;
|
|
372
|
-
const data = new Float32Array(12 * arcs.length);
|
|
373
|
-
arcs.forEach((a, idx) => {
|
|
374
|
-
data.set(
|
|
375
|
-
[
|
|
376
|
-
...locationToSphere(a.from),
|
|
377
|
-
...locationToSphere(a.to),
|
|
378
|
-
arcHeight + markerElevation,
|
|
379
|
-
0.005 * arcWidth,
|
|
380
|
-
...(a.color || [0, 0, 0]),
|
|
381
|
-
a.color ? 1 : 0,
|
|
382
|
-
],
|
|
383
|
-
12 * idx
|
|
384
|
-
);
|
|
385
|
-
});
|
|
386
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, arcBuffer);
|
|
387
|
-
gl.bufferData(gl.ARRAY_BUFFER, data, gl.DYNAMIC_DRAW);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
function render(nextOpts = {}) {
|
|
391
|
-
if (nextOpts.phi !== undefined) phi = nextOpts.phi;
|
|
392
|
-
if (nextOpts.theta !== undefined) theta = nextOpts.theta;
|
|
393
|
-
if (nextOpts.markers !== undefined) updateMarkers(nextOpts.markers);
|
|
394
|
-
if (nextOpts.arcs !== undefined) updateArcs(nextOpts.arcs);
|
|
395
|
-
|
|
396
|
-
if (nextOpts.width && nextOpts.height) {
|
|
397
|
-
canvas.width = nextOpts.width * dpr;
|
|
398
|
-
canvas.height = nextOpts.height * dpr;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
if (nextOpts.mapSamples !== undefined) mapSamples = nextOpts.mapSamples;
|
|
402
|
-
if (nextOpts.mapBrightness !== undefined) mapBrightness = nextOpts.mapBrightness;
|
|
403
|
-
if (nextOpts.mapBaseBrightness !== undefined) mapBaseBrightness = nextOpts.mapBaseBrightness;
|
|
404
|
-
if (nextOpts.baseColor !== undefined) baseColor = nextOpts.baseColor;
|
|
405
|
-
if (nextOpts.markerColor !== undefined) markerColor = nextOpts.markerColor;
|
|
406
|
-
if (nextOpts.glowColor !== undefined) glowColor = nextOpts.glowColor;
|
|
407
|
-
if (nextOpts.arcColor !== undefined) arcColor = nextOpts.arcColor;
|
|
408
|
-
if (nextOpts.arcWidth !== undefined) arcWidth = nextOpts.arcWidth;
|
|
409
|
-
if (nextOpts.arcHeight !== undefined) arcHeight = nextOpts.arcHeight;
|
|
410
|
-
if (nextOpts.diffuse !== undefined) diffuse = nextOpts.diffuse;
|
|
411
|
-
if (nextOpts.dark !== undefined) dark = nextOpts.dark;
|
|
412
|
-
if (nextOpts.opacity !== undefined) opacity = nextOpts.opacity;
|
|
413
|
-
if (nextOpts.offset !== undefined) offset = nextOpts.offset;
|
|
414
|
-
if (nextOpts.scale !== undefined) scale = nextOpts.scale;
|
|
415
|
-
if (nextOpts.markerElevation !== undefined) markerElevation = nextOpts.markerElevation;
|
|
416
|
-
|
|
417
|
-
gl.viewport(0, 0, canvas.width, canvas.height);
|
|
418
|
-
gl.clearColor(0, 0, 0, 0);
|
|
419
|
-
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
420
|
-
gl.enable(gl.BLEND);
|
|
421
|
-
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
|
422
|
-
|
|
423
|
-
// Render Base Globe
|
|
424
|
-
gl.useProgram(globeProgram);
|
|
425
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, quadBuffer);
|
|
426
|
-
gl.enableVertexAttribArray(globePosAttrib);
|
|
427
|
-
gl.vertexAttribPointer(globePosAttrib, 2, gl.FLOAT, false, 0, 0);
|
|
428
|
-
if (isWebGL2) {
|
|
429
|
-
gl.vertexAttribDivisor(globePosAttrib, 0);
|
|
430
|
-
} else if (ext) {
|
|
431
|
-
ext.vertexAttribDivisorANGLE(globePosAttrib, 0);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
gl.uniform2f(globeUniforms.t, canvas.width, canvas.height);
|
|
435
|
-
gl.uniform2f(globeUniforms.s, phi, theta);
|
|
436
|
-
gl.uniform1f(globeUniforms.k, mapSamples);
|
|
437
|
-
gl.uniform1f(globeUniforms.x, scale);
|
|
438
|
-
gl.uniform2f(globeUniforms.v, offset[0] * dpr, offset[1] * dpr);
|
|
439
|
-
gl.uniform3fv(globeUniforms.F, baseColor);
|
|
440
|
-
gl.uniform3fv(globeUniforms.w, glowColor);
|
|
441
|
-
gl.uniform4f(globeUniforms.n, mapBrightness, diffuse, dark, opacity);
|
|
442
|
-
gl.uniform1f(globeUniforms.y, mapBaseBrightness);
|
|
443
|
-
gl.uniform1i(globeUniforms.z, 0);
|
|
444
|
-
gl.activeTexture(gl.TEXTURE0);
|
|
445
|
-
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
446
|
-
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
|
447
|
-
|
|
448
|
-
// Render Arcs
|
|
449
|
-
if (arcProgram && arcCount > 0) {
|
|
450
|
-
gl.useProgram(arcProgram);
|
|
451
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, arcStripBuffer);
|
|
452
|
-
if (arcAttribs.k >= 0) {
|
|
453
|
-
gl.enableVertexAttribArray(arcAttribs.k);
|
|
454
|
-
gl.vertexAttribPointer(arcAttribs.k, 2, gl.FLOAT, false, 0, 0);
|
|
455
|
-
if (isWebGL2) gl.vertexAttribDivisor(arcAttribs.k, 0);
|
|
456
|
-
else if (ext) ext.vertexAttribDivisorANGLE(arcAttribs.k, 0);
|
|
457
|
-
}
|
|
458
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, arcBuffer);
|
|
459
|
-
const arcStride = 48;
|
|
460
|
-
setupVertexAttrib(gl, arcAttribs.l, 3, arcStride, 0, 1, isWebGL2, ext);
|
|
461
|
-
setupVertexAttrib(gl, arcAttribs.m, 3, arcStride, 12, 1, isWebGL2, ext);
|
|
462
|
-
setupVertexAttrib(gl, arcAttribs.v, 1, arcStride, 24, 1, isWebGL2, ext);
|
|
463
|
-
setupVertexAttrib(gl, arcAttribs.w, 1, arcStride, 28, 1, isWebGL2, ext);
|
|
464
|
-
setupVertexAttrib(gl, arcAttribs.N, 3, arcStride, 32, 1, isWebGL2, ext);
|
|
465
|
-
setupVertexAttrib(gl, arcAttribs.O, 1, arcStride, 44, 1, isWebGL2, ext);
|
|
466
|
-
|
|
467
|
-
gl.uniform1f(arcUniforms.y, phi);
|
|
468
|
-
gl.uniform1f(arcUniforms.z, theta);
|
|
469
|
-
gl.uniform2f(arcUniforms.g, canvas.width, canvas.height);
|
|
470
|
-
gl.uniform1f(arcUniforms.h, scale);
|
|
471
|
-
gl.uniform2f(arcUniforms.x, offset[0] * dpr, offset[1] * dpr);
|
|
472
|
-
gl.uniform3fv(arcUniforms.M, arcColor);
|
|
473
|
-
gl.uniform1f(arcUniforms.A, markerElevation);
|
|
474
|
-
|
|
475
|
-
if (isWebGL2) {
|
|
476
|
-
gl.drawArraysInstanced(gl.TRIANGLE_STRIP, 0, 66, arcCount);
|
|
477
|
-
} else if (ext) {
|
|
478
|
-
ext.drawArraysInstancedANGLE(gl.TRIANGLE_STRIP, 0, 66, arcCount);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
// Render Markers
|
|
483
|
-
if (markerProgram && markers.length > 0) {
|
|
484
|
-
gl.useProgram(markerProgram);
|
|
485
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, quadBuffer);
|
|
486
|
-
if (markerAttribs.n >= 0) {
|
|
487
|
-
gl.enableVertexAttribArray(markerAttribs.n);
|
|
488
|
-
gl.vertexAttribPointer(markerAttribs.n, 2, gl.FLOAT, false, 0, 0);
|
|
489
|
-
if (isWebGL2) gl.vertexAttribDivisor(markerAttribs.n, 0);
|
|
490
|
-
else if (ext) ext.vertexAttribDivisorANGLE(markerAttribs.n, 0);
|
|
491
|
-
}
|
|
492
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, markerBuffer);
|
|
493
|
-
const markerStride = 32;
|
|
494
|
-
setupVertexAttrib(gl, markerAttribs.p, 3, markerStride, 0, 1, isWebGL2, ext);
|
|
495
|
-
setupVertexAttrib(gl, markerAttribs.q, 1, markerStride, 12, 1, isWebGL2, ext);
|
|
496
|
-
setupVertexAttrib(gl, markerAttribs.w, 3, markerStride, 16, 1, isWebGL2, ext);
|
|
497
|
-
setupVertexAttrib(gl, markerAttribs.x, 1, markerStride, 28, 1, isWebGL2, ext);
|
|
498
|
-
|
|
499
|
-
gl.uniform1f(markerUniforms.i, phi);
|
|
500
|
-
gl.uniform1f(markerUniforms.j, theta);
|
|
501
|
-
gl.uniform2f(markerUniforms.b, canvas.width, canvas.height);
|
|
502
|
-
gl.uniform1f(markerUniforms.k, scale);
|
|
503
|
-
gl.uniform2f(markerUniforms.r, offset[0] * dpr, offset[1] * dpr);
|
|
504
|
-
gl.uniform3fv(markerUniforms.v, markerColor);
|
|
505
|
-
gl.uniform1f(markerUniforms.s, markerElevation);
|
|
506
|
-
|
|
507
|
-
if (isWebGL2) {
|
|
508
|
-
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, markers.length);
|
|
509
|
-
} else if (ext) {
|
|
510
|
-
ext.drawArraysInstancedANGLE(gl.TRIANGLES, 0, 6, markers.length);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
// Initial draw
|
|
516
|
-
render({ markers, arcs });
|
|
517
|
-
|
|
518
|
-
return {
|
|
519
|
-
update: render,
|
|
520
|
-
destroy: () => {
|
|
521
|
-
gl.deleteBuffer(quadBuffer);
|
|
522
|
-
gl.deleteBuffer(arcStripBuffer);
|
|
523
|
-
gl.deleteBuffer(markerBuffer);
|
|
524
|
-
gl.deleteBuffer(arcBuffer);
|
|
525
|
-
gl.deleteTexture(texture);
|
|
526
|
-
gl.deleteProgram(globeProgram);
|
|
527
|
-
if (markerProgram) gl.deleteProgram(markerProgram);
|
|
528
|
-
if (arcProgram) gl.deleteProgram(arcProgram);
|
|
529
|
-
},
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
/**
|
|
534
|
-
* cynx-lib Globe Component
|
|
535
|
-
*/
|
|
536
|
-
export default function Globe({
|
|
537
|
-
width,
|
|
538
|
-
height,
|
|
539
|
-
phi = 0,
|
|
540
|
-
theta = 0.3,
|
|
541
|
-
autoRotate = true,
|
|
542
|
-
autoRotateSpeed = 0.003,
|
|
543
|
-
draggable = true,
|
|
544
|
-
dark = 0,
|
|
545
|
-
diffuse = 1.2,
|
|
546
|
-
mapSamples = 16000,
|
|
547
|
-
mapBrightness = 6,
|
|
548
|
-
mapBaseBrightness = 0,
|
|
549
|
-
baseColor,
|
|
550
|
-
markerColor = [0.15, 0.5, 1.0],
|
|
551
|
-
glowColor = [1, 1, 1],
|
|
552
|
-
arcColor = [0.2, 0.55, 1.0],
|
|
553
|
-
arcWidth = 1,
|
|
554
|
-
arcHeight = 0.2,
|
|
555
|
-
markers = [],
|
|
556
|
-
arcs = [],
|
|
557
|
-
scale = 1,
|
|
558
|
-
offset = [0, 0],
|
|
559
|
-
markerElevation = 0.05,
|
|
560
|
-
onRender,
|
|
561
|
-
className = '',
|
|
562
|
-
style = {},
|
|
563
|
-
}) {
|
|
564
|
-
const containerRef = useRef(null);
|
|
565
|
-
const canvasRef = useRef(null);
|
|
566
|
-
const globeInstanceRef = useRef(null);
|
|
567
|
-
const animFrameIdRef = useRef(null);
|
|
568
|
-
|
|
569
|
-
const rotationRef = useRef({ phi, theta });
|
|
570
|
-
const isDraggingRef = useRef(false);
|
|
571
|
-
const pointerStartRef = useRef({ x: 0, y: 0, phi: 0, theta: 0 });
|
|
572
|
-
|
|
573
|
-
// Default theme-aware base colors
|
|
574
|
-
const activeBaseColor = baseColor || (dark === 1 ? [0.28, 0.3, 0.38] : [0.8, 0.85, 0.92]);
|
|
575
|
-
|
|
576
|
-
// Pointer drag events for smooth rotation
|
|
577
|
-
const handlePointerDown = useCallback(
|
|
578
|
-
(e) => {
|
|
579
|
-
if (!draggable) return;
|
|
580
|
-
isDraggingRef.current = true;
|
|
581
|
-
pointerStartRef.current = {
|
|
582
|
-
x: e.clientX,
|
|
583
|
-
y: e.clientY,
|
|
584
|
-
phi: rotationRef.current.phi,
|
|
585
|
-
theta: rotationRef.current.theta,
|
|
586
|
-
};
|
|
587
|
-
if (e.currentTarget?.setPointerCapture) {
|
|
588
|
-
try {
|
|
589
|
-
e.currentTarget.setPointerCapture(e.pointerId);
|
|
590
|
-
} catch (_) {}
|
|
591
|
-
}
|
|
592
|
-
},
|
|
593
|
-
[draggable]
|
|
594
|
-
);
|
|
595
|
-
|
|
596
|
-
const handlePointerMove = useCallback(
|
|
597
|
-
(e) => {
|
|
598
|
-
if (!isDraggingRef.current || !draggable) return;
|
|
599
|
-
const dx = e.clientX - pointerStartRef.current.x;
|
|
600
|
-
const dy = e.clientY - pointerStartRef.current.y;
|
|
601
|
-
rotationRef.current.phi = pointerStartRef.current.phi + dx * 0.005;
|
|
602
|
-
const nextTheta = pointerStartRef.current.theta - dy * 0.005;
|
|
603
|
-
rotationRef.current.theta = Math.max(-Math.PI / 2.2, Math.min(Math.PI / 2.2, nextTheta));
|
|
604
|
-
},
|
|
605
|
-
[draggable]
|
|
606
|
-
);
|
|
607
|
-
|
|
608
|
-
const handlePointerUp = useCallback(
|
|
609
|
-
(e) => {
|
|
610
|
-
if (!isDraggingRef.current) return;
|
|
611
|
-
isDraggingRef.current = false;
|
|
612
|
-
if (e.currentTarget?.releasePointerCapture) {
|
|
613
|
-
try {
|
|
614
|
-
e.currentTarget.releasePointerCapture(e.pointerId);
|
|
615
|
-
} catch (_) {}
|
|
616
|
-
}
|
|
617
|
-
},
|
|
618
|
-
[]
|
|
619
|
-
);
|
|
620
|
-
|
|
621
|
-
useEffect(() => {
|
|
622
|
-
const canvas = canvasRef.current;
|
|
623
|
-
const container = containerRef.current;
|
|
624
|
-
if (!canvas || !container) return;
|
|
625
|
-
|
|
626
|
-
const initialWidth = width || container.clientWidth || 400;
|
|
627
|
-
const initialHeight = height || container.clientHeight || 400;
|
|
628
|
-
|
|
629
|
-
const globe = createGlobe(canvas, {
|
|
630
|
-
width: initialWidth,
|
|
631
|
-
height: initialHeight,
|
|
632
|
-
phi: rotationRef.current.phi,
|
|
633
|
-
theta: rotationRef.current.theta,
|
|
634
|
-
dark,
|
|
635
|
-
diffuse,
|
|
636
|
-
scale,
|
|
637
|
-
offset,
|
|
638
|
-
mapSamples,
|
|
639
|
-
mapBrightness,
|
|
640
|
-
mapBaseBrightness,
|
|
641
|
-
baseColor: activeBaseColor,
|
|
642
|
-
markerColor,
|
|
643
|
-
glowColor,
|
|
644
|
-
arcColor,
|
|
645
|
-
arcWidth,
|
|
646
|
-
arcHeight,
|
|
647
|
-
markerElevation,
|
|
648
|
-
markers,
|
|
649
|
-
arcs,
|
|
650
|
-
});
|
|
651
|
-
|
|
652
|
-
globeInstanceRef.current = globe;
|
|
653
|
-
|
|
654
|
-
let isMounted = true;
|
|
655
|
-
|
|
656
|
-
const loop = () => {
|
|
657
|
-
if (!isMounted) return;
|
|
658
|
-
|
|
659
|
-
if (autoRotate && !isDraggingRef.current) {
|
|
660
|
-
rotationRef.current.phi += autoRotateSpeed;
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
const state = {
|
|
664
|
-
phi: rotationRef.current.phi,
|
|
665
|
-
theta: rotationRef.current.theta,
|
|
666
|
-
width: width || container.clientWidth || 400,
|
|
667
|
-
height: height || container.clientHeight || 400,
|
|
668
|
-
dark,
|
|
669
|
-
diffuse,
|
|
670
|
-
scale,
|
|
671
|
-
offset,
|
|
672
|
-
mapSamples,
|
|
673
|
-
mapBrightness,
|
|
674
|
-
mapBaseBrightness,
|
|
675
|
-
baseColor: activeBaseColor,
|
|
676
|
-
markerColor,
|
|
677
|
-
glowColor,
|
|
678
|
-
arcColor,
|
|
679
|
-
arcWidth,
|
|
680
|
-
arcHeight,
|
|
681
|
-
markerElevation,
|
|
682
|
-
markers,
|
|
683
|
-
arcs,
|
|
684
|
-
};
|
|
685
|
-
|
|
686
|
-
if (onRender) {
|
|
687
|
-
onRender(state);
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
globe.update(state);
|
|
691
|
-
animFrameIdRef.current = requestAnimationFrame(loop);
|
|
692
|
-
};
|
|
693
|
-
|
|
694
|
-
animFrameIdRef.current = requestAnimationFrame(loop);
|
|
695
|
-
|
|
696
|
-
return () => {
|
|
697
|
-
isMounted = false;
|
|
698
|
-
if (animFrameIdRef.current) {
|
|
699
|
-
cancelAnimationFrame(animFrameIdRef.current);
|
|
700
|
-
}
|
|
701
|
-
globe.destroy();
|
|
702
|
-
globeInstanceRef.current = null;
|
|
703
|
-
};
|
|
704
|
-
}, [
|
|
705
|
-
width,
|
|
706
|
-
height,
|
|
707
|
-
autoRotate,
|
|
708
|
-
autoRotateSpeed,
|
|
709
|
-
dark,
|
|
710
|
-
diffuse,
|
|
711
|
-
scale,
|
|
712
|
-
offset,
|
|
713
|
-
mapSamples,
|
|
714
|
-
mapBrightness,
|
|
715
|
-
mapBaseBrightness,
|
|
716
|
-
activeBaseColor,
|
|
717
|
-
markerColor,
|
|
718
|
-
glowColor,
|
|
719
|
-
arcColor,
|
|
720
|
-
arcWidth,
|
|
721
|
-
arcHeight,
|
|
722
|
-
markerElevation,
|
|
723
|
-
markers,
|
|
724
|
-
arcs,
|
|
725
|
-
onRender,
|
|
726
|
-
]);
|
|
727
|
-
|
|
728
|
-
return (
|
|
729
|
-
<div
|
|
730
|
-
ref={containerRef}
|
|
731
|
-
className={className}
|
|
732
|
-
onPointerDown={handlePointerDown}
|
|
733
|
-
onPointerMove={handlePointerMove}
|
|
734
|
-
onPointerUp={handlePointerUp}
|
|
735
|
-
onPointerCancel={handlePointerUp}
|
|
736
|
-
style={{
|
|
737
|
-
position: 'relative',
|
|
738
|
-
width: width ? `${width}px` : '100%',
|
|
739
|
-
height: height ? `${height}px` : '100%',
|
|
740
|
-
maxWidth: '100%',
|
|
741
|
-
aspectRatio: !height ? '1 / 1' : undefined,
|
|
742
|
-
display: 'flex',
|
|
743
|
-
alignItems: 'center',
|
|
744
|
-
justifyContent: 'center',
|
|
745
|
-
touchAction: draggable ? 'none' : 'auto',
|
|
746
|
-
cursor: draggable ? (isDraggingRef.current ? 'grabbing' : 'grab') : 'default',
|
|
747
|
-
userSelect: 'none',
|
|
748
|
-
...style,
|
|
749
|
-
}}
|
|
750
|
-
>
|
|
751
|
-
<canvas
|
|
752
|
-
ref={canvasRef}
|
|
753
|
-
style={{
|
|
754
|
-
width: '100%',
|
|
755
|
-
height: '100%',
|
|
756
|
-
display: 'block',
|
|
757
|
-
contain: 'layout paint size',
|
|
758
|
-
}}
|
|
759
|
-
/>
|
|
760
|
-
</div>
|
|
761
|
-
);
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
export { Globe };
|
|
1
|
+
import { useEffect, useRef, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
// WebGL Shaders & Constants
|
|
4
|
+
const VS_QUAD = `attribute vec2 a;void main(){gl_Position=vec4(a,0.0,1.0);}`;
|
|
5
|
+
|
|
6
|
+
const FS_GLOBE = `precision highp float;
|
|
7
|
+
uniform vec2 t,v,s;
|
|
8
|
+
uniform vec3 F,w;
|
|
9
|
+
uniform vec4 n;
|
|
10
|
+
uniform float k,x,y;
|
|
11
|
+
uniform sampler2D z;
|
|
12
|
+
float u;
|
|
13
|
+
mat3 A(float a,float b){
|
|
14
|
+
float c=cos(a),d=cos(b),e=sin(a),f=sin(b);
|
|
15
|
+
return mat3(d,f*e,-f*c,0.0,c,e,f,d*-e,d*c);
|
|
16
|
+
}
|
|
17
|
+
vec3 B(vec3 c,out float G){
|
|
18
|
+
c=c.xzy;
|
|
19
|
+
float q=max(2.0,floor(log2(2.236068*k*3.141593*(1.0-c.z*c.z))*0.72021));
|
|
20
|
+
vec2 g=floor(pow(1.618034,q)/2.236068*vec2(1.0,1.618034)+0.5);
|
|
21
|
+
vec2 d=fract((g+1.0)*0.618034)*6.283185-3.883222;
|
|
22
|
+
vec2 e=-2.0*g;
|
|
23
|
+
vec2 f=vec2(atan(c.y,c.x),c.z-1.0);
|
|
24
|
+
vec2 r=floor(vec2(e.y*f.x-d.y*(f.y*k+1.0),-e.x*f.x+d.x*(f.y*k+1.0))/(d.x*e.y-e.x*d.y));
|
|
25
|
+
float o=3.141593;
|
|
26
|
+
vec3 C;
|
|
27
|
+
for(float h=0.0;h<4.0;h+=1.0){
|
|
28
|
+
vec2 D=vec2(mod(h,2.0),floor(h*0.5));
|
|
29
|
+
float j=dot(g,r+D);
|
|
30
|
+
if(j>k) continue;
|
|
31
|
+
float a=j,b=0.0;
|
|
32
|
+
if(a>=16384.0){a-=16384.0;b+=0.868872;}
|
|
33
|
+
if(a>=8192.0){a-=8192.0;b+=0.934436;}
|
|
34
|
+
if(a>=4096.0){a-=4096.0;b+=0.467218;}
|
|
35
|
+
if(a>=2048.0){a-=2048.0;b+=0.733609;}
|
|
36
|
+
if(a>=1024.0){a-=1024.0;b+=0.866804;}
|
|
37
|
+
if(a>=512.0){a-=512.0;b+=0.433402;}
|
|
38
|
+
if(a>=256.0){a-=256.0;b+=0.216701;}
|
|
39
|
+
if(a>=128.0){a-=128.0;b+=0.108351;}
|
|
40
|
+
if(a>=64.0){a-=64.0;b+=0.554175;}
|
|
41
|
+
if(a>=32.0){a-=32.0;b+=0.777088;}
|
|
42
|
+
if(a>=16.0){a-=16.0;b+=0.888544;}
|
|
43
|
+
if(a>=8.0){a-=8.0;b+=0.944272;}
|
|
44
|
+
if(a>=4.0){a-=4.0;b+=0.472136;}
|
|
45
|
+
if(a>=2.0){a-=2.0;b+=0.236068;}
|
|
46
|
+
if(a>=1.0){a-=1.0;b+=0.618034;}
|
|
47
|
+
float l=fract(b)*6.283185;
|
|
48
|
+
float i=1.0-2.0*j*u;
|
|
49
|
+
float m=sqrt(1.0-i*i);
|
|
50
|
+
vec3 p=vec3(cos(l)*m,sin(l)*m,i);
|
|
51
|
+
float E=length(c-p);
|
|
52
|
+
if(E<o){o=E;C=p;}
|
|
53
|
+
}
|
|
54
|
+
G=o;
|
|
55
|
+
return C.xzy;
|
|
56
|
+
}
|
|
57
|
+
void main(){
|
|
58
|
+
u=1.0/k;
|
|
59
|
+
vec2 c=1.0/t;
|
|
60
|
+
vec2 b=(gl_FragCoord.xy*c*2.0-1.0)/x-v*vec2(1.0,-1.0)*c;
|
|
61
|
+
b.x*=t.x*c.y;
|
|
62
|
+
float a=dot(b,b);
|
|
63
|
+
float f=0.0;
|
|
64
|
+
vec4 l=vec4(0.0);
|
|
65
|
+
if(a<=0.64){
|
|
66
|
+
float g;
|
|
67
|
+
vec4 m=vec4(0.0);
|
|
68
|
+
vec3 h=normalize(vec3(b,sqrt(0.64-a)));
|
|
69
|
+
mat3 o=A(s.y,s.x);
|
|
70
|
+
float i=h.z;
|
|
71
|
+
vec3 d=B(h*o,g);
|
|
72
|
+
float j=asin(d.y);
|
|
73
|
+
float e=acos(-d.x/cos(j));
|
|
74
|
+
e=d.z<0.0?-e:e;
|
|
75
|
+
float p=max(texture2D(z,vec2(e*0.5/3.141593,-(j/3.141593+0.5))).x,y);
|
|
76
|
+
float q=p*smoothstep(0.008,0.0,g)*pow(i,n.y)*n.x;
|
|
77
|
+
m+=vec4(F*(mix((1.0-q)*pow(i,0.4),q,n.z)+0.1)+pow(1.0-i,4.0)*w,1.0);
|
|
78
|
+
l+=m*(1.0+n.w)*0.5;
|
|
79
|
+
f=(1.0-a)*(1.0-a)*smoothstep(0.0,1.0,0.2/(a-0.64));
|
|
80
|
+
}else{
|
|
81
|
+
float r=sqrt(0.2/(a-0.64));
|
|
82
|
+
f=smoothstep(0.5,1.0,r/(r+1.0));
|
|
83
|
+
}
|
|
84
|
+
gl_FragColor=l+vec4(f*w,f);
|
|
85
|
+
}`;
|
|
86
|
+
|
|
87
|
+
const VS_MARKER = `varying vec2 m;
|
|
88
|
+
varying vec3 g;
|
|
89
|
+
varying float h;
|
|
90
|
+
attribute vec2 n;
|
|
91
|
+
attribute vec3 p,w;
|
|
92
|
+
attribute float q,x;
|
|
93
|
+
uniform vec2 b,r;
|
|
94
|
+
uniform float i,j,k,s;
|
|
95
|
+
void main(){
|
|
96
|
+
float c=cos(j),d=sin(j),e=cos(i),f=sin(i);
|
|
97
|
+
vec3 a=p*(0.8+s);
|
|
98
|
+
vec3 l=vec3(e*a.x+f*a.z,f*d*a.x+c*a.y-e*d*a.z,-f*c*a.x+d*a.y+e*c*a.z);
|
|
99
|
+
if(l.z<0.0&&length(l.xy)<0.8){
|
|
100
|
+
gl_Position=vec4(2.0,2.0,0.0,1.0);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
float t=b.y/b.x;
|
|
104
|
+
vec2 y=(l.xy+n*q*2.0)*vec2(t,1.0)*k+r*vec2(1.0,-1.0)*k/b;
|
|
105
|
+
gl_Position=vec4(y,0.0,1.0);
|
|
106
|
+
m=n;
|
|
107
|
+
g=w;
|
|
108
|
+
h=x;
|
|
109
|
+
}`;
|
|
110
|
+
|
|
111
|
+
const FS_MARKER = `precision highp float;
|
|
112
|
+
varying vec2 m;
|
|
113
|
+
varying vec3 g;
|
|
114
|
+
varying float h;
|
|
115
|
+
uniform vec3 v;
|
|
116
|
+
void main(){
|
|
117
|
+
if(length(m)>0.25) discard;
|
|
118
|
+
vec3 a=h>0.5?g:v;
|
|
119
|
+
gl_FragColor=vec4(a,1.0);
|
|
120
|
+
}`;
|
|
121
|
+
|
|
122
|
+
const VS_ARC = `varying vec3 i;
|
|
123
|
+
varying float j,s,t;
|
|
124
|
+
attribute vec2 k;
|
|
125
|
+
attribute vec3 l,m,N;
|
|
126
|
+
attribute float v,w,O;
|
|
127
|
+
uniform vec2 g,x;
|
|
128
|
+
uniform float y,z,h,A;
|
|
129
|
+
mat3 B(float a,float b){
|
|
130
|
+
float c=cos(a),d=cos(b),e=sin(a),f=sin(b);
|
|
131
|
+
return mat3(d,f*e,-f*c,0.0,c,e,f,d*-e,d*c);
|
|
132
|
+
}
|
|
133
|
+
vec3 C(vec3 c,vec3 d,vec3 e,float a){
|
|
134
|
+
float b=1.0-a;
|
|
135
|
+
return b*b*c+2.0*b*a*d+a*a*e;
|
|
136
|
+
}
|
|
137
|
+
vec3 D(vec3 c,vec3 b,vec3 d,float a){
|
|
138
|
+
float e=1.0-a;
|
|
139
|
+
return 2.0*e*(b-c)+2.0*a*(d-b);
|
|
140
|
+
}
|
|
141
|
+
void main(){
|
|
142
|
+
mat3 b=B(z,y);
|
|
143
|
+
float c=0.8+A;
|
|
144
|
+
vec3 d=l*c,e=m*c,f=l+m;
|
|
145
|
+
float n=length(f);
|
|
146
|
+
vec3 E=n>0.001?f/n:vec3(0.0,1.0,0.0);
|
|
147
|
+
vec3 o=E*(0.8+v);
|
|
148
|
+
float p=k.x;
|
|
149
|
+
vec3 F=C(d,o,e,p);
|
|
150
|
+
vec3 q=b*F;
|
|
151
|
+
vec3 G=D(d,o,e,p);
|
|
152
|
+
vec3 H=b*G;
|
|
153
|
+
vec2 a=H.xy;
|
|
154
|
+
float r=length(a);
|
|
155
|
+
vec2 I=r>0.001?vec2(-a.y,a.x)/r:vec2(1.0,0.0);
|
|
156
|
+
float J=g.x/g.y;
|
|
157
|
+
vec2 K=q.xy*vec2(1.0/J,1.0)*h+x*vec2(1.0,-1.0)*h/g;
|
|
158
|
+
vec2 P=K+I*w*k.y*h;
|
|
159
|
+
gl_Position=vec4(P,0.0,1.0);
|
|
160
|
+
i=N;
|
|
161
|
+
j=O;
|
|
162
|
+
s=q.z;
|
|
163
|
+
t=length(q.xy);
|
|
164
|
+
}`;
|
|
165
|
+
|
|
166
|
+
const FS_ARC = `precision highp float;
|
|
167
|
+
varying vec3 i;
|
|
168
|
+
varying float j,s,t;
|
|
169
|
+
uniform vec3 M;
|
|
170
|
+
void main(){
|
|
171
|
+
if(s<0.0&&t<0.8) discard;
|
|
172
|
+
vec3 a=j>0.5?i:M;
|
|
173
|
+
gl_FragColor=vec4(a,1.0);
|
|
174
|
+
}`;
|
|
175
|
+
|
|
176
|
+
const SPHERE_BASE_RADIUS = 0.8;
|
|
177
|
+
const LANDMASS_IMAGE =
|
|
178
|
+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAACAAQAAAADMzoqnAAAECklEQVR42u3VsW4jRRzH8d94gzfF4Q0VQaC4vBLTRTp0mze4ggfAPAE5XQEFsGNAVIjwBrmW7h7gJE+giKjyABTZE4g06LKJETdRJvtD65kdz6yduKABiW+TVfzRf2bXYxtcE/59YJCz6YdbgQF6ACSRrwYKYImmh5PbwOewlV3wlQNbAN6SEExjUOO+BU0aCSnxReHABUlK4YFQeJeUT3da8IIkZ6NGoSnFY5KsMoVzMKfECUnqxgPYRArarmUCndHwzIEaQEpg5xVdBXROl8mpAQx5dUgPiHoYAAkg5w3JABR06byGAVgcRGAz5bznj6phBQNRFwyqgdxebH6gshJAesWoFhgYpApAFoG8BIZ/fEhSox5jDjQXmV0Ar5XJfAIrALi3URVs09gHIL4XJCkLC5LH9JWiArABFCSrQjdgkBzRJ0WJeUOSNyQAfJJwUSWUBRlJQ8oGHATACGlBynnzy2kEYLNjrxouigD8BZcgOeVPqh12RtufaCN5wCPVDpvQ9lsIrqndsJtDcWqBCpf4hWN7OdWHBw58FwIaNOU/n1TpMW2DFaD48cmr4185T8NHkpUFX749pQPVdgRKC/DGoQPVeAEKv+WHvY8OOWNTPRp5kHuwSf8wzXtVBKR7YwEH9H3lQUaypUfSATOALyVNu5vZJW31Bnx98nkLfDUWJaz6ixvm+RIQRdl3kmRxxiaDoGnZW4CpPfkaQadlcPim1xOSvETQo7Lv75enVAXJ3xGUlony4KQBBWUM1NiDc6qhyS8RgQs18OCMMtPDaAUIyg0PZkRWDqs+wnKJBTDI1Js6BolegOsKmUxNDBAAKqQyMQmidhegBlLZ+wwKYdv5M/8x1khkb1cgKqP2H+MKyV5vS+whrE8DQDgAlUAoRBX056EElJCjJVACeJBZgNfVp+iCCm4RBWCgKsRxASSA9KgDhDtCiTuMyfHsKXzhC6wNAIjjWb8LKAOA2ctk3FmCOlgKFy8f1N0JJtgsxinYnVAHt4t3gPzZXSCTyCWCQmBT91QE3B5yarSN40dNHYPka4TlDhTUI8zLvl0JSL3vZn6DsCFZOeB2yROEpR68sECQQA++xIGCR2X7DwlEoLRgUrZrqlUg50S1uy43YqDcN6UFBVkhAjWiCV2Q0jgQPdplMKxvBXodcOfAwJYvgdL+1etA1YJJfBcZlQV7sO1i2gHoNiyxtQ5sBsCgWyoxCHiFFd2L5nUTCqMAqGUgsQ9f5kCcCiZgRYkMgMTd5WsB1rTzj0Em14BE4r+QxN1lCEsVur2PoF5Wbg8RJXR4djgvBgauhLywoEZQrt1KKRdVS4CdlJ8qafyP+9KIj/nE/d7kKwH9jgS72e9DV+kvfTWgct4ZyP8Byb8BPG7MaaIIkAQAAAAASUVORK5CYII=';
|
|
179
|
+
|
|
180
|
+
function createShader(gl, type, source) {
|
|
181
|
+
const shader = gl.createShader(type);
|
|
182
|
+
gl.shaderSource(shader, source);
|
|
183
|
+
gl.compileShader(shader);
|
|
184
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
185
|
+
gl.deleteShader(shader);
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
return shader;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function createProgram(gl, vsSource, fsSource) {
|
|
192
|
+
const vs = createShader(gl, gl.VERTEX_SHADER, vsSource);
|
|
193
|
+
const fs = createShader(gl, gl.FRAGMENT_SHADER, fsSource);
|
|
194
|
+
if (!vs || !fs) return null;
|
|
195
|
+
const program = gl.createProgram();
|
|
196
|
+
gl.attachShader(program, vs);
|
|
197
|
+
gl.attachShader(program, fs);
|
|
198
|
+
gl.linkProgram(program);
|
|
199
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
200
|
+
gl.deleteShader(vs);
|
|
201
|
+
gl.deleteShader(fs);
|
|
202
|
+
gl.deleteProgram(program);
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
return program;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function getUniforms(gl, program, names) {
|
|
209
|
+
const map = {};
|
|
210
|
+
for (const name of names) {
|
|
211
|
+
map[name] = gl.getUniformLocation(program, name);
|
|
212
|
+
}
|
|
213
|
+
return map;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function getAttributes(gl, program, names) {
|
|
217
|
+
const map = {};
|
|
218
|
+
for (const name of names) {
|
|
219
|
+
map[name] = gl.getAttribLocation(program, name);
|
|
220
|
+
}
|
|
221
|
+
return map;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function locationToSphere([lat, lon]) {
|
|
225
|
+
const phi = (lat * Math.PI) / 180;
|
|
226
|
+
const theta = (lon * Math.PI) / 180 - Math.PI;
|
|
227
|
+
const cosPhi = Math.cos(phi);
|
|
228
|
+
return [-cosPhi * Math.cos(theta), Math.sin(phi), cosPhi * Math.sin(theta)];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function setupVertexAttrib(gl, location, size, stride, offset, divisor, isWebGL2, ext) {
|
|
232
|
+
if (location < 0) return;
|
|
233
|
+
gl.enableVertexAttribArray(location);
|
|
234
|
+
gl.vertexAttribPointer(location, size, gl.FLOAT, false, stride, offset);
|
|
235
|
+
if (isWebGL2) {
|
|
236
|
+
gl.vertexAttribDivisor(location, divisor);
|
|
237
|
+
} else if (ext) {
|
|
238
|
+
ext.vertexAttribDivisorANGLE(location, divisor);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Creates and renders a standalone WebGL 3D globe.
|
|
244
|
+
*
|
|
245
|
+
* @param {HTMLCanvasElement} canvas
|
|
246
|
+
* @param {Object} opts
|
|
247
|
+
* @returns {{ update: (opts: Object) => void, destroy: () => void }}
|
|
248
|
+
*/
|
|
249
|
+
export function createGlobe(canvas, opts) {
|
|
250
|
+
const contextAttrs = {
|
|
251
|
+
alpha: true,
|
|
252
|
+
stencil: false,
|
|
253
|
+
antialias: true,
|
|
254
|
+
depth: false,
|
|
255
|
+
preserveDrawingBuffer: false,
|
|
256
|
+
...opts.context,
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
let gl = canvas.getContext('webgl2', contextAttrs);
|
|
260
|
+
const isWebGL2 = !!gl;
|
|
261
|
+
if (!gl) {
|
|
262
|
+
gl = canvas.getContext('webgl', contextAttrs);
|
|
263
|
+
}
|
|
264
|
+
if (!gl) {
|
|
265
|
+
return { destroy: () => {}, update: () => {} };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const ext = isWebGL2 ? null : gl.getExtension('ANGLE_instanced_arrays');
|
|
269
|
+
const dpr = opts.devicePixelRatio || (typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1);
|
|
270
|
+
|
|
271
|
+
canvas.width = (opts.width || 500) * dpr;
|
|
272
|
+
canvas.height = (opts.height || 500) * dpr;
|
|
273
|
+
|
|
274
|
+
let phi = opts.phi || 0;
|
|
275
|
+
let theta = opts.theta || 0;
|
|
276
|
+
let markers = opts.markers || [];
|
|
277
|
+
let arcs = opts.arcs || [];
|
|
278
|
+
let mapSamples = opts.mapSamples || 16000;
|
|
279
|
+
let mapBrightness = opts.mapBrightness ?? 6;
|
|
280
|
+
let mapBaseBrightness = opts.mapBaseBrightness ?? 0;
|
|
281
|
+
let baseColor = opts.baseColor || [0.8, 0.85, 0.9];
|
|
282
|
+
let markerColor = opts.markerColor || [0.15, 0.5, 1.0];
|
|
283
|
+
let glowColor = opts.glowColor || [1, 1, 1];
|
|
284
|
+
let arcColor = opts.arcColor || [0.3, 0.6, 1.0];
|
|
285
|
+
let arcWidth = opts.arcWidth ?? 1;
|
|
286
|
+
let arcHeight = opts.arcHeight ?? 0.2;
|
|
287
|
+
let diffuse = opts.diffuse ?? 1.2;
|
|
288
|
+
let dark = opts.dark ?? 0;
|
|
289
|
+
let opacity = opts.opacity ?? 1;
|
|
290
|
+
let offset = opts.offset || [0, 0];
|
|
291
|
+
let scale = opts.scale ?? 1;
|
|
292
|
+
let markerElevation = opts.markerElevation ?? 0.05;
|
|
293
|
+
|
|
294
|
+
const globeProgram = createProgram(gl, VS_QUAD, FS_GLOBE);
|
|
295
|
+
const markerProgram = createProgram(gl, VS_MARKER, FS_MARKER);
|
|
296
|
+
const arcProgram = createProgram(gl, VS_ARC, FS_ARC);
|
|
297
|
+
|
|
298
|
+
if (!globeProgram) {
|
|
299
|
+
return { destroy: () => {}, update: () => {} };
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Buffers
|
|
303
|
+
const quadBuffer = gl.createBuffer();
|
|
304
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, quadBuffer);
|
|
305
|
+
gl.bufferData(
|
|
306
|
+
gl.ARRAY_BUFFER,
|
|
307
|
+
new Float32Array([-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1]),
|
|
308
|
+
gl.STATIC_DRAW
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
const arcStripBuffer = gl.createBuffer();
|
|
312
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, arcStripBuffer);
|
|
313
|
+
const stripPoints = [];
|
|
314
|
+
for (let i = 0; i <= 32; i++) {
|
|
315
|
+
const t = i / 32;
|
|
316
|
+
stripPoints.push(t, -1, t, 1);
|
|
317
|
+
}
|
|
318
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(stripPoints), gl.STATIC_DRAW);
|
|
319
|
+
|
|
320
|
+
const markerBuffer = gl.createBuffer();
|
|
321
|
+
const arcBuffer = gl.createBuffer();
|
|
322
|
+
|
|
323
|
+
const globeUniforms = getUniforms(gl, globeProgram, ['t', 's', 'k', 'x', 'v', 'F', 'w', 'n', 'y', 'z']);
|
|
324
|
+
const markerUniforms = markerProgram ? getUniforms(gl, markerProgram, ['i', 'j', 'b', 'k', 'r', 'v', 's']) : {};
|
|
325
|
+
const markerAttribs = markerProgram ? getAttributes(gl, markerProgram, ['n', 'p', 'q', 'w', 'x']) : {};
|
|
326
|
+
const arcUniforms = arcProgram ? getUniforms(gl, arcProgram, ['y', 'z', 'g', 'h', 'x', 'M', 'A']) : {};
|
|
327
|
+
const arcAttribs = arcProgram ? getAttributes(gl, arcProgram, ['k', 'l', 'm', 'v', 'w', 'N', 'O']) : {};
|
|
328
|
+
const globePosAttrib = gl.getAttribLocation(globeProgram, 'a');
|
|
329
|
+
|
|
330
|
+
// Landmass Texture
|
|
331
|
+
const texture = gl.createTexture();
|
|
332
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
333
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, 1, 1, 0, gl.RGB, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0]));
|
|
334
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
335
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
336
|
+
|
|
337
|
+
const img = new Image();
|
|
338
|
+
img.onload = () => {
|
|
339
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
340
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, img);
|
|
341
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
342
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
343
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
344
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
345
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
346
|
+
};
|
|
347
|
+
img.src = LANDMASS_IMAGE;
|
|
348
|
+
|
|
349
|
+
let arcCount = 0;
|
|
350
|
+
|
|
351
|
+
function updateMarkers(list) {
|
|
352
|
+
markers = list;
|
|
353
|
+
const data = new Float32Array(8 * markers.length);
|
|
354
|
+
markers.forEach((m, idx) => {
|
|
355
|
+
data.set(
|
|
356
|
+
[
|
|
357
|
+
...locationToSphere(m.location),
|
|
358
|
+
m.size,
|
|
359
|
+
...(m.color || [0, 0, 0]),
|
|
360
|
+
m.color ? 1 : 0,
|
|
361
|
+
],
|
|
362
|
+
8 * idx
|
|
363
|
+
);
|
|
364
|
+
});
|
|
365
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, markerBuffer);
|
|
366
|
+
gl.bufferData(gl.ARRAY_BUFFER, data, gl.DYNAMIC_DRAW);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function updateArcs(list) {
|
|
370
|
+
arcs = list;
|
|
371
|
+
arcCount = arcs.length;
|
|
372
|
+
const data = new Float32Array(12 * arcs.length);
|
|
373
|
+
arcs.forEach((a, idx) => {
|
|
374
|
+
data.set(
|
|
375
|
+
[
|
|
376
|
+
...locationToSphere(a.from),
|
|
377
|
+
...locationToSphere(a.to),
|
|
378
|
+
arcHeight + markerElevation,
|
|
379
|
+
0.005 * arcWidth,
|
|
380
|
+
...(a.color || [0, 0, 0]),
|
|
381
|
+
a.color ? 1 : 0,
|
|
382
|
+
],
|
|
383
|
+
12 * idx
|
|
384
|
+
);
|
|
385
|
+
});
|
|
386
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, arcBuffer);
|
|
387
|
+
gl.bufferData(gl.ARRAY_BUFFER, data, gl.DYNAMIC_DRAW);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function render(nextOpts = {}) {
|
|
391
|
+
if (nextOpts.phi !== undefined) phi = nextOpts.phi;
|
|
392
|
+
if (nextOpts.theta !== undefined) theta = nextOpts.theta;
|
|
393
|
+
if (nextOpts.markers !== undefined) updateMarkers(nextOpts.markers);
|
|
394
|
+
if (nextOpts.arcs !== undefined) updateArcs(nextOpts.arcs);
|
|
395
|
+
|
|
396
|
+
if (nextOpts.width && nextOpts.height) {
|
|
397
|
+
canvas.width = nextOpts.width * dpr;
|
|
398
|
+
canvas.height = nextOpts.height * dpr;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if (nextOpts.mapSamples !== undefined) mapSamples = nextOpts.mapSamples;
|
|
402
|
+
if (nextOpts.mapBrightness !== undefined) mapBrightness = nextOpts.mapBrightness;
|
|
403
|
+
if (nextOpts.mapBaseBrightness !== undefined) mapBaseBrightness = nextOpts.mapBaseBrightness;
|
|
404
|
+
if (nextOpts.baseColor !== undefined) baseColor = nextOpts.baseColor;
|
|
405
|
+
if (nextOpts.markerColor !== undefined) markerColor = nextOpts.markerColor;
|
|
406
|
+
if (nextOpts.glowColor !== undefined) glowColor = nextOpts.glowColor;
|
|
407
|
+
if (nextOpts.arcColor !== undefined) arcColor = nextOpts.arcColor;
|
|
408
|
+
if (nextOpts.arcWidth !== undefined) arcWidth = nextOpts.arcWidth;
|
|
409
|
+
if (nextOpts.arcHeight !== undefined) arcHeight = nextOpts.arcHeight;
|
|
410
|
+
if (nextOpts.diffuse !== undefined) diffuse = nextOpts.diffuse;
|
|
411
|
+
if (nextOpts.dark !== undefined) dark = nextOpts.dark;
|
|
412
|
+
if (nextOpts.opacity !== undefined) opacity = nextOpts.opacity;
|
|
413
|
+
if (nextOpts.offset !== undefined) offset = nextOpts.offset;
|
|
414
|
+
if (nextOpts.scale !== undefined) scale = nextOpts.scale;
|
|
415
|
+
if (nextOpts.markerElevation !== undefined) markerElevation = nextOpts.markerElevation;
|
|
416
|
+
|
|
417
|
+
gl.viewport(0, 0, canvas.width, canvas.height);
|
|
418
|
+
gl.clearColor(0, 0, 0, 0);
|
|
419
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
420
|
+
gl.enable(gl.BLEND);
|
|
421
|
+
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
|
422
|
+
|
|
423
|
+
// Render Base Globe
|
|
424
|
+
gl.useProgram(globeProgram);
|
|
425
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, quadBuffer);
|
|
426
|
+
gl.enableVertexAttribArray(globePosAttrib);
|
|
427
|
+
gl.vertexAttribPointer(globePosAttrib, 2, gl.FLOAT, false, 0, 0);
|
|
428
|
+
if (isWebGL2) {
|
|
429
|
+
gl.vertexAttribDivisor(globePosAttrib, 0);
|
|
430
|
+
} else if (ext) {
|
|
431
|
+
ext.vertexAttribDivisorANGLE(globePosAttrib, 0);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
gl.uniform2f(globeUniforms.t, canvas.width, canvas.height);
|
|
435
|
+
gl.uniform2f(globeUniforms.s, phi, theta);
|
|
436
|
+
gl.uniform1f(globeUniforms.k, mapSamples);
|
|
437
|
+
gl.uniform1f(globeUniforms.x, scale);
|
|
438
|
+
gl.uniform2f(globeUniforms.v, offset[0] * dpr, offset[1] * dpr);
|
|
439
|
+
gl.uniform3fv(globeUniforms.F, baseColor);
|
|
440
|
+
gl.uniform3fv(globeUniforms.w, glowColor);
|
|
441
|
+
gl.uniform4f(globeUniforms.n, mapBrightness, diffuse, dark, opacity);
|
|
442
|
+
gl.uniform1f(globeUniforms.y, mapBaseBrightness);
|
|
443
|
+
gl.uniform1i(globeUniforms.z, 0);
|
|
444
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
445
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
446
|
+
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
|
447
|
+
|
|
448
|
+
// Render Arcs
|
|
449
|
+
if (arcProgram && arcCount > 0) {
|
|
450
|
+
gl.useProgram(arcProgram);
|
|
451
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, arcStripBuffer);
|
|
452
|
+
if (arcAttribs.k >= 0) {
|
|
453
|
+
gl.enableVertexAttribArray(arcAttribs.k);
|
|
454
|
+
gl.vertexAttribPointer(arcAttribs.k, 2, gl.FLOAT, false, 0, 0);
|
|
455
|
+
if (isWebGL2) gl.vertexAttribDivisor(arcAttribs.k, 0);
|
|
456
|
+
else if (ext) ext.vertexAttribDivisorANGLE(arcAttribs.k, 0);
|
|
457
|
+
}
|
|
458
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, arcBuffer);
|
|
459
|
+
const arcStride = 48;
|
|
460
|
+
setupVertexAttrib(gl, arcAttribs.l, 3, arcStride, 0, 1, isWebGL2, ext);
|
|
461
|
+
setupVertexAttrib(gl, arcAttribs.m, 3, arcStride, 12, 1, isWebGL2, ext);
|
|
462
|
+
setupVertexAttrib(gl, arcAttribs.v, 1, arcStride, 24, 1, isWebGL2, ext);
|
|
463
|
+
setupVertexAttrib(gl, arcAttribs.w, 1, arcStride, 28, 1, isWebGL2, ext);
|
|
464
|
+
setupVertexAttrib(gl, arcAttribs.N, 3, arcStride, 32, 1, isWebGL2, ext);
|
|
465
|
+
setupVertexAttrib(gl, arcAttribs.O, 1, arcStride, 44, 1, isWebGL2, ext);
|
|
466
|
+
|
|
467
|
+
gl.uniform1f(arcUniforms.y, phi);
|
|
468
|
+
gl.uniform1f(arcUniforms.z, theta);
|
|
469
|
+
gl.uniform2f(arcUniforms.g, canvas.width, canvas.height);
|
|
470
|
+
gl.uniform1f(arcUniforms.h, scale);
|
|
471
|
+
gl.uniform2f(arcUniforms.x, offset[0] * dpr, offset[1] * dpr);
|
|
472
|
+
gl.uniform3fv(arcUniforms.M, arcColor);
|
|
473
|
+
gl.uniform1f(arcUniforms.A, markerElevation);
|
|
474
|
+
|
|
475
|
+
if (isWebGL2) {
|
|
476
|
+
gl.drawArraysInstanced(gl.TRIANGLE_STRIP, 0, 66, arcCount);
|
|
477
|
+
} else if (ext) {
|
|
478
|
+
ext.drawArraysInstancedANGLE(gl.TRIANGLE_STRIP, 0, 66, arcCount);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// Render Markers
|
|
483
|
+
if (markerProgram && markers.length > 0) {
|
|
484
|
+
gl.useProgram(markerProgram);
|
|
485
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, quadBuffer);
|
|
486
|
+
if (markerAttribs.n >= 0) {
|
|
487
|
+
gl.enableVertexAttribArray(markerAttribs.n);
|
|
488
|
+
gl.vertexAttribPointer(markerAttribs.n, 2, gl.FLOAT, false, 0, 0);
|
|
489
|
+
if (isWebGL2) gl.vertexAttribDivisor(markerAttribs.n, 0);
|
|
490
|
+
else if (ext) ext.vertexAttribDivisorANGLE(markerAttribs.n, 0);
|
|
491
|
+
}
|
|
492
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, markerBuffer);
|
|
493
|
+
const markerStride = 32;
|
|
494
|
+
setupVertexAttrib(gl, markerAttribs.p, 3, markerStride, 0, 1, isWebGL2, ext);
|
|
495
|
+
setupVertexAttrib(gl, markerAttribs.q, 1, markerStride, 12, 1, isWebGL2, ext);
|
|
496
|
+
setupVertexAttrib(gl, markerAttribs.w, 3, markerStride, 16, 1, isWebGL2, ext);
|
|
497
|
+
setupVertexAttrib(gl, markerAttribs.x, 1, markerStride, 28, 1, isWebGL2, ext);
|
|
498
|
+
|
|
499
|
+
gl.uniform1f(markerUniforms.i, phi);
|
|
500
|
+
gl.uniform1f(markerUniforms.j, theta);
|
|
501
|
+
gl.uniform2f(markerUniforms.b, canvas.width, canvas.height);
|
|
502
|
+
gl.uniform1f(markerUniforms.k, scale);
|
|
503
|
+
gl.uniform2f(markerUniforms.r, offset[0] * dpr, offset[1] * dpr);
|
|
504
|
+
gl.uniform3fv(markerUniforms.v, markerColor);
|
|
505
|
+
gl.uniform1f(markerUniforms.s, markerElevation);
|
|
506
|
+
|
|
507
|
+
if (isWebGL2) {
|
|
508
|
+
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, markers.length);
|
|
509
|
+
} else if (ext) {
|
|
510
|
+
ext.drawArraysInstancedANGLE(gl.TRIANGLES, 0, 6, markers.length);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// Initial draw
|
|
516
|
+
render({ markers, arcs });
|
|
517
|
+
|
|
518
|
+
return {
|
|
519
|
+
update: render,
|
|
520
|
+
destroy: () => {
|
|
521
|
+
gl.deleteBuffer(quadBuffer);
|
|
522
|
+
gl.deleteBuffer(arcStripBuffer);
|
|
523
|
+
gl.deleteBuffer(markerBuffer);
|
|
524
|
+
gl.deleteBuffer(arcBuffer);
|
|
525
|
+
gl.deleteTexture(texture);
|
|
526
|
+
gl.deleteProgram(globeProgram);
|
|
527
|
+
if (markerProgram) gl.deleteProgram(markerProgram);
|
|
528
|
+
if (arcProgram) gl.deleteProgram(arcProgram);
|
|
529
|
+
},
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* cynx-lib Globe Component
|
|
535
|
+
*/
|
|
536
|
+
export default function Globe({
|
|
537
|
+
width,
|
|
538
|
+
height,
|
|
539
|
+
phi = 0,
|
|
540
|
+
theta = 0.3,
|
|
541
|
+
autoRotate = true,
|
|
542
|
+
autoRotateSpeed = 0.003,
|
|
543
|
+
draggable = true,
|
|
544
|
+
dark = 0,
|
|
545
|
+
diffuse = 1.2,
|
|
546
|
+
mapSamples = 16000,
|
|
547
|
+
mapBrightness = 6,
|
|
548
|
+
mapBaseBrightness = 0,
|
|
549
|
+
baseColor,
|
|
550
|
+
markerColor = [0.15, 0.5, 1.0],
|
|
551
|
+
glowColor = [1, 1, 1],
|
|
552
|
+
arcColor = [0.2, 0.55, 1.0],
|
|
553
|
+
arcWidth = 1,
|
|
554
|
+
arcHeight = 0.2,
|
|
555
|
+
markers = [],
|
|
556
|
+
arcs = [],
|
|
557
|
+
scale = 1,
|
|
558
|
+
offset = [0, 0],
|
|
559
|
+
markerElevation = 0.05,
|
|
560
|
+
onRender,
|
|
561
|
+
className = '',
|
|
562
|
+
style = {},
|
|
563
|
+
}) {
|
|
564
|
+
const containerRef = useRef(null);
|
|
565
|
+
const canvasRef = useRef(null);
|
|
566
|
+
const globeInstanceRef = useRef(null);
|
|
567
|
+
const animFrameIdRef = useRef(null);
|
|
568
|
+
|
|
569
|
+
const rotationRef = useRef({ phi, theta });
|
|
570
|
+
const isDraggingRef = useRef(false);
|
|
571
|
+
const pointerStartRef = useRef({ x: 0, y: 0, phi: 0, theta: 0 });
|
|
572
|
+
|
|
573
|
+
// Default theme-aware base colors
|
|
574
|
+
const activeBaseColor = baseColor || (dark === 1 ? [0.28, 0.3, 0.38] : [0.8, 0.85, 0.92]);
|
|
575
|
+
|
|
576
|
+
// Pointer drag events for smooth rotation
|
|
577
|
+
const handlePointerDown = useCallback(
|
|
578
|
+
(e) => {
|
|
579
|
+
if (!draggable) return;
|
|
580
|
+
isDraggingRef.current = true;
|
|
581
|
+
pointerStartRef.current = {
|
|
582
|
+
x: e.clientX,
|
|
583
|
+
y: e.clientY,
|
|
584
|
+
phi: rotationRef.current.phi,
|
|
585
|
+
theta: rotationRef.current.theta,
|
|
586
|
+
};
|
|
587
|
+
if (e.currentTarget?.setPointerCapture) {
|
|
588
|
+
try {
|
|
589
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
590
|
+
} catch (_) {}
|
|
591
|
+
}
|
|
592
|
+
},
|
|
593
|
+
[draggable]
|
|
594
|
+
);
|
|
595
|
+
|
|
596
|
+
const handlePointerMove = useCallback(
|
|
597
|
+
(e) => {
|
|
598
|
+
if (!isDraggingRef.current || !draggable) return;
|
|
599
|
+
const dx = e.clientX - pointerStartRef.current.x;
|
|
600
|
+
const dy = e.clientY - pointerStartRef.current.y;
|
|
601
|
+
rotationRef.current.phi = pointerStartRef.current.phi + dx * 0.005;
|
|
602
|
+
const nextTheta = pointerStartRef.current.theta - dy * 0.005;
|
|
603
|
+
rotationRef.current.theta = Math.max(-Math.PI / 2.2, Math.min(Math.PI / 2.2, nextTheta));
|
|
604
|
+
},
|
|
605
|
+
[draggable]
|
|
606
|
+
);
|
|
607
|
+
|
|
608
|
+
const handlePointerUp = useCallback(
|
|
609
|
+
(e) => {
|
|
610
|
+
if (!isDraggingRef.current) return;
|
|
611
|
+
isDraggingRef.current = false;
|
|
612
|
+
if (e.currentTarget?.releasePointerCapture) {
|
|
613
|
+
try {
|
|
614
|
+
e.currentTarget.releasePointerCapture(e.pointerId);
|
|
615
|
+
} catch (_) {}
|
|
616
|
+
}
|
|
617
|
+
},
|
|
618
|
+
[]
|
|
619
|
+
);
|
|
620
|
+
|
|
621
|
+
useEffect(() => {
|
|
622
|
+
const canvas = canvasRef.current;
|
|
623
|
+
const container = containerRef.current;
|
|
624
|
+
if (!canvas || !container) return;
|
|
625
|
+
|
|
626
|
+
const initialWidth = width || container.clientWidth || 400;
|
|
627
|
+
const initialHeight = height || container.clientHeight || 400;
|
|
628
|
+
|
|
629
|
+
const globe = createGlobe(canvas, {
|
|
630
|
+
width: initialWidth,
|
|
631
|
+
height: initialHeight,
|
|
632
|
+
phi: rotationRef.current.phi,
|
|
633
|
+
theta: rotationRef.current.theta,
|
|
634
|
+
dark,
|
|
635
|
+
diffuse,
|
|
636
|
+
scale,
|
|
637
|
+
offset,
|
|
638
|
+
mapSamples,
|
|
639
|
+
mapBrightness,
|
|
640
|
+
mapBaseBrightness,
|
|
641
|
+
baseColor: activeBaseColor,
|
|
642
|
+
markerColor,
|
|
643
|
+
glowColor,
|
|
644
|
+
arcColor,
|
|
645
|
+
arcWidth,
|
|
646
|
+
arcHeight,
|
|
647
|
+
markerElevation,
|
|
648
|
+
markers,
|
|
649
|
+
arcs,
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
globeInstanceRef.current = globe;
|
|
653
|
+
|
|
654
|
+
let isMounted = true;
|
|
655
|
+
|
|
656
|
+
const loop = () => {
|
|
657
|
+
if (!isMounted) return;
|
|
658
|
+
|
|
659
|
+
if (autoRotate && !isDraggingRef.current) {
|
|
660
|
+
rotationRef.current.phi += autoRotateSpeed;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
const state = {
|
|
664
|
+
phi: rotationRef.current.phi,
|
|
665
|
+
theta: rotationRef.current.theta,
|
|
666
|
+
width: width || container.clientWidth || 400,
|
|
667
|
+
height: height || container.clientHeight || 400,
|
|
668
|
+
dark,
|
|
669
|
+
diffuse,
|
|
670
|
+
scale,
|
|
671
|
+
offset,
|
|
672
|
+
mapSamples,
|
|
673
|
+
mapBrightness,
|
|
674
|
+
mapBaseBrightness,
|
|
675
|
+
baseColor: activeBaseColor,
|
|
676
|
+
markerColor,
|
|
677
|
+
glowColor,
|
|
678
|
+
arcColor,
|
|
679
|
+
arcWidth,
|
|
680
|
+
arcHeight,
|
|
681
|
+
markerElevation,
|
|
682
|
+
markers,
|
|
683
|
+
arcs,
|
|
684
|
+
};
|
|
685
|
+
|
|
686
|
+
if (onRender) {
|
|
687
|
+
onRender(state);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
globe.update(state);
|
|
691
|
+
animFrameIdRef.current = requestAnimationFrame(loop);
|
|
692
|
+
};
|
|
693
|
+
|
|
694
|
+
animFrameIdRef.current = requestAnimationFrame(loop);
|
|
695
|
+
|
|
696
|
+
return () => {
|
|
697
|
+
isMounted = false;
|
|
698
|
+
if (animFrameIdRef.current) {
|
|
699
|
+
cancelAnimationFrame(animFrameIdRef.current);
|
|
700
|
+
}
|
|
701
|
+
globe.destroy();
|
|
702
|
+
globeInstanceRef.current = null;
|
|
703
|
+
};
|
|
704
|
+
}, [
|
|
705
|
+
width,
|
|
706
|
+
height,
|
|
707
|
+
autoRotate,
|
|
708
|
+
autoRotateSpeed,
|
|
709
|
+
dark,
|
|
710
|
+
diffuse,
|
|
711
|
+
scale,
|
|
712
|
+
offset,
|
|
713
|
+
mapSamples,
|
|
714
|
+
mapBrightness,
|
|
715
|
+
mapBaseBrightness,
|
|
716
|
+
activeBaseColor,
|
|
717
|
+
markerColor,
|
|
718
|
+
glowColor,
|
|
719
|
+
arcColor,
|
|
720
|
+
arcWidth,
|
|
721
|
+
arcHeight,
|
|
722
|
+
markerElevation,
|
|
723
|
+
markers,
|
|
724
|
+
arcs,
|
|
725
|
+
onRender,
|
|
726
|
+
]);
|
|
727
|
+
|
|
728
|
+
return (
|
|
729
|
+
<div
|
|
730
|
+
ref={containerRef}
|
|
731
|
+
className={className}
|
|
732
|
+
onPointerDown={handlePointerDown}
|
|
733
|
+
onPointerMove={handlePointerMove}
|
|
734
|
+
onPointerUp={handlePointerUp}
|
|
735
|
+
onPointerCancel={handlePointerUp}
|
|
736
|
+
style={{
|
|
737
|
+
position: 'relative',
|
|
738
|
+
width: width ? `${width}px` : '100%',
|
|
739
|
+
height: height ? `${height}px` : '100%',
|
|
740
|
+
maxWidth: '100%',
|
|
741
|
+
aspectRatio: !height ? '1 / 1' : undefined,
|
|
742
|
+
display: 'flex',
|
|
743
|
+
alignItems: 'center',
|
|
744
|
+
justifyContent: 'center',
|
|
745
|
+
touchAction: draggable ? 'none' : 'auto',
|
|
746
|
+
cursor: draggable ? (isDraggingRef.current ? 'grabbing' : 'grab') : 'default',
|
|
747
|
+
userSelect: 'none',
|
|
748
|
+
...style,
|
|
749
|
+
}}
|
|
750
|
+
>
|
|
751
|
+
<canvas
|
|
752
|
+
ref={canvasRef}
|
|
753
|
+
style={{
|
|
754
|
+
width: '100%',
|
|
755
|
+
height: '100%',
|
|
756
|
+
display: 'block',
|
|
757
|
+
contain: 'layout paint size',
|
|
758
|
+
}}
|
|
759
|
+
/>
|
|
760
|
+
</div>
|
|
761
|
+
);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
export { Globe };
|