Last active
April 25, 2017 22:52
-
-
Save burritojustice/5dffe406db5ff996574c2ce2380ff3a4 to your computer and use it in GitHub Desktop.
albers polygons, lines and points
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
styles: | |
albers: | |
base: polygons | |
animated: true | |
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 | |
blocks: | |
global: | | |
// http://wiki.openstreetmap.org/wiki/Mercator | |
float y2lat_m (float y) { return rad2deg(2.0*atan(exp((y/EARTH_RADIUS)))-HALF_PI); } | |
float x2lon_m (float x) { return rad2deg(x/EARTH_RADIUS); } | |
float lat2y_m (float lat) { return EARTH_RADIUS*log(tan(QUARTER_PI+ deg2rad(lat)/2.0)); } | |
float lon2x_m (float lon) { return deg2rad(lon)*EARTH_RADIUS; } | |
// convert from lat/long to albers -- from https://gist.github.com/RandomEtc/476238 | |
vec2 albers(float lat, float lng, float lat0, float lng0, float phi1, float phi2) { | |
float n = 0.5 * (sin(phi1) + sin(phi2)); | |
float c = cos(phi1); | |
float C = c*c + 2.*n*sin(phi1); | |
float p0 = sqrt(C - 2.*n*sin(lat0)) / n; | |
float theta = n * (lng * PI/180. - lng0); | |
float p = sqrt(C - 2.*n*sin(lat* PI/180.)) / n; | |
float x = p * sin(theta); | |
float y = p0 - p * cos(theta); | |
return vec2(x,y); | |
} | |
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(mercator.y); | |
float lon = x2lon_m(mercator.x); | |
// Latitude_Of_Origin | |
float centerlat = deg2rad(y2lat_m(u_map_position.y)); | |
// Central_Meridian | |
float centerlon = deg2rad(x2lon_m(u_map_position.x)); | |
// Standard_Parallel_1 | |
float phi1 = deg2rad(y2lat_m(u_map_position.y) + 10.); | |
// Standard_Parallel_2 | |
float phi2 = deg2rad(y2lat_m(u_map_position.y) - 10.); | |
position.xy = albers(lat, lon, centerlat, centerlon, phi1, phi2)*EARTH_RADIUS; | |
alberslines: | |
base: lines | |
mix: albers | |
alberspoints: | |
base: text | |
mix: albers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment