Published
Edited
Dec 6, 2020
Importers
1 star
Insert cell
Insert cell
latlng = {
//const ll = [36.3928, -112.6304]; // Colorado River
//const ll = [51.4853, 0.1348]

const ll = [54.4703451, -3.0408847]; //lakes
//const ll = [45.9764, 7.6585]; // Matterhorn
//const ll = [32.8861, 131.0819]; // Mount Aso
//const ll = [40.8038, 14.3981]; // Vesuvio
return ll;
}
Insert cell
vscale = 2
Insert cell
zoom = 12
Insert cell
radius = 20 //km
Insert cell
chart = {
const renderer = new THREE.WebGLRenderer({ antialias: true });
const controls = new THREE.OrbitControls(camera, renderer.domElement);
renderer.setSize(width, height);
renderer.setPixelRatio(devicePixelRatio);
invalidation.then(
() => (controls.dispose(), renderer.dispose(), clearScene())
);

scene.scale.set(1, 1, vscale);

const render = () => {
renderer.render(scene, camera);
};
controls.addEventListener("change", render);
render(); // first time

// https://github.com/w3reality/three-geo#usage
const tgeo = new ThreeGeo({
tokenMapbox: tgeoParams.token
});
tgeo.getTerrain(latlng, tgeoParams.radius, tgeoParams.zoom, {
onRgbDem: meshes => {
meshes.forEach(mesh => {
scene.add(mesh);
});
render();
}

//onSatelliteMat: (mesh) => {
// render();
//},
// onVectorDem: objs => {
// // type is either Mesh or Line
// objs.forEach(obj => {
// scene.scale.set(1, 1, vscale);
// scene.add(obj);
// });
// render();
// }
});

return renderer.domElement;
}
Insert cell
clearScene = () => {
// clear the scene in case of re-evaluation of notebook
// https://stackoverflow.com/questions/35060831/how-to-remove-all-mesh-objects-from-the-scene-in-three-js
for (let i = scene.children.length - 1; i >= 0; i--) {
let ch = scene.children[i];
if (ch.type === "Mesh" || ch.type === "Line") {
scene.remove(ch);
ch.geometry.dispose();
ch.material.dispose();
}
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
THREE = {
const THREE = window.THREE = await require("three@0.96/build/three.min.js");
await require("three@0.96/examples/js/controls/OrbitControls.js").catch(() => {});
return THREE;
}
Insert cell
Insert cell
ThreeGeo = {
const _THREE = THREE; // just to ensure THREE is resolved first by notebook...
return (await require(`three-geo@1.4.2/dist/three-geo.esm.compat.js`)).default;
}
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