Skip to content

Instantly share code, notes, and snippets.

@darrenwiens
Created February 25, 2024 00:59
Show Gist options
  • Save darrenwiens/1bc213ac9e38e3d5c22bb4e4e061913e to your computer and use it in GitHub Desktop.
Save darrenwiens/1bc213ac9e38e3d5c22bb4e4e061913e to your computer and use it in GitHub Desktop.
A Potree static site for showing COPCs from Microsoft Planetary Computer
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>MPC COPC Viewer</title>
<link rel="stylesheet" type="text/css" href="../build/potree/potree.css">
<link rel="stylesheet" type="text/css" href="../libs/jquery-ui/jquery-ui.min.css">
<link rel="stylesheet" type="text/css" href="../libs/openlayers3/ol.css">
<link rel="stylesheet" type="text/css" href="../libs/spectrum/spectrum.css">
<link rel="stylesheet" type="text/css" href="../libs/jstree/themes/mixed/style.css">
</head>
<body>
<script src="../libs/jquery/jquery-3.1.1.min.js"></script>
<script src="../libs/spectrum/spectrum.js"></script>
<script src="../libs/jquery-ui/jquery-ui.min.js"></script>
<script src="../libs/other/BinaryHeap.js"></script>
<script src="../libs/tween/tween.min.js"></script>
<script src="../libs/d3/d3.js"></script>
<script src="../libs/proj4/proj4.js"></script>
<script src="../libs/openlayers3/ol.js"></script>
<script src="../libs/i18next/i18next.js"></script>
<script src="../libs/jstree/jstree.js"></script>
<script src="../libs/copc/index.js"></script>
<script src="../build/potree/potree.js"></script>
<script src="../libs/plasio/js/laslaz.js"></script>
<!-- INCLUDE ADDITIONAL DEPENDENCIES HERE -->
<!-- INCLUDE SETTINGS HERE -->
<div class="potree_container" style="position: absolute; width: 100%; height: 100%; left: 0px; top: 0px; ">
<div id="potree_render_area" style="background-image: url('../build/potree/resources/images/face.png');">
</div>
<div id="potree_sidebar_container"> </div>
</div>
<script type="module">
import * as THREE from "../libs/three.js/build/three.module.js";
window.viewer = new Potree.Viewer(document.getElementById("potree_render_area"));
viewer.setEDLEnabled(true);
viewer.setFOV(60);
viewer.setPointBudget(2_000_000);
viewer.loadSettingsFromURL();
viewer.setDescription("Edit URL with query parameters:<br>r: Microsoft Planetary Computer COPC URL<br>c: color attribute name");
viewer.loadGUI(() => {
viewer.setLanguage('en');
$("#menu_appearance").next().show();
});
var getQueryParam = function (name) {
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(window.location.href);
if (!results || !results[2]) return null;
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
var r = getQueryParam('r');
fetch('https://planetarycomputer.microsoft.com/api/sas/v1/sign?href=' + r)
.then(response => response.json())
.then(data => {
let path = data.href
var c = getQueryParam('c');
Potree.loadPointCloud(path, name, function (e) {
viewer.scene.addPointCloud(e.pointcloud);
let material = e.pointcloud.material;
material.size = 0.1;
material.pointSizeType = Potree.PointSizeType.ADAPTIVE;
if (c) {
material.activeAttributeName = c;
} else {
material.activeAttributeName = "elevation";
}
viewer.fitToScreen(0.5);
});
})
.catch((error) => {
console.error('Error:', error);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment