Check that an elevation COG works correctly at the edge of the map.
import { MapControls } from "three/examples/jsm/controls/MapControls.js";
import Extent from "@giro3d/giro3d/core/geographic/Extent.js";
import GeoTIFFSource from "@giro3d/giro3d/sources/GeoTIFFSource.js";
import Instance from "@giro3d/giro3d/core/Instance.js";
import ElevationLayer from "@giro3d/giro3d/core/layer/ElevationLayer.js";
import Map from "@giro3d/giro3d/entities/Map.js";
import Inspector from "@giro3d/giro3d/gui/Inspector.js";
const extent = Extent.fromCenterAndSize(
"EPSG:3857",
{ x: -13555565, y: 5919254 },
20000,
20000,
);
const instance = new Instance({
target: "view",
crs: extent.crs,
});
instance.view.camera.position.set(-13577183, 5907053, 45050);
const controls = new MapControls(instance.view.camera, instance.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.2;
controls.target.set(-13557038, 5920026, 0);
instance.view.setControls(controls);
const map = new Map({
extent,
backgroundColor: "gray",
hillshading: true,
});
instance.add(map);
// Use an elevation COG with nodata values
const source = new GeoTIFFSource({
// https://www.sciencebase.gov/catalog/item/632a9a9ad34e71c6d67b95a3
url: "https://3d.oslandia.com/cog_data/COG_EPSG3857_USGS_13_n47w122_20220919.tif",
crs: extent.crs,
});
const min = 263;
const max = 4347;
map.addLayer(
new ElevationLayer({
name: "elevation",
extent,
source,
preloadImages: false,
minmax: { min, max },
}),
);
Inspector.attach("inspector", instance);
<!doctype html>
<html lang="en">
<head>
<title>Cropped Elevation COG</title>
<meta charset="UTF-8" />
<meta name="name" content="cropped_cog_elevation" />
<meta
name="description"
content="Check that an elevation COG works correctly at the edge of the map."
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="https://giro3d.org/images/favicon.svg" />
<link
href="https://giro3d.org/assets/bootstrap-custom.css"
rel="stylesheet"
/>
<script src="https://giro3d.org/assets/bootstrap.bundle.min.js"></script>
<link
rel="stylesheet"
type="text/css"
href="https://giro3d.org/latest/examples/css/example.css"
/>
</head>
<body>
<div id="view" class="m-0 p-0 w-100 h-100"></div>
<div
id="inspector"
class="position-absolute top-0 start-0 mh-100 overflow-auto"
></div>
<script type="module" src="index.js"></script>
<script>
/* activate popovers */
const popoverTriggerList = [].slice.call(
document.querySelectorAll('[data-bs-toggle="popover"]'),
);
popoverTriggerList.map(
// bootstrap is used as script in the template, disable warning about undef
// eslint-disable-next-line no-undef
(popoverTriggerEl) =>
new bootstrap.Popover(popoverTriggerEl, {
trigger: "hover",
placement: "left",
content: document.getElementById(
popoverTriggerEl.getAttribute("data-bs-content"),
).innerHTML,
html: true,
}),
);
</script>
</body>
</html>
{
"name": "cropped_cog_elevation",
"dependencies": {
"@giro3d/giro3d": "0.40.0"
},
"devDependencies": {
"vite": "^3.2.3"
},
"scripts": {
"start": "vite",
"build": "vite build"
}
}