Skip to content

Instantly share code, notes, and snippets.

@jhwohlgemuth
Created March 20, 2025 16:07
Show Gist options
  • Select an option

  • Save jhwohlgemuth/606937729a099b81df07be2f61ac7bd4 to your computer and use it in GitHub Desktop.

Select an option

Save jhwohlgemuth/606937729a099b81df07be2f61ac7bd4 to your computer and use it in GitHub Desktop.
Standalone file for viewing GeoTIFF in a web browser
<html>
<head>
<title>My first web page</title>
<script src="https://cdn.jsdelivr.net/npm/geotiff/dist-browser/geotiff.js"></script>
<script src="https://cdn.jsdelivr.net/npm/proj4/dist/proj4.js"></script>
<script src="https://cdn.jsdelivr.net/npm/geotiff-geokeys-to-proj4/main-dist-iife.js"></script>
<script src="https://unpkg.com/[email protected]/dist/plotty.min.js"></script>
</head>
<body>
<h1>GeoTIFF in Browser</h1>
<canvas id="plot"></canvas>
<script>
const { fromUrl, fromUrls, fromArrayBuffer, fromBlob } = GeoTIFF;
(async function() {
// https://visibleearth.nasa.gov/images/57752/blue-marble-land-surface-shallow-water-and-shaded-topography
const response = await fetch("test.tif");
const arrayBuffer = await response.arrayBuffer();
const tiff = await fromArrayBuffer(arrayBuffer);
const image = await tiff.getImage();
const data = await image.readRasters();
const canvas = document.getElementById("plot");
console.log(image.getGeoKeys());
const plot = new plotty.plot({
canvas,
data: data[0],
width: image.getWidth(),
height: image.getHeight(),
domain: [0, 256],
colorScale: "viridis"
});
plot.render();
})()
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment