terrain_pmtiles/readme.txt
2026-02-18 22:04:45 +01:00

61 lines
No EOL
2.2 KiB
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script>
// ... codice precedente ...
map.on('load', () => {
// 1) Sorgente DEM per la MESH 3D (terrain)
map.addSource('terrain-dem', {
type: 'raster-dem',
// Se stai usando il tuo PMTiles Terrarium:
// url: 'pmtiles://' + `${origin}/data/terrain_terrarium.pmtiles`,
// encoding: 'terrarium',
// tileSize: 256, // oppure 512 se il tuo tileset lo usa
// ESEMPIO DEM DI TEST (Terrarium pubblico):
url: 'https://demotiles.maplibre.org/terrain-tiles/tiles.json',
tileSize: 256
});
// 2) Sorgente DEM *separata* per l'HILLSHADE (stesso dataset, ID diverso)
map.addSource('hillshade-dem', {
type: 'raster-dem',
// Se usi lo stesso PMTiles Terrarium, ripeti gli stessi parametri qui
// url: 'pmtiles://' + `${origin}/data/terrain_terrarium.pmtiles`,
// encoding: 'terrarium',
// tileSize: 256,
// DEM di test identico allesempio sopra
url: 'https://demotiles.maplibre.org/terrain-tiles/tiles.json',
tileSize: 256
});
// 3) Attiva il terrain 3D sulla sola source 'terrain-dem'
let exag = 1.6;
map.setTerrain({ source: 'terrain-dem', exaggeration: exag });
// 4) Inserisci lhillshade usando la source 'hillshade-dem'
const labelLayerId = map.getStyle().layers.find(l => l.type === 'symbol')?.id;
map.addLayer({
id: 'hillshade',
type: 'hillshade',
source: 'hillshade-dem',
paint: {
'hillshade-exaggeration': 0.5,
'hillshade-illumination-direction': 315
// (opzionale) 'hillshade-illumination-anchor': 'map'
// ancora map può aiutare con il terrain attivo
}
}, labelLayerId);
// 5) Slider per cambiare lexaggeration (non ricrea le sorgenti)
const exIn = document.getElementById('exag');
const exSp = document.getElementById('exagv');
const setExag = (v) => {
exSp.textContent = v.toFixed(1);
map.setTerrain({ source: 'terrain-dem', exaggeration: v });
// ← ora NON vedrai più il warning, perché lhillshade usa unaltra source
};
exIn?.addEventListener('input', e => setExag(parseFloat(e.target.value)));
});
// ... codice successivo ...
</script>