enable terrain only when pitch is positive
This commit is contained in:
parent
9bc743bc18
commit
9be7c8eb02
1 changed files with 28 additions and 19 deletions
|
@ -19,6 +19,32 @@
|
||||||
easing: () => 1
|
easing: () => 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function toggleTerrain() {
|
||||||
|
if ($map) {
|
||||||
|
if ($map.getPitch() > 0) {
|
||||||
|
if (!$map.getSource('mapbox-dem')) {
|
||||||
|
$map.addSource('mapbox-dem', {
|
||||||
|
type: 'raster-dem',
|
||||||
|
url: 'mapbox://mapbox.mapbox-terrain-dem-v1',
|
||||||
|
tileSize: 512,
|
||||||
|
maxzoom: 14
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!$map.getTerrain()) {
|
||||||
|
$map.setTerrain({ source: 'mapbox-dem', exaggeration: 1 });
|
||||||
|
$map.setFog({
|
||||||
|
color: 'rgb(186, 210, 235)',
|
||||||
|
'high-color': 'rgb(36, 92, 223)',
|
||||||
|
'horizon-blend': 0.1,
|
||||||
|
'space-color': 'rgb(156, 240, 255)'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$map.setTerrain(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
$map = new mapboxgl.Map({
|
$map = new mapboxgl.Map({
|
||||||
container: 'map',
|
container: 'map',
|
||||||
|
@ -65,25 +91,8 @@
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
$map.on('style.load', () => {
|
$map.on('style.load', toggleTerrain);
|
||||||
if ($map) {
|
$map.on('pitchstart', toggleTerrain);
|
||||||
if (!$map.getLayer('mapbox-dem')) {
|
|
||||||
$map.addSource('mapbox-dem', {
|
|
||||||
type: 'raster-dem',
|
|
||||||
url: 'mapbox://mapbox.mapbox-terrain-dem-v1',
|
|
||||||
tileSize: 512,
|
|
||||||
maxzoom: 14
|
|
||||||
});
|
|
||||||
}
|
|
||||||
$map.setTerrain({ source: 'mapbox-dem', exaggeration: 1 });
|
|
||||||
$map.setFog({
|
|
||||||
color: 'rgb(186, 210, 235)',
|
|
||||||
'high-color': 'rgb(36, 92, 223)',
|
|
||||||
'horizon-blend': 0.1,
|
|
||||||
'space-color': 'rgb(156, 240, 255)'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue