Skip to content

Commit

Permalink
Major code overhaul:
Browse files Browse the repository at this point in the history
- added support for self-contained share links
- reorganised files and folders
- moved all configuration to separate file
- added Norwegian elevation map
  • Loading branch information
Harmen G. Zijp committed Feb 8, 2021
1 parent b61d92e commit 810d387
Show file tree
Hide file tree
Showing 31 changed files with 5,330 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RewriteEngine On

RewriteRule js/(.*) js/$1 [L]
RewriteRule img/(.*) img/$1 [L]
RewriteRule glsl/(.*) glsl/$1 [L]
RewriteRule style/(.*) style/$1 [L]

RewriteRule config.json config.json [L]

RewriteRule ^([^\/]+)\/? index.html [L]
84 changes: 84 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"nl": {
"projection": {
"epsg": "EPSG:28992",
"proj4def": "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155022 +y_0=463015 +ellps=bessel +towgs84=565.417,50.3319,465.552,-0.398957,0.343988,-1.8774,4.0725 +units=m +no_defs",
"extent": [-285401.92,22598.08,595401.92,903402.0]
},
"backgroundmap": {
"wmts": "https://geodata.nationaalgeoregister.nl/tiles/service/wmts/brtachtergrondkaart",
"layer": "brtachtergrondkaart",
"resolutions": [3440.64, 1720.32, 860.16, 430.08, 215.04, 107.52, 53.76, 26.88, 13.44, 6.72, 3.36, 1.68, 0.84, 0.42]
},
"elevationmap": {
"wcs": "\"https://geodata.nationaalgeoregister.nl/ahn3/wcs?SERVICE=WCS&VERSION=1.0.0&REQUEST=GetCoverage&FORMAT=GEOTIFF_FLOAT32&COVERAGE=ahn3_05m_\" + settings.dataset + \"&BBOX=\" + bbox + \"&CRS=EPSG:28992&RESPONSE_CRS=EPSG:28992&WIDTH=\" + width + \"&HEIGHT=\" + height"
},
"init": {
"coords": [5.38763888888889, 52.15616055555555],
"zoom": 16,
"dataset": "DTM",
"level": 0.0
},
"language": {
"actions": "acties",
"elevation": "hoogte",
"waterlevel": "waterpeil",
"waterlevelunit": "m + NAP",
"dataset": "dataset",
"terrain": "maaiveld",
"surface": "ruwe data",
"addsource": "Voeg een bron toe op de kaart",
"addsink": "Voeg een put toe op de kaart",
"sculpt": "Interpoleer de hoogtes tussen twee punten op de kaart",
"togglesimulation": "Start/stop simulatie",
"togglerain": "Neerslag aan/uit",
"share": "Deel",
"showelevationmap": "toon hoogtekaart",
"hideelevationmap": "verberg hoogtekaart",
"urlcopied": "url is naar het klembord gekopieerd",
"attribution": "Software: <a href=\"https://opensource.org/licenses/Simple-2.0\">SimPL-2.0</a> <a target=\"_blank\" href=\"view-source:https://www.mapmind.org/\">Harmen G.Zijp</a><br/>Kaartgegevens: <a href=\"https://creativecommons.org/licenses/by-sa/4.0/deed.nl\">CC-BY-SA</a> <a href=\"https://www.osm.org\">OSM</a> & <a href=\"https://www.kadaster.nl\">Kadaster</a>, <a href=\"https://creativecommons.org/publicdomain/zero/1.0/deed.nl\">CC-0</a> <a href=\"https://www.ahn.nl/index.html\">AHN</a>.",
"warningnowebgl": "Deze pagina werkt alleen met een browser die <a href=\"https://get.webgl.org/\">WebGL</a> ondersteunt."
}
},
"no": {
"projection": {
"epsg": "EPSG:25833",
"proj4def": "+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs",
"extent": [-2500000.0, 3500000.0, 3045984.0, 9045984.0]
},
"backgroundmap": {
"wmts": "https://opencache.statkart.no/gatekeeper/gk/gk.open_wmts",
"layer": "topo4",
"resolutions": [21664,10832,5416,2708,1354,677,338.5,169.25,84.625,42.3125,21.15625,10.578125,5.2890625,2.64453125,1.322265625,0.6611328125,0.33056640625,0.165283203125]
},
"elevationmap": {
"wcs": "\"https://wms.geonorge.no/skwms1/wcs.hoyde-\"+ settings.dataset + \"1_33?VERSION=1.0.0&SERVICE=WCS&REQUEST=GetCoverage&format=GeoTIFF&COVERAGE=1&CRS=EPSG:25833&WIDTH=\" + width + \"&HEIGHT=\" + height + \"&BBOX=\" + bbox"
},
"init": {
"coords": [5.354, 60.387],
"zoom": 15,
"dataset": "dtm",
"level": 0.0
},
"language": {
"actions": "handlinger",
"elevation": "høyde",
"waterlevel": "vannstand",
"waterlevelunit": "moh",
"dataset": "datasett",
"terrain": "terreng",
"surface": "overflate",
"addsource": "Legg til en kilde på kartet",
"addsink": "Legg til en avløp på kartet",
"sculpt": "Interpolere høydene mellom to punkter på kartet",
"togglesimulation": "Start/stopp simulering",
"togglerain": "Nedbør på/av",
"share": "Del",
"showelevationmap": "vis høydekart",
"hideelevationmap": "skjul høydekart",
"urlcopied": "url kopiert til utklippstavlen",
"attribution": "Software: <a href=\"https://opensource.org/licenses/Simple-2.0\">SimPL-2.0</a> <a target=\"_blank\" href=\"view-source:https://www.mapmind.org/\">Harmen G.Zijp</a><br/>Kaartgegevens: <a href=\"https://creativecommons.org/licenses/by-sa/4.0/deed.nl\">CC-BY-SA</a> <a href=\"https://www.osm.org\">OSM</a> & <a href=\"https://www.kadaster.nl\">Kadaster</a>, <a href=\"https://creativecommons.org/publicdomain/zero/1.0/deed.nl\">CC-0</a> <a href=\"https://www.ahn.nl/index.html\">AHN</a>.",
"warningnowebgl": "Deze pagina werkt alleen met een browser die <a href=\"https://get.webgl.org/\">WebGL</a> ondersteunt."
}
}
}
181 changes: 181 additions & 0 deletions glsl/automaton.fsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
* LICENSE
* MapMind was developed by Harmen G. Zijp at the Cooperative University of Amersfoort. The code is distributed under the Simple Public License 2.0 which can be found at https://opensource.org/licenses/Simple-2.0
*
* Contact: harmen [at] universiteitamersfoort [dot] nl
*/

// colormap fragment shader

// Watch out: Some horrible ugly hacks were used because stupid webgl cannot handle variable array indices!
// See https://stackoverflow.com/questions/30585265/what-can-i-use-as-an-array-index-in-glsl-in-webgl

precision mediump float;

// our textures
uniform sampler2D waterlevelMap;
uniform sampler2D elevationMap;

// declare the texture coordinate that is passed in from the fragment shader
varying vec2 v_texCoord;

// declare additional variables we pass from the main program into this shader
uniform float zmin;
uniform float zmax;
uniform float dw; // water increment
uniform float du; // the width of the cells
uniform float dv; // the height of the cells

uniform int rain;
uniform float lastX;
uniform float lastY;
uniform float currX;
uniform float currY;
uniform float wellX;
uniform float wellY;

uniform int nSources;
uniform vec2 sourceCoords[16];
uniform int nSinks;
uniform vec2 sinkCoords[16];

uniform int pass;
uniform int rseed;

vec2 coord(int dir) {
if (dir==0) return vec2(v_texCoord.x, v_texCoord.y );
if (dir==1 || dir==-2) return vec2(v_texCoord.x - du, v_texCoord.y - dv);
if (dir==2 || dir==-1) return vec2(v_texCoord.x + du, v_texCoord.y + dv);
if (dir==3 || dir==-4) return vec2(v_texCoord.x - du, v_texCoord.y );
if (dir==4 || dir==-3) return vec2(v_texCoord.x + du, v_texCoord.y );
if (dir==5 || dir==-6) return vec2(v_texCoord.x - du, v_texCoord.y + dv);
if (dir==6 || dir==-5) return vec2(v_texCoord.x + du, v_texCoord.y - dv);
if (dir==7 || dir==-8) return vec2(v_texCoord.x, v_texCoord.y + dv);
if (dir==8 || dir==-7) return vec2(v_texCoord.x, v_texCoord.y - dv);
}

int elevation(int dir) {
return int((zmax-zmin)*texture2D(elevationMap, coord(dir)).r/dw);
}

int waterlevel(int dir) {
return int(255.0*texture2D(waterlevelMap, coord(dir)).r);
}

bool getbit(int a, int n) {
// Below is an *UGLY* WebGL rewrite for
// for (int i=7;i>n;i--) if(a-int(exp2(float(i)))>=0) a = a - int(exp2(float(i)));
for (int i=7;i>=0;i--) if (i>n && a-int(exp2(float(i)))>=0) a = a - int(exp2(float(i)));
if (a-int(exp2(float(n)))>=0) return true;
else return false;
}

bool flowdir(int pos, int dir) {
int flowdirs = int(255.0*texture2D(waterlevelMap, coord(pos)).g);
return getbit(flowdirs, dir);
}

int rand(vec2 co, int max) {
float a = 12.9898;
float b = 78.233;
float c = 43758.5453;
float dt = dot(co.xy ,vec2(a,b));
float sn = mod(dt, 3.14);
int rnd = int(float(max)*fract(abs(sin(sn) * c)));
if (rnd<0) rnd = 0;
if (rnd>=max) rnd = max-1;
return rnd;
}

void main() {
if (pass == 0) {
int flowdirs = 0;
// only continue if water is available at gridpoint
if (waterlevel(0) > 0) {
// calculate slope (drop/verval) in 8 wind directions
int dh[9];
dh[0] = 0;
for (int i=1;i<9;i++) dh[i] = (elevation(0) + waterlevel(0) - elevation(i) - waterlevel(i));

// find out which winddirection has highest drop
int m = 0;
for (int i=1;i<9;i++) {
// Below is an *UGLY* WebGL rewrite for
// if (dh[i] > dh[m]) m = i;
for (int k = 0; k < 9; ++k) if (m == k) {
if (dh[i] > dh[k]) m = i;
}
}

// only continue if gridpoint shows drop in one or more directions
if (m>0) {
// set flags for direction(s) with highest drop
int n = 0;
for (int i=1;i<9;i++) {
// Below is an *UGLY* WebGL rewrite for
// if (dh[i] == dh[m]) {
// flowdirs = flowdirs + int(exp2(i-1));
// n++;
// }
for (int k = 0; k < 9; ++k) if (m == k) {
if (dh[i] == dh[k]) {
flowdirs = flowdirs + int(exp2(float(i-1)));
n++;
}
}
}

// check for available excess water at gridpoint
int available = waterlevel(0);

// Below is an *UGLY* WebGL rewrite for
// if (dh[m] < available) available = dh[m];
for (int k = 0; k < 9; ++k) if (m == k) {
if (dh[k] < available) available = dh[k];
}

// knock down bits from flowdirs until the number matches available units, start at random
int dir = rand(coord(rseed), 8);

// Below is an *UGLY* WebGL rewrite for
// while(n>available) {
for (int d=0; d<8; d++) {
if((n>available) && getbit(flowdirs, dir)) {
flowdirs = flowdirs - int(exp2(float(dir)));
n--;
}
dir++;
if (dir == 8) dir = 0;
}
}
}
gl_FragColor = vec4(texture2D(waterlevelMap, v_texCoord).r, float(flowdirs)/255.0, 0.0, 0.0);
}
else {
int level = int(255.0*texture2D(waterlevelMap, v_texCoord).r);

// account flow from resp to gridpoint
if (level>0) for (int i=1;i<9;i++) if (flowdir(0, i-1)) level--;
for (int i=1;i<9;i++) if (flowdir(-i,i-1)) level++;

// apply raining...
if ((rain==1) && (rand(coord(rseed), 8)==0)) level++;

// apply sources and sinks
vec2 scale = vec2(1, du/dv);
for (int i=0; i<16; i++) {
if (i<nSources) {
if (distance(scale*v_texCoord, scale*sourceCoords[i]) < 3.0*du) level+= 4;
}
}
for (int i=0; i<16; i++) {
if (i<nSinks) {
if (distance(scale*v_texCoord, scale*sinkCoords[i]) < 3.0*du) level = 0;
}
}

// drain at border of frame
if ((v_texCoord.x < du) || (v_texCoord.x >= 1.0-du) || (v_texCoord.y < dv) || (v_texCoord.y >= 1.0-dv)) gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
else gl_FragColor = vec4(float(level)/255.0, 0.0, 0.0, 0.0);
}
}
30 changes: 30 additions & 0 deletions glsl/automaton.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* LICENSE
* MapMind was developed by Harmen G. Zijp at the Cooperative University of Amersfoort. The code is distributed under the Simple Public License 2.0 which can be found at https://opensource.org/licenses/Simple-2.0
*
* Contact: harmen [at] universiteitamersfoort [dot] nl
*/

// colormap vertex shader
precision mediump float;

// declare variables for various coordinates (framebuffer, texture) we get from the main program
attribute vec2 a_position;
attribute vec2 a_texCoord;

// declare additional variables we pass from the main program into this shader
uniform vec2 u_resolution;

// declare the texture coordinate that is passed on to the fragment shader
varying vec2 v_texCoord;

void main() {
// convert the rectangle from pixels (0,0 to u_resolution) to clipspace (-1.0 to 1.0)
vec2 clipCoord = 2.0*(a_position/u_resolution) - 1.0;

// set position
gl_Position = vec4(clipCoord, 0, 1);

// pass the texCoord to the fragment shader
v_texCoord = a_texCoord;
}
48 changes: 48 additions & 0 deletions glsl/colormap.fsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* LICENSE
* MapMind was developed by Harmen G. Zijp at the Cooperative University of Amersfoort. The code is distributed under the Simple Public License 2.0 which can be found at https://opensource.org/licenses/Simple-2.0
*
* Contact: harmen [at] universiteitamersfoort [dot] nl
*/

// colormap fragment shader
precision mediump float;

// our textures
uniform sampler2D elevationMap;
uniform sampler2D waterlevelMap;

// declare the texture coordinate that is passed in from the fragment shader
varying vec2 v_texCoord;

// declare additional variables we pass from the main program into this shader
uniform float level;
uniform float heights[16];
uniform float reds[16];
uniform float greens[16];
uniform float blues[16];

vec4 col(float h) {
h = h/2.0;
float dh, r, g, b;
for (int i=0; i<15; i++) if ((h>=heights[i]) && (h<heights[i+1])) {
dh = float(h-heights[i])/float(heights[i+1]-heights[i]);
r = reds[i] + (reds[i+1] - reds[i]) * dh;
g = greens[i] + (greens[i+1] - greens[i]) * dh;
b = blues[i] + (blues[i+1] - blues[i]) * dh;
break;
}
vec4 c = vec4(r, g, b, 1.0);
return c;
}

void main() {
float elevation = texture2D(elevationMap, v_texCoord).r;
float waterlayer = texture2D(waterlevelMap, v_texCoord).r;

if (elevation==0.0) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
else {
if (waterlayer > 0.0 && waterlayer > level - elevation) gl_FragColor = col(-waterlayer);
else gl_FragColor = col(elevation - level);
}
}
30 changes: 30 additions & 0 deletions glsl/colormap.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* LICENSE
* MapMind was developed by Harmen G. Zijp at the Cooperative University of Amersfoort. The code is distributed under the Simple Public License 2.0 which can be found at https://opensource.org/licenses/Simple-2.0
*
* Contact: harmen [at] universiteitamersfoort [dot] nl
*/

// colormap vertex shader
precision mediump float;

// declare variables for various coordinates (framebuffer, texture) we get from the main program
attribute vec2 a_position;
attribute vec2 a_texCoord;

// declare additional variables we pass from the main program into this shader
uniform vec2 u_resolution;

// declare the texture coordinate that is passed on to the fragment shader
varying vec2 v_texCoord;

void main() {
// convert the rectangle from pixels (0,0 to u_resolution) to clipspace (-1.0 to 1.0)
vec2 clipCoord = 2.0*(a_position/u_resolution) - 1.0;

// set position
gl_Position = vec4(clipCoord * vec2(1, -1), 0, 1);

// pass the texCoord to the fragment shader
v_texCoord = a_texCoord;
}
Loading

0 comments on commit 810d387

Please sign in to comment.