itowns
Version:
A JS/WebGL framework for 3D geospatial data visualization
173 lines (136 loc) • 5.98 kB
HTML
<html>
<head>
<meta charset="UTF-8">
<title>Itowns - COPC loader</title>
<script type="importmap">
{
"imports": {
"itowns": "../dist/itowns.js",
"debug": "../dist/debug.js",
"lil": "https://unpkg.com/lil-gui@0.20.0/dist/lil-gui.esm.js",
"dat": "https://unpkg.com/dat.gui@0.7.9/build/dat.gui.module.js",
"GuiTools": "./jsm/GUI/GuiTools.js",
"LoadingScreen": "./jsm/GUI/LoadingScreen.js",
"itowns_widgets": "../dist/itowns_widgets.js",
"three": "https://unpkg.com/three@0.170.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.170.0/examples/jsm/"
}
}
</script>
<link rel="stylesheet" type="text/css" href="css/example.css">
<link rel="stylesheet" type="text/css" href="css/LoadingScreen.css">
<style>
#description {
z-index: 2;
left: 10px;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="description">Specify the URL of a COPC file to load:
<input type="text" id="copc_url" />
<button onclick="readURL()">Load</button>
<div>
<button id="loadAutzenButton">Load Autzen Stadium (80mb)</button>
<button id="loadSofiButton">Load SoFI Stadium (2.3gb)</button>
<button id="loadMillsiteButton">Load Millsite (1.9gb)</button>
<div id="share"></div>
</div>
</div>
<div id="viewerDiv"></div>
<script type="module">
import lil from 'lil';
import GuiTools from 'GuiTools';
import setupLoadingScreen from 'LoadingScreen';
import * as THREE from 'three';
import * as itowns from 'itowns';
import * as debug from 'debug';
import * as itowns_widgets from 'itowns_widgets';
let layer; // COPCLayer
const uri = new URL(location);
const gui = new lil();
const viewerDiv = document.getElementById('viewerDiv');
const view = new itowns.View('EPSG:4326', viewerDiv);
const controls = new itowns.PlanarControls(view);
view.mainLoop.gfxEngine.renderer.setClearColor(0xdddddd);
setUrl(uri.searchParams.get('copc'));
function onLayerReady(layer) {
const camera = view.camera.camera3D;
const lookAt = new THREE.Vector3();
const size = new THREE.Vector3();
layer.root.bbox.getSize(size);
layer.root.bbox.getCenter(lookAt);
camera.far = 2.0 * size.length();
controls.groundLevel = layer.root.bbox.min.z;
const position = layer.root.bbox.min.clone().add(
size.multiply({ x: 1, y: 1, z: size.x / size.z }),
);
camera.position.copy(position);
camera.lookAt(lookAt);
camera.updateProjectionMatrix();
view.notifyChange(camera);
}
function readURL() {
const url = document.getElementById('copc_url').value;
if (url) {
setUrl(url);
}
}
function setUrl(url) {
if (!url) return;
const input_url = document.getElementById('copc_url');
if (!input_url) return;
uri.searchParams.set('copc', url);
history.replaceState(null, null, `?${uri.searchParams.toString()}`);
input_url.value = url;
load(url);
}
function load(url) {
const options = {};
const urlParams = uri.searchParams
urlParams.keys().forEach(key => {
if (key !== 'copc') {
options[key] = parseInt(urlParams.get(key), 10);
}
});
const source = new itowns.CopcSource({ url });
if (layer) {
layer.debugUI.destroy()
view.removeLayer('COPC');
view.notifyChange();
layer.delete();
}
const config = {
source,
crs: view.referenceCrs,
sseThreshold: 2,
pointBudget: 3000000,
...options,
};
layer = new itowns.CopcLayer('COPC', config);
view.addLayer(layer).then(onLayerReady);
layer.whenReady
.then(() => debug.PointCloudDebug.initTools(view, layer, gui));
}
function loadAutzen() {
setUrl("https://s3.amazonaws.com/hobu-lidar/autzen-classified.copc.laz");
}
function loadSofi() {
setUrl("https://s3.amazonaws.com/hobu-lidar/sofi.copc.laz");
}
function loadMillsite() {
setUrl("https://s3.amazonaws.com/data.entwine.io/millsite.copc.laz");
}
const loadAutzenButton = document.getElementById('loadAutzenButton');
const loadSofiButton = document.getElementById('loadSofiButton');
const loadMillsiteButton = document.getElementById('loadMillsiteButton');
loadAutzenButton.addEventListener('click', loadAutzen);
loadSofiButton.addEventListener('click', loadSofi);
loadMillsiteButton.addEventListener('click', loadMillsite);
window.view = view;
window.itowns = itowns;
window.THREE = THREE;
</script>
</body>
</html>