查看全屏地图
在全屏模式下显示地图;
<!DOCTYPE html>
<html lang="en">
<head>
<title>查看全屏地图</title>
<meta property="og:description" content="在全屏模式下显示地图" />
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel='stylesheet' href='https://unpkg.com/maplibre-gl@5.5.0/dist/maplibre-gl.css' />
<script src='https://unpkg.com/maplibre-gl@5.5.0/dist/maplibre-gl.js'></script>
<style>
body { margin: 0; padding: 0; }
html, body, #map { height: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script>
const map = new maplibregl.Map({
container: 'map', // 容器ID
style:
'https://api.maptiler.com/maps/streets/style.json?key=get_your_own_OpIi9ZULNHzrESv6T2vL', // 样式URL
center: [-74.0066, 40.7135], // 起始位置
zoom: 15.5, // 起始缩放
pitch: 45, // 起始倾斜
bearing: -17.6, // 起始方位角
antialias: true
});
// 添加全屏控件
map.addControl(new maplibregl.FullscreenControl());
// 添加导航控件
map.addControl(new maplibregl.NavigationControl());
map.on('load', () => {
// 插入前景层的自定义层
map.addLayer({
'id': 'sky',
'type': 'sky',
'paint': {
'sky-type': 'atmosphere',
'sky-atmosphere-sun': [0.0, 0.0],
'sky-atmosphere-sun-intensity': 15
}
});
});
</script>
</body>
</html>