// 使用OpenStreetMap和Leaflet替代百度地图 export function loadBMap() { return new Promise(function(resolve, reject) { // eslint-disable-next-line no-undef if (typeof L !== 'undefined') { // eslint-disable-next-line no-undef resolve(L); return true; } // 加载Leaflet CSS if (!document.querySelector('link[href*="leaflet.css"]')) { const link = document.createElement('link'); link.rel = 'stylesheet'; link.href = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.css'; link.integrity = 'sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY='; link.crossOrigin = ''; document.head.appendChild(link); } // 加载Leaflet JS const script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.js'; script.integrity = 'sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo='; script.crossOrigin = ''; script.onload = function() { // eslint-disable-next-line no-undef resolve(L); }; script.onerror = reject; document.head.appendChild(script); }); }