Non Interactive
Runnable MapLibre GL JS example: Non Interactive. Open the live demo, read the complete source, and copy the file into your project. No build step or API key.
single HTML file · CDN dependencies onlyinterface may contain Chinese labels
Source
<!--
示例:不可交互的地图
核心逻辑:构造参数 interactive 设为 false,所有手势与滚轮一次性关闭
数据:页面内写死的三个城市点,用程序打开一个弹窗
依赖:MapLibre GL JS 4 · jsDelivr CDN · demotiles 样式
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta name="robots" content="noindex,follow">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>不可交互的地图</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/maplibre-gl@4/dist/maplibre-gl.css">
<style>
html,body{height:100%;margin:0}
body{display:flex;flex-direction:column;overflow:hidden;
font:13px/1.6 -apple-system,"Segoe UI","PingFang SC",sans-serif;color:#16181d}
.bar{flex:0 0 auto;display:flex;gap:14px;align-items:center;padding:8px 12px;
background:#f6f7f9;border-bottom:1px solid #e3e6ea;font-size:12px;color:#58606e;flex-wrap:wrap}
.bar b{color:#16181d;font-weight:600}
.bar button{background:#fff;border:1px solid #cfd6df;border-radius:4px;padding:3px 10px;
font:12px/1.4 inherit;color:#3a4250;cursor:pointer}
.bar button:hover{border-color:#2e86de;color:#2e86de}
#map{flex:1 1 auto;min-height:0}
</style>
</head>
<body>
<div class="bar">
<span>状态 <b id="st">不可交互</b></span>
<button id="peek">弹出说明</button>
<span>拖动、缩放、双击都不会有反应</span>
</div>
<div id="map"></div>
<script src="https://cdn.jsdelivr.net/npm/maplibre-gl@4/dist/maplibre-gl.js"></script>
<script>
(function () {
'use strict';
if (typeof maplibregl === 'undefined') {
document.body.innerHTML =
'<div style="padding:24px;color:#b42318">MapLibre 加载失败,请检查能否访问 cdn.jsdelivr.net</div>';
return;
}
var map = new maplibregl.Map({
container: 'map',
style: 'https://demotiles.maplibre.org/style.json',
center: [108, 34],
zoom: 3.2,
/* 一行关掉全部内置手势,适合做缩略图或背景图 */
interactive: false,
attributionControl: { compact: true, customAttribution: 'MapLibre demo tiles' }
});
var cities = [
[116.39, 39.90], [121.47, 31.23], [104.06, 30.57]
];
var popup = new maplibregl.Popup({ closeButton: false, offset: 14 })
.setLngLat(cities[0])
.setHTML('<b>北京</b><br><span style="color:#888">这张图不会响应任何手势</span>');
map.on('load', function () {
map.addSource('pts', {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: cities.map(function (c, i) {
return {
type: 'Feature',
properties: { name: ['北京', '上海', '成都'][i] },
geometry: { type: 'Point', coordinates: c }
};
})
}
});
map.addLayer({
id: 'pts',
type: 'circle',
source: 'pts',
paint: {
'circle-radius': 7,
'circle-color': '#2e86de',
'circle-stroke-width': 2,
'circle-stroke-color': '#ffffff'
}
});
popup.addTo(map);
});
/* interactive 只关手势,程序化跳转与弹窗照常可用 */
document.getElementById('peek').addEventListener('click', function () {
map.jumpTo({ center: [121.47, 31.23], zoom: 4 });
popup.setLngLat([121.47, 31.23])
.setHTML('<b>上海</b><br><span style="color:#888">跳转由代码触发,不依赖手势</span>');
document.getElementById('st').textContent = '已代码跳转';
});
map.on('error', function (e) {
if (e.error) console.warn('地图错误:' + e.error.message);
});
})();
</script>
</body>
</html>
Language: the code and this page are in English; the full tutorial and API notes for this example are in Chinese. The demo itself is the authoritative version — it runs exactly as shown.