You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Bing Maps路线管理器报错:Uncaught ReferenceError: sj_evt is not defined

解决Bing Maps Directions Manager的sj_evt is not defined错误及红色闪烁问题

针对你遇到的这个问题——未修改代码却出现Uncaught ReferenceError: sj_evt is not defined,且调用.clearAll()后路线管理器重新渲染时出现红色闪烁,这大概率是Bing Maps Directions Manager模块内部状态清理不彻底或版本兼容性导致的问题,以下是几个可行的排查和解决方向:

  • 检查脚本版本与加载顺序
    首先确认你加载的Bing Maps主脚本和Directions Manager模块的版本是否完全一致。如果主地图脚本用了某个版本,而Directions Manager用了另一个,很可能出现内部变量不兼容的情况。比如确保两者的URL中v=参数值相同(比如都是v=1.0或最新稳定版)。另外,避免异步加载导致的竞态条件,务必把所有依赖Directions Manager的逻辑放在Microsoft.Maps.loadModule('Microsoft.Maps.Directions', callback)的回调函数内,确保模块完全加载后再执行操作。

  • 替换.clearAll()为实例销毁重建
    .clearAll()方法可能没有彻底重置Directions Manager的内部状态,导致重新渲染时找不到内部事件对象sj_evt。你可以尝试销毁旧实例并重建,替代直接调用.clearAll():

    // 清理旧的Directions Manager实例
    if (window.directionsManager) {
        window.directionsManager.dispose();
        window.directionsManager = null;
    }
    // 重新创建实例并配置
    window.directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);
    // 重新添加途经点、设置渲染选项等
    window.directionsManager.calculateDirections();
    
  • 用异常捕获规避错误扩散
    针对红色闪烁的视觉异常,你可以用try-catch包裹相关操作,当捕获到sj_evt相关错误时,自动触发实例重建,避免错误影响页面渲染:

    try {
        directionsManager.clearAll();
        // 重新配置路线并计算
        directionsManager.calculateDirections();
    } catch (err) {
        if (err.message.includes('sj_evt is not defined')) {
            // 触发实例重建逻辑
            directionsManager.dispose();
            directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);
            // 重新初始化配置
            // ...
            directionsManager.calculateDirections();
        }
    }
    
  • 排查服务端临时问题
    偶尔微软的地图服务端更新会引入临时bug,你可以尝试在不同环境测试,或者等待1-2天看看是否自动修复。也可以检查Bing Maps官方的服务状态页面确认是否有已知故障。

内容的提问来源于stack exchange,提问作者Chase Ingebritson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:09:51