Bing地图 - 路线管理器:未捕获的ReferenceError:未定义sj_evt

时间:2018-02-06 20:40:49

标签: javascript jquery html bing-maps

问题

基本上,当我们加载网站时,我注意到控制台中出现错误,声明Uncaught ReferenceError: sj_evt is not defined。我之前没有做任何更改会导致显示此错误。

以下是完整错误:

Uncaught ReferenceError: sj_evt is not defined
at t._subscribeToTaskFocusEvent (www.bing.com/rms/InternalControlsPluginBundle/cj,nj/7cecd1c6/0f79a01b.js?bu=rms+answers+Maps+AnonymousBegin*InternalControls.en*InternalControlsPluginStart*TaskBarTemplate*TaskBarViewModel*TaskBar*TaskBarItem*CategorySearchTemplate*UserTipTemplate*UserTipControl*CategoryDropdownControl*CategoryDropdownManager*CategoryItem*PrintDialog*PrintLogHelper*PrintDialogViewModel*PrintManager*SharingDialog*SharingDialogViewModel*SharePanelTemplate*SharePanel*BirdsEyeV2DialogViewModel*BirdsEyeV2Dialog*CommutabilityControl*CommutabilityControlOverlay*CommutabilityLogHelper*CommutabilityControlTemplate*ContextualTaskbarManager*InternalControlsPluginEnd*AnonymousEnd:1)
at t.initialize (www.bing.com/rms/InternalControlsPluginBundle/cj,nj/7cecd1c6/0f79a01b.js?bu=rms+answers+Maps+AnonymousBegin*InternalControls.en*InternalControlsPluginStart*TaskBarTemplate*TaskBarViewModel*TaskBar*TaskBarItem*CategorySearchTemplate*UserTipTemplate*UserTipControl*CategoryDropdownControl*CategoryDropdownManager*CategoryItem*PrintDialog*PrintLogHelper*PrintDialogViewModel*PrintManager*SharingDialog*SharingDialogViewModel*SharePanelTemplate*SharePanel*BirdsEyeV2DialogViewModel*BirdsEyeV2Dialog*CommutabilityControl*CommutabilityControlOverlay*CommutabilityLogHelper*CommutabilityControlTemplate*ContextualTaskbarManager*InternalControlsPluginEnd*AnonymousEnd:1)
at www.bing.com/rms/InternalControlsPluginBundle/cj,nj/7cecd1c6/0f79a01b.js?bu=rms+answers+Maps+AnonymousBegin*InternalControls.en*InternalControlsPluginStart*TaskBarTemplate*TaskBarViewModel*TaskBar*TaskBarItem*CategorySearchTemplate*UserTipTemplate*UserTipControl*CategoryDropdownControl*CategoryDropdownManager*CategoryItem*PrintDialog*PrintLogHelper*PrintDialogViewModel*PrintManager*SharingDialog*SharingDialogViewModel*SharePanelTemplate*SharePanel*BirdsEyeV2DialogViewModel*BirdsEyeV2Dialog*CommutabilityControl*CommutabilityControlOverlay*CommutabilityLogHelper*CommutabilityControlTemplate*ContextualTaskbarManager*InternalControlsPluginEnd*AnonymousEnd:1
at www.bing.com/rms/InternalControlsPluginBundle/cj,nj/7cecd1c6/0f79a01b.js?bu=rms+answers+Maps+AnonymousBegin*InternalControls.en*InternalControlsPluginStart*TaskBarTemplate*TaskBarViewModel*TaskBar*TaskBarItem*CategorySearchTemplate*UserTipTemplate*UserTipControl*CategoryDropdownControl*CategoryDropdownManager*CategoryItem*PrintDialog*PrintLogHelper*PrintDialogViewModel*PrintManager*SharingDialog*SharingDialogViewModel*SharePanelTemplate*SharePanel*BirdsEyeV2DialogViewModel*BirdsEyeV2Dialog*CommutabilityControl*CommutabilityControlOverlay*CommutabilityLogHelper*CommutabilityControlTemplate*ContextualTaskbarManager*InternalControlsPluginEnd*AnonymousEnd:1

从目前为止我发现,这与在Bing Maps中加载Directions Manager模块有关。它似乎唯一影响的是调用.clearAll()后路线管理器重新渲染自身的方式。它会在每个重新加载的图块上创建一种红色闪烁。

我能够在Chrome,Safari和Firefox上重现错误,以及Chrome,Safari,Firefox上的红色闪烁,偶尔也会在Internet Explorer上重现。

我在MDSN支持论坛中看到有关此错误的a post,其中提到了加载模块时可能出现的时序问题。但是,从我如何加载地图和路线管理器,这应该不是问题。该帖子随后被关闭,说明错误已自行解决,但似乎并没有为所有用户解决。

代码

以下是我在索引文件中调用Bing Maps的方法:

<script src='https://www.bing.com/api/maps/mapcontrol?branch=experimental&callback=initialize' async defer></script>

请注意,此错误发生在V8的发行版和实验版分支上。

这是回调引用的函数:

function initialize () {
    const CENTER = new Microsoft.Maps.Location(44.96375272262944, -93.2353971897461);

    // Initialize the map
    map = new Microsoft.Maps.Map(document.getElementById('map-canvas'), {
        credentials: API_KEY,
        minZoom: zoom,
        center: CENTER,
        disableStreetside: true,
        disableStreetsideAutoCoverage: true,
        enableClickableLogo: false,
        showLocateMeButton: false,
        showMapTypeSelector: false,
        disablePanning: disablePanning,
        disableZooming: disableZoom,
        draggable: isDraggable
    });

    // Creates all busses and adds them to an array
    bus1 = {
        directionsManager: null,
    };
    bus2 = {
        directionsManager: null,
    };
    bus3 = {
        directionsManager: null,
    };
    buses = [bus1, bus2, bus3];

    // Add the traffic layer
    Microsoft.Maps.loadModule('Microsoft.Maps.Traffic', function () {
        trafficLayer = new Microsoft.Maps.Traffic.TrafficManager(map);
    });

    // Add the directions manager
    Microsoft.Maps.loadModule('Microsoft.Maps.Directions', function () {
        bus1.directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);
        bus2.directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);
        bus3.directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);

        Microsoft.Maps.Events.addHandler(bus1.directionsManager, 'directionsError', function(e) {
            console.log("Error: " + e.message + "\r\nResponse Code: " + e.responseCode);
        });
        Microsoft.Maps.Events.addHandler(bus1.directionsManager, 'directionsUpdated', function(e) {
            directionsUpdated(e, bus1);
        });

        Microsoft.Maps.Events.addHandler(bus2.directionsManager, 'directionsError', function(e) {
            console.log("Error: " + e.message + "\r\nResponse Code: " + e.responseCode);
        });
        Microsoft.Maps.Events.addHandler(bus2.directionsManager, 'directionsUpdated', function(e) {
            directionsUpdated(e, bus2);
        });

        Microsoft.Maps.Events.addHandler(bus3.directionsManager, 'directionsError', function(e) {
            console.log("Error: " + e.message + "\r\nResponse Code: " + e.responseCode);
        });
        Microsoft.Maps.Events.addHandler(bus3.directionsManager, 'directionsUpdated', function(e) {
            directionsUpdated(e, bus3);
        });

        // Call for the current version of our bus data
        requestServerUpdate();
    });

    console.log("Initialization complete.");
}

我删除了大部分不需要的代码,并留下了与模块和地图加载相关的所有内容。如果看起来缺少重要的东西或者您想要更多代码,请告诉我,我很乐意更新帖子。

问题

所以我想主要的问题是,有什么办法可以解决我发生的Uncaught ReferenceError: sj_evt is not defined错误或摆脱它造成的红色闪烁吗?

感谢所有人提前获得任何建议!

修改

Here是Codepen,显示指定的Uncaught ReferenceError: sj_evt is not defined错误。但是,由于示例中未实现.clearAll()函数,因此不会显示闪烁错误。

为了补充这一点,下面是一个示例: Red Flashing Example

经过进一步测试,我发现红色是由于附近有彩色多边形引起的。删除后,只会出现大量模糊的地图部分。

0 个答案:

没有答案