换成第三方底图增加重试
This commit is contained in:
@@ -104,9 +104,6 @@ import { ref, computed, onMounted, watch } from 'vue'
|
||||
import L from 'leaflet'
|
||||
import 'leaflet/dist/leaflet.css'
|
||||
|
||||
// 瓦片代理地址 — 部署到内网其他机器时,将 localhost 改为服务器 IP
|
||||
const TILE_PROXY_URL = 'http://localhost:8080/tiles/{z}/{x}/{y}{r}.png'
|
||||
|
||||
// ── 常量 ────────────────────────────────────────────────────
|
||||
const TOTAL_VOLS = 63
|
||||
|
||||
@@ -271,10 +268,23 @@ function initMap() {
|
||||
attributionControl: false
|
||||
})
|
||||
|
||||
L.tileLayer(TILE_PROXY_URL, {
|
||||
maxZoom: 18
|
||||
const tileLayer = L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png', {
|
||||
maxZoom: 18,
|
||||
subdomains: 'abcd'
|
||||
}).addTo(map)
|
||||
|
||||
// 瓦片加载失败时自动重试(最多3次,间隔递增)
|
||||
const retryCounts = new Map()
|
||||
tileLayer.on('tileerror', (e) => {
|
||||
const key = e.tile.src
|
||||
const count = retryCounts.get(key) ?? 0
|
||||
if (count >= 3) return
|
||||
retryCounts.set(key, count + 1)
|
||||
setTimeout(() => {
|
||||
e.tile.src = e.tile.src.split('?')[0] + '?t=' + Date.now()
|
||||
}, 500 * (count + 1)) // 500ms / 1000ms / 1500ms
|
||||
})
|
||||
|
||||
L.control.attribution({ prefix: false, position: 'bottomright' })
|
||||
.addAttribution('大唐双龙传 - 黄易')
|
||||
.addTo(map)
|
||||
|
||||
Reference in New Issue
Block a user