Published
Edited
Nov 17, 2019
4 stars
Insert cell
Insert cell
viewof gl = {
const canvas = DOM.canvas(height, height);
canvas.style.cssText = `margin: 0 -14px;width:${height}px;height:${height}px;`;
canvas.value = canvas.getContext("webgl");
return canvas;
}
Insert cell
Insert cell
Insert cell
url = "https://cyberjapandata.gsi.go.jp/xyz/dem_png/13/7262/3232.png"
Insert cell
// HTMLImageElement of elevation tile image
image = {
const imgUrl = await fetch(url).then(r => r.blob()).then(b => URL.createObjectURL(b));
const im = new Image;
im.src = imgUrl;
return im;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Extract color array from d3
scheme = {
const scheme = d3.schemeSpectral;
return scheme[scheme.length - 1].reverse();
}
Insert cell
// Hex color => Array of RGB in range [0, 1]
rgbColors = scheme.map(hex => {
const color = d3.color(hex);
return [color.r/255, color.g/255, color.b/255]
});
Insert cell
Insert cell
Insert cell
program = Program(gl, vertexShader, fragmentShader)
Insert cell
draw = {
gl.useProgram(program.program);
program.a_vertex.set([[-1, -1], [+1, -1], [+1, +1], [-1, 1]]);
program.u_size.set(Math.max(viewof gl.width, viewof gl.height));
Texture(gl, gl.NEAREST, image, image.width, image.height).bindToUnit(0);
program.u_texture.set(0);
program.u_n.set(rgbColors.length);
program.u_colorScheme.set([].concat.apply([], rgbColors));

gl.drawArrays(gl.TRIANGLE_FAN, 0, 4);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more