显示非交互式地图
创建一个不允许用户交互的地图;
<!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.5, 40], // 起始位置 [经度, 纬度]
zoom: 9, // 起始缩放级别
interactive: false // 禁用所有地图交互
});
// 添加导航控件(虽然地图是非交互式的,这里只是为了显示比例、方向等信息)
map.addControl(new maplibregl.NavigationControl());
</script>
</body>
</html>