针对被中断的图像设置的重载定时器在 map.remove() 之后仍然存在,并保留已删除的 Map(在 v3.26.0 中出现回退问题)
作者: shaunml09创建于 2026年9月28日更新于 2026年9月28日
repro.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link href="https://api.mapbox.com/mapbox-gl-js/v3.31.0/mapbox-gl.css" rel="stylesheet">
<style>#map { width: 800px; height: 600px; } pre { font: 13px/1.4 monospace; }</style>
</head>
<body>
<div id="map"></div>
<pre id="out">running…</pre>
<script>
// Count the long timers the page arms and clears (tile reload timers are ~hours long).
const pending = new Set();
const origSet = window.setTimeout, origClear = window.clearTimeout;
window.setTimeout = function (fn, ms, ...args) {
const id = origSet.call(window, function (...a) { pending.delete(id); return fn.apply(this, a); }, ms, ...args);
if (ms > 60 * 60 * 1000) pending.add(id);
return id;
};
window.clearTimeout = function (id) { pending.delete(id); return origClear.call(window, id); };
</script>
<script src="https://api.mapbox.com/mapbox-gl-js/v3.31.0/mapbox-gl.js"></script>
<script>
mapboxgl.accessToken = 'YOUR_MAPBOX_ACCESS_TOKEN';
const out = document.getElementById('out');
const wait = (ms) => new Promise((r) => origSet(r, ms));
const removed = [];
async function once(i) {
const container = document.getElementById('map');
const map = new mapboxgl.Map({ container, style: 'mapbox://styles/mapbox/standard', center: [-74.5, 40], zoom: 12 });
await new
…内容来源: mapbox/mapbox-gl-js