1
- const EARTH_RADIUS_METERS = 6371008.8 ;
2
- const EARTH_CIRCUMFERENCE_METERS = 2 * Math . PI * EARTH_RADIUS_METERS ;
3
- const GLOBE_CIRCUMFERENCE_ECEF = 8192 ;
4
- const METERS_TO_ECEF = GLOBE_CIRCUMFERENCE_ECEF / EARTH_CIRCUMFERENCE_METERS ;
5
-
6
1
const KM_TO_M = 1000 ;
7
2
const TIME_STEP = 3 * 1000 ;
8
3
@@ -13,12 +8,19 @@ const globeVertCode = `
13
8
uniform mat4 u_projection;
14
9
uniform mat4 u_globeToMercMatrix;
15
10
uniform float u_globeToMercatorTransition;
11
+ uniform vec2 u_centerInMerc;
12
+ uniform float u_pixelsPerMeterRatio;
16
13
17
14
void main() {
18
15
vec4 p = u_projection * u_globeToMercMatrix * vec4(a_pos_ecef, 1.);
19
16
p /= p.w;
20
17
if (u_globeToMercatorTransition > 0.) {
21
- vec4 merc = u_projection * vec4(a_pos_merc, 1.);
18
+
19
+ vec4 merc = vec4(a_pos_merc, 1.);
20
+ merc.xy = (merc.xy - u_centerInMerc) * u_pixelsPerMeterRatio + u_centerInMerc;
21
+ merc.z *= u_pixelsPerMeterRatio;
22
+
23
+ merc = u_projection * merc;
22
24
merc /= merc.w;
23
25
p = mix(p, merc, u_globeToMercatorTransition);
24
26
}
@@ -141,21 +143,22 @@ const satellitesLayer = {
141
143
}
142
144
} ,
143
145
144
- render ( gl , projectionMatrix , projection , globeToMercMatrix , transition ) {
146
+ render ( gl , projectionMatrix , projection , globeToMercMatrix , transition , centerInMercator , pixelsPerMeterRatio ) {
145
147
if ( this . satData ) {
146
148
this . updateBuffers ( ) ;
147
149
148
150
const primitiveCount = this . posEcef . length / 3 ;
149
- gl . enable ( gl . DEPTH_TEST ) ;
151
+ gl . disable ( gl . DEPTH_TEST ) ;
150
152
if ( projection && projection . name === 'globe' ) { // globe projection and globe to mercator transition
151
153
gl . useProgram ( this . globeProgram ) ;
152
154
153
155
updateVboAndActivateAttrib ( gl , this . globeProgram , this . posEcefVbo , this . posEcef , "a_pos_ecef" ) ;
154
156
updateVboAndActivateAttrib ( gl , this . globeProgram , this . posMercVbo , this . posMerc , "a_pos_merc" ) ;
155
-
156
157
gl . uniformMatrix4fv ( gl . getUniformLocation ( this . globeProgram , "u_projection" ) , false , projectionMatrix ) ;
157
158
gl . uniformMatrix4fv ( gl . getUniformLocation ( this . globeProgram , "u_globeToMercMatrix" ) , false , globeToMercMatrix ) ;
158
159
gl . uniform1f ( gl . getUniformLocation ( this . globeProgram , "u_globeToMercatorTransition" ) , transition ) ;
160
+ gl . uniform2f ( gl . getUniformLocation ( this . globeProgram , "u_centerInMerc" ) , centerInMercator [ 0 ] , centerInMercator [ 1 ] ) ;
161
+ gl . uniform1f ( gl . getUniformLocation ( this . globeProgram , "u_pixelsPerMeterRatio" ) , pixelsPerMeterRatio ) ;
159
162
160
163
gl . drawArrays ( gl . POINTS , 0 , primitiveCount ) ;
161
164
} else { // mercator projection
0 commit comments