-
Notifications
You must be signed in to change notification settings - Fork 4
/
mollweide-points.yaml
68 lines (62 loc) · 3.06 KB
/
mollweide-points.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# contributors: @patriciogv @meetar
import: mercator-functions.yaml
styles:
projection_points:
mix: mollweide-points
mollweide-points:
mix: mercator-functions
shaders:
defines:
EARTH_RADIUS: 6378137.0
PI: 3.14159265358979323846
HALF_PI: 1.570796327
QUARTER_PI: .785398163
deg2rad(d): (d)*PI/180.0
rad2deg(d): (d)*180.0/PI
SQRT2: sqrt(2.0)
# MAX_ITER: 10
TOLERANCE: .0000001
blocks:
global: |
// http://wiki.openstreetmap.org/wiki/Mercator
float y2lat_d (float y) { return rad2deg( atan(exp( deg2rad(y) )) * 2.0 - HALF_PI ); }
float x2lon_d (float x) { return x; }
float lat2y_d(float lat) { return rad2deg( log(tan( deg2rad(lat) / 2.0 + PI/4.0 )) ); }
float lon2x_d(float lon) { return lon; }
float sp = sin(HALF_PI);
float r = sqrt(PI * 2.0 * sp / PI);
float cx = SQRT2 / HALF_PI;
float cy = SQRT2;
// convert from lat/lon to mollweide -- Adapted from https://github.com/d3/d3-geo-projection/blob/master/src/mollweide.js
float mollweideBromleyTheta(float phi) {
float cpsinPhi = PI * sin(phi);
for ( int i = 4; i != 0; i--) {
float delta = (phi + sin(phi) - cpsinPhi) / (1. + cos(phi));
phi -= delta;
}
return phi / 2.;
}
// x,y = lambda, phi
vec2 mollweide(float lambda, float phi) {
phi = mollweideBromleyTheta(phi);
return vec2(cx * lambda * cos(phi), cy * sin(phi));
}
position: |
// mercator position of the current vertex, u_map_position = center of screen,
// position.xy = vertex screen position in meters from the center of the screen
vec2 mercator = u_map_position.xy + position.xy;
float lat = y2lat_m(position.y);
float lon = x2lon_m(position.x);
if (abs(lon) > 180.) {
// clip the point
position.xy = vec2(3.402823466e+38);
} else {
// bend map into mollweide
lon = max(-180., lon);
lon = min(180., lon);
vec2 new = mollweide(deg2rad(lon), deg2rad(lat));
// TODO: factor out this magic number – possibly something related to the difference in coordinate systems?
float magic_number = 100.;
new = vec2(lon2x_m(new.x)*magic_number, lat2y_m(new.y)*magic_number);
position.xy = new;
}