gpt4 book ai didi

javascript - Bing map 信息框未显示 - setMap 不是控制台上的函数错误

转载 作者:行者123 更新时间:2023-11-28 05:07:16 24 4
gpt4 key购买 nike

我的 bing map 无法加载信息框。我有一个数组,可以为渲染的位置创建图钉,下面是我使用的代码。我已经添加了用于显示的控制台消息,以检查它是否被正确调用。我想知道偏移/ anchor 是否与不显示信息框有关。有人可以帮我吗?

    var arrPins = [];
var arrPinCenter = [];
//Generating Pins for multiple locations with Lat,Long
for (var locNum = 0; locNum <= arrLocInfoRec.length - 1; locNum++) {
try {
arrLLAdder = arrLocInfoRec[locNum].split("`");
if (arrLLAdder.length >= 13) {
arrPinCenter[locNum] = new Microsoft.Maps.Location(parseFloat(arrLLAdder[11]), parseFloat(arrLLAdder[12]));
arrPinCenter[locNum] = new Microsoft.Maps.Location(parseFloat(arrLLAdder[11]), parseFloat(arrLLAdder[12]));
arrPins[locNum] = new Microsoft.Maps.Pushpin(
arrPinCenter[locNum], {
text: arrLLAdder[8] , icon: 'https://www.bingmapsportal.com/Content/images/poi_custom.png', anchor: new Microsoft.Maps.Point(12, 39)
}
var adder = arrLLAdder[2] + '\r\n' + arrLLAdder[4] + '\r\n' + arrLLAdder[6] + arrLLAdder[9] + "\r\n" + arrLLAdder[1]
// Create the infobox for the pushpin
arrPinInfobox[locNum] = new Microsoft.Maps.Infobox(arrPins[locNum].getLocation(),
{ width: 350,
height: 100,
title: arrLLAdder[5],
description: adder,
offset: new Microsoft.Maps.Point(-3,13)`enter code here`
});
// Add handler for the pushpin click event.
Microsoft.Maps.Events.addHandler(arrPins[locNum], 'click', displayInfobox);
}

else {
console.log("Invalid Data: arrLocInfoRec[" + locNum + "] = \"" + arrLocInfoRec[locNum] + "\"");
}`enter code here`
} catch (e) {
console.log(e.message + "\r\n" + arrLocInfoRec[locNum]);
}
}
// Hide the infobox when the map is moved.
// Microsoft.Maps.Events.addHandler(map, 'viewchange', hideInfobox);
// Add the Push Pins and InfoBox to the map all at once

if(arrPins.length > 0) {
map.entities.push(arrPins); //[locNum]
arrPinInfobox.setMap(map);

//I get a console error here for the setMap function
// see error below
//map.entities.push(arrPinInfobox);
//map.entities.push(InfoBoxEntity);
}


}

Uncaught TypeError: arrPinInfobox.setMap is not a function at GetMap (68A611D186DE4DC991773CAED323DA31.ashx:135) at Object.Microsoft.Maps.notifyMapReadyForBootstrap (www.bing.com/mapspreview/sdk/mapcontrol?branch=release&callback=GetMap:14) at www.bing.com/rms/SDKPlugin/jc,nj/9ac8b1b9/4153aba0.js?//bu=rms+answers+MapsSD…leLayerMapsTilePrimerSDKMapPointCompressionSDKPluginEndAnonymousEnd:1 at www.bing.com/rms/SDKPlugin/jc,nj/9ac8b1b9/4153aba0.js?//bu=rms+answers+MapsSD…//leLayerMapsTilePrimerSDKMapPointCompressionSDKPluginEndAnonymousEnd:1

我使用下面的代码来显示信息框

            function displayInfobox(e) {
//map.entities.push(arrPinInfobox);
console.log("DisplayBox");
for(var i in arrPinInfobox)
arrPinInfobox[i].setOptions({ visible: true });
arrPinInfobox[parseInt(e.target.getText()) - 1].setOptions({ visible: true });
}

最佳答案

向代码中添加一些断点并单步调试它。您的代码有点困惑,但看起来有可能当您到达 setMap 代码行时,信息框从未创建,因为它是在 try 语句内创建的,并且可能从未创建。

也就是说,我强烈建议使用单个信息框以获得更好的性能。看看这个代码示例:https://msdn.microsoft.com/en-us/library/mt750274.aspx

关于javascript - Bing map 信息框未显示 - setMap 不是控制台上的函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41640943/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com