tuqin
3 天以前 08fdad8d691b9c68f865b7aee1d62b8a09213656
public/bmap-test.html
@@ -145,5 +145,52 @@
        document.body.appendChild(s);
      })();
    </script>
    <hr style="margin:24px 0" />
    <h3>本站改写版 SDK(SDK + 瓦片 + 接口全部走代理)</h3>
    <div style="padding:8px;background:#fffbe6;border-radius:6px;font-size:13px;margin-bottom:8px">
      这是正式页面实际使用的方式:/bmap-sdk.js 里的百度域名已被改写成 /bmap-xxx,
      由服务器用固定 IPv4 回源,客户端不再直连百度。
    </div>
    <div id="log3" style="padding:12px;background:#f6ffed;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="map3" style="width:100%;height:360px;margin-top:12px;border:1px solid #ddd"></div>
    <script>
      (function () {
        var el = document.getElementById('log3');
        function lg(msg, cls) {
          var t = new Date().toLocaleTimeString('zh-CN', { hour12: false });
          var d = document.createElement('div');
          d.className = cls || '';
          d.textContent = '[' + t + '] ' + msg;
          el.appendChild(d);
        }
        lg('开始加载 /bmap-sdk.js(改写版)...');
        var start = Date.now();
        var s = document.createElement('script');
        s.src = '/bmap-sdk.js';
        s.addEventListener('load', function () {
          lg('load 事件触发(耗时 ' + ((Date.now() - start) / 1000).toFixed(2) + ' 秒)', 'ok');
          lg('window.BMapGL = ' + (window.BMapGL ? '存在' : '不存在'), window.BMapGL ? 'ok' : 'bad');
          if (!window.BMapGL) { return; }
          try {
            var map = new window.BMapGL.Map(document.getElementById('map3'));
            map.centerAndZoom(new window.BMapGL.Point(87.616848, 43.825592), 14);
            map.enableScrollWheelZoom(true);
            lg('地图创建成功,正在加载瓦片...', 'ok');
            setTimeout(function () {
              var imgs = document.querySelectorAll('#map3 canvas, #map3 img');
              lg('地图区域已渲染元素数量: ' + imgs.length, imgs.length > 0 ? 'ok' : 'warn');
              lg('👉 如果下方地图能看到乌鲁木齐的街道,说明全部打通了', 'ok');
            }, 3000);
          } catch (e) {
            lg('创建地图失败: ' + e.message, 'bad');
          }
        });
        s.addEventListener('error', function () {
          lg('error 事件:/bmap-sdk.js 本身加载失败', 'bad');
        });
        document.body.appendChild(s);
      })();
    </script>
  </body>
</html>