From f2416683bc31c1e9e77c7123ef350e8df32d016d Mon Sep 17 00:00:00 2001
From: tuqin <tuqin@tuqin.cn>
Date: 星期四, 05 十一月 2026 17:27:16 +0800
Subject: [PATCH] feat(map): 新增 2D 版百度地图改写 SDK(绕开 GL 版的 Blob Worker 域名问题)
---
public/bmap-test.html | 241 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 241 insertions(+), 0 deletions(-)
diff --git a/public/bmap-test.html b/public/bmap-test.html
index b3a278f..879a35b 100644
--- a/public/bmap-test.html
+++ b/public/bmap-test.html
@@ -27,6 +27,23 @@
#map { width: 100%; height: 320px; margin-top: 12px; border: 1px solid #ddd; }
.tip { margin-top: 12px; padding: 10px; background: #e6f4ff; border-radius: 6px; }
</style>
+ <script>
+ // 灏芥棭娉ㄥ唽锛氭崟鑾� SDK 鎵ц鏈熼棿鎶涘嚭鐨勬墍鏈� JS 閿欒锛堣繖鏄渶鐩存帴鐨勬牴鍥犵嚎绱級
+ window.__bmapErr = [];
+ window.addEventListener('error', function (e) {
+ var t = e.target;
+ if (t && (t.tagName === 'SCRIPT' || t.tagName === 'IMG' || t.tagName === 'LINK')) { return; }
+ window.__bmapErr.push('JS 閿欒: ' + e.message + ' @' + (e.filename || '').split('/').pop() + ':' + e.lineno + ':' + e.colno);
+ }, true);
+ window.addEventListener('unhandledrejection', function (e) {
+ window.__bmapErr.push('Promise 鎷掔粷: ' + (e.reason && e.reason.message ? e.reason.message : e.reason));
+ });
+ var _ce = console.error;
+ console.error = function () {
+ try { window.__bmapErr.push('console.error: ' + Array.prototype.join.call(arguments, ' ').slice(0, 200)); } catch (_) {}
+ return _ce.apply(console, arguments);
+ };
+ </script>
</head>
<body>
<h3>鐧惧害鍦板浘 SDK 鍔犺浇璇婃柇</h3>
@@ -244,5 +261,229 @@
lg('锛堝鏋滆繖閲屾病鏈変换浣曡褰曪紝璇存槑 220 鏉ヨ嚜鐧惧害 SDK 鍐呴儴 alert锛岃鐪嬫湁娌℃湁銆岀櫨搴﹀脊绐椼�嶈锛�');
})();
</script>
+
+ <hr style="margin:24px 0" />
+ <h3>鐜鑳藉姏妫�娴嬶紙WebGL / XHR / 娓叉煋锛�</h3>
+ <div id="log5" style="padding:12px;background:#f9f0ff;border-radius:6px;font-family:Consolas,monospace;font-size:13px;line-height:1.9;white-space:pre-wrap;word-break:break-all"></div>
+ <script>
+ (function () {
+ var el = document.getElementById('log5');
+ function lg(msg, cls) {
+ var d = document.createElement('div');
+ d.className = cls || '';
+ d.textContent = msg;
+ el.appendChild(d);
+ }
+ lg('=== WebGL 鑳藉姏 ===');
+ var gl1 = null, gl2 = null;
+ try {
+ var c1 = document.createElement('canvas');
+ gl1 = c1.getContext('webgl') || c1.getContext('experimental-webgl');
+ } catch (e) { lg('WebGL1 妫�娴嬪紓甯�: ' + e.message, 'bad'); }
+ try {
+ var c2 = document.createElement('canvas');
+ gl2 = c2.getContext('webgl2');
+ } catch (e) {}
+ lg('WebGL 1.0: ' + (gl1 ? '鉁� 鏀寔' : '鉂� 涓嶆敮鎸�'), gl1 ? 'ok' : 'bad');
+ lg('WebGL 2.0: ' + (gl2 ? '鉁� 鏀寔' : '鉂� 涓嶆敮鎸�'), gl2 ? 'ok' : 'warn');
+ if (gl1) {
+ try {
+ var ext = gl1.getExtension('WEBGL_debug_renderer_info');
+ if (ext) {
+ lg('娓叉煋鍣�: ' + gl1.getParameter(ext.UNMASKED_RENDERER_WEBGL));
+ lg('鍘傚晢: ' + gl1.getParameter(ext.UNMASKED_VENDOR_WEBGL));
+ } else {
+ lg('娓叉煋鍣�: ' + gl1.getParameter(gl1.RENDERER));
+ }
+ } catch (e) {}
+ }
+ lg('');
+ lg('=== 鍏朵粬 ===');
+ lg('纭欢鍔犻��(绮楃暐): ' + (navigator.hardwareConcurrency || '?') + ' 鏍�');
+ lg('璁惧鍍忕礌姣�: ' + (window.devicePixelRatio || 1));
+ lg('鏄惁杩滅▼妗岄潰/铏氭嫙鏈�: 闇�鐪嬫覆鏌撳櫒鍚嶇О锛堝惈 SwiftShader/llvmpipe 鍗充负杞欢娓叉煋锛�', 'warn');
+
+ lg('');
+ lg('=== XHR 鎷︽埅锛堣褰曞け璐ヨ姹傜殑鐪熷疄鏉ユ簮锛�===');
+ var origOpen = XMLHttpRequest.prototype.open;
+ var origSend = XMLHttpRequest.prototype.send;
+ XMLHttpRequest.prototype.open = function (m, u) {
+ this.__url = u;
+ return origOpen.apply(this, arguments);
+ };
+ XMLHttpRequest.prototype.send = function () {
+ var xhr = this;
+ xhr.addEventListener('loadend', function () {
+ if (xhr.status === 0 || xhr.status >= 400) {
+ lg('鉂� XHR ' + (xhr.status || '澶辫触') + ' ' + String(xhr.__url).slice(0, 150), 'bad');
+ }
+ });
+ return origSend.apply(this, arguments);
+ };
+ lg('宸插紑濮嬫嫤鎴� XHR銆傝鍒锋柊椤甸潰鐪嬪畬鏁磋褰曘��');
+
+ // 3 绉掑悗妫�鏌ュ湴鍥惧鍣ㄩ噷鐨勫疄闄呭唴瀹�
+ setTimeout(function () {
+ var m = document.getElementById('map3');
+ if (!m) { return; }
+ lg('');
+ lg('=== 鍦板浘瀹瑰櫒瀹為檯鍐呭 ===');
+ lg('innerHTML 闀垮害: ' + m.innerHTML.length);
+ lg('canvas 鏁伴噺: ' + m.querySelectorAll('canvas').length);
+ lg('瀛愬厓绱�: ' + m.children.length);
+ lg('灏哄: ' + m.offsetWidth + ' x ' + m.offsetHeight);
+ }, 5000);
+ })();
+ </script>
+
+ <hr style="margin:24px 0" />
+ <h3>娣卞害鎺㈡祴锛圫DK 瀹屾暣鎬� / 瀹炰緥琛屼负 / 鍏ㄩ儴缃戠粶璇锋眰锛�</h3>
+ <div id="log6" style="padding:12px;background:#e6fffb;border-radius:6px;font-family:Consolas,monospace;font-size:13px;line-height:1.9;white-space:pre-wrap;word-break:break-all"></div>
+ <div id="probe-map" style="width:400px;height:300px;border:1px solid #ccc;margin-top:8px"></div>
+ <script>
+ (function () {
+ var el = document.getElementById('log6');
+ function lg(msg, cls) {
+ var d = document.createElement('div');
+ d.className = cls || '';
+ d.textContent = msg;
+ el.appendChild(d);
+ }
+ lg('=== 1. BMapGL 瀵硅薄瀹屾暣鎬� ===');
+ lg('typeof window.BMapGL = ' + typeof window.BMapGL);
+ if (window.BMapGL) {
+ lg('BMapGL.Map = ' + typeof window.BMapGL.Map);
+ lg('BMapGL.Point = ' + typeof window.BMapGL.Point);
+ lg('BMapGL.Marker= ' + typeof window.BMapGL.Marker);
+ lg('BMapGL.Circle= ' + typeof window.BMapGL.Circle);
+ lg('BMapGL.Geocoder = ' + typeof window.BMapGL.Geocoder);
+ lg('BMapGL.Version = ' + (window.BMapGL.Version || window.BMapGL.version || '(鏃�)'));
+ var keys = Object.keys(window.BMapGL);
+ lg('BMapGL 灞炴�ф暟閲�: ' + keys.length);
+ lg('鍓� 20 涓�: ' + keys.slice(0, 20).join(', '));
+ }
+
+ lg('');
+ lg('=== 2. 鏂板缓涓�涓函鍑�瀹瑰櫒锛屽垱寤哄湴鍥惧悗绔嬪嵆妫�鏌� ===');
+ var div = document.getElementById('probe-map');
+ try {
+ var t0 = Date.now();
+ var m = new window.BMapGL.Map(div);
+ lg('new BMapGL.Map() 杩斿洖绫诲瀷: ' + typeof m + '锛堣�楁椂 ' + (Date.now() - t0) + 'ms锛�', 'ok');
+ lg('瀹瑰櫒 innerHTML 闀垮害锛堢珛鍗筹級: ' + div.innerHTML.length, div.innerHTML.length > 0 ? 'ok' : 'bad');
+ lg('瀹瑰櫒 children 鏁伴噺: ' + div.children.length, div.children.length > 0 ? 'ok' : 'bad');
+ lg('瀹瑰櫒 outerHTML 鍓� 300: ' + div.outerHTML.slice(0, 300));
+ lg('map.getSize() = ' + JSON.stringify(m.getSize ? m.getSize() : null));
+ lg('map.getCenter() = ' + (m.getCenter ? JSON.stringify(m.getCenter()) : 'null'));
+ try {
+ m.centerAndZoom(new window.BMapGL.Point(87.616848, 43.825592), 14);
+ lg('centerAndZoom 璋冪敤鎴愬姛', 'ok');
+ } catch (e2) {
+ lg('centerAndZoom 寮傚父: ' + e2.message, 'bad');
+ }
+ setTimeout(function () {
+ lg('1 绉掑悗瀹瑰櫒 innerHTML 闀垮害: ' + div.innerHTML.length, div.innerHTML.length > 0 ? 'ok' : 'bad');
+ lg('1 绉掑悗 canvas 鏁伴噺: ' + div.querySelectorAll('canvas').length);
+ }, 1000);
+ } catch (e) {
+ lg('鍒涘缓鍦板浘鎶涘紓甯�: ' + e.message, 'bad');
+ lg('鍫嗘爤: ' + (e.stack || '').slice(0, 300), 'bad');
+ }
+
+ lg('');
+ lg('=== 3. 椤甸潰瀹為檯鍙戝嚭鐨勫叏閮ㄧ綉缁滆姹傦紙performance API锛�===');
+ setTimeout(function () {
+ var rs = performance.getEntriesByType('resource');
+ lg('鎬昏祫婧愯姹�: ' + rs.length);
+ var bm = rs.filter(function (r) { return r.name.indexOf('bmap') >= 0 || r.name.indexOf('baidu') >= 0; });
+ lg('bmap/baidu 鐩稿叧: ' + bm.length);
+ bm.forEach(function (r) {
+ var size = r.transferSize || r.encodedBodySize || 0;
+ var st = r.responseStatus || (size > 0 ? 200 : '?');
+ lg(' [' + st + '] ' + Math.round(r.duration) + 'ms ' + size + 'B ' + r.name.replace(location.origin, '').slice(0, 110), size > 0 ? '' : 'warn');
+ });
+ lg('');
+ lg('=== 4. 鎺у埗鍙伴敊璇崟鑾� ===');
+ lg('锛堝涓婃柟鏃犲紓甯革紝璇存槑 SDK 闈欓粯澶辫触锛岄噸鐐圭湅绗� 3 鑺傚摢浜涜姹� 0 瀛楄妭锛�');
+ }, 6000);
+ })();
+ </script>
+
+ <hr style="margin:24px 0" />
+ <h3>绗� 7 鍧楋細JS 鎵ц閿欒 + 2D 鐗堝湴鍥撅紙涓嶄緷璧� WebGL锛�</h3>
+ <div id="log7" style="padding:12px;background:#fcffe6;border-radius:6px;font-family:Consolas,monospace;font-size:13px;line-height:1.9;white-space:pre-wrap;word-break:break-all"></div>
+ <div id="map4" style="width:100%;height:340px;margin-top:12px;border:1px solid #ddd"></div>
+ <script>
+ (function () {
+ var el = document.getElementById('log7');
+ function lg(msg, cls) { var d = document.createElement('div'); d.className = cls || ''; d.textContent = msg; el.appendChild(d); }
+
+ setTimeout(function () {
+ lg('=== 鎹曡幏鍒扮殑 JS 鎵ц閿欒 ===');
+ if (!window.__bmapErr || window.__bmapErr.length === 0) {
+ lg('锛堟棤 JS 閿欒锛�', 'ok');
+ } else {
+ window.__bmapErr.slice(0, 15).forEach(function (m) { lg(m, 'bad'); });
+ }
+ }, 3000);
+
+ lg('');
+ lg('=== 2D 鐗堝湴鍥撅紙BMap锛屼笉浣跨敤 WebGL / Worker锛�===');
+ var s = document.createElement('script');
+ s.src = '/bmap-api/getscript?v=3.0&ak=' + KEY + '&services=&t=' + Date.now();
+ s.addEventListener('load', function () {
+ lg('load 瑙﹀彂锛寃indow.BMap = ' + typeof window.BMap, window.BMap ? 'ok' : 'bad');
+ if (!window.BMap) { return; }
+ try {
+ var map = new window.BMap.Map('map4');
+ map.centerAndZoom(new window.BMap.Point(87.616848, 43.825592), 14);
+ map.enableScrollWheelZoom(true);
+ lg('鍦板浘鍒涘缓鎴愬姛', 'ok');
+ setTimeout(function () {
+ var d = document.getElementById('map4');
+ lg('瀹瑰櫒 innerHTML 闀垮害: ' + d.innerHTML.length, d.innerHTML.length > 0 ? 'ok' : 'bad');
+ lg('瀹瑰櫒鍐� img 鏁伴噺: ' + d.querySelectorAll('img').length);
+ lg('馃憠 濡傛灉杩欓噷鑳界湅鍒颁箤椴佹湪榻愯閬擄紝璇存槑 2D 鐗堝彲鐢紝鎴戠珛鍗冲垏杩囧幓', 'ok');
+ }, 3000);
+ } catch (e) {
+ lg('鍒涘缓 2D 鍦板浘寮傚父: ' + e.message, 'bad');
+ }
+ });
+ s.addEventListener('error', function () { lg('2D SDK 鍔犺浇澶辫触', 'bad'); });
+ document.body.appendChild(s);
+ })();
+ </script>
+
+ <hr style="margin:24px 0" />
+ <h3>绗� 8 鍧楋細2D 鐗堟敼鍐� SDK锛堢摝鐗囦篃璧颁唬鐞嗭紝鏃� Worker锛�</h3>
+ <div id="log8" style="padding:12px;background:#f0f5ff;border-radius:6px;font-family:Consolas,monospace;font-size:13px;line-height:1.9;white-space:pre-wrap;word-break:break-all"></div>
+ <div id="map5" style="width:100%;height:340px;margin-top:12px;border:1px solid #ddd"></div>
+ <script>
+ (function () {
+ var el = document.getElementById('log8');
+ function lg(m, c) { var d = document.createElement('div'); d.className = c || ''; d.textContent = m; el.appendChild(d); }
+ lg('鍔犺浇 /bmap-sdk2d.js锛�2D 鏀瑰啓鐗堬紝鐡︾墖璧� /bmap-tileN锛�...');
+ var s = document.createElement('script');
+ s.src = '/bmap-sdk2d.js';
+ s.addEventListener('load', function () {
+ lg('load 瑙﹀彂锛寃indow.BMap = ' + typeof window.BMap, window.BMap ? 'ok' : 'bad');
+ if (!window.BMap) { return; }
+ try {
+ var map = new window.BMap.Map('map5');
+ map.centerAndZoom(new window.BMap.Point(87.616848, 43.825592), 14);
+ map.enableScrollWheelZoom(true);
+ lg('2D 鍦板浘鍒涘缓鎴愬姛', 'ok');
+ setTimeout(function () {
+ var d = document.getElementById('map5');
+ lg('瀹瑰櫒 innerHTML: ' + d.innerHTML.length);
+ lg('img 鏁伴噺: ' + d.querySelectorAll('img').length, d.querySelectorAll('img').length > 0 ? 'ok' : 'bad');
+ lg('馃憠 鑳界湅鍒扮殑琛楅亾灏辫鏄� 2D 鏀瑰啓鐗堝彲鐢�', 'ok');
+ }, 4000);
+ } catch (e) { lg('鍒涘缓寮傚父: ' + e.message, 'bad'); }
+ });
+ s.addEventListener('error', function () { lg('鍔犺浇澶辫触', 'bad'); });
+ document.body.appendChild(s);
+ })();
+ </script>
</body>
</html>
--
Gitblit v1.9.3