未显示Bing地图信息框 - 在控制台上,setMap不是功能错误

时间:2017-01-13 18:12:02

标签: javascript maps bing-maps bing-api

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

    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);
                }


            }
  

未捕获的TypeError:arrPinInfobox.setMap不是GetMap的函数   (68A611D186DE4DC991773CAED323DA31.ashx:135)at   Object.Microsoft.Maps.notifyMapReadyForBootstrap   (www.bing.com/mapspreview/sdk/mapcontrol?branch=release&callback=GetMap:14)   在   www.bing.com/rms/SDKPlugin/jc,nj/9ac8b1b9/4153aba0.js?// BU =均方根+答案+ MapsSD ... leLayer MapsTilePrimer SDKMap PointCompression SDKPluginEnd < EM> AnonymousEnd:1   在   www.bing.com/rms/SDKPlugin/jc,nj/9ac8b1b9/4153aba0.js?// BU =均方根+答案+ MapsSD ... // leLayer MapsTilePrimer SDKMap PointCompression SDKPluginEnd AnonymousEnd: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 });
            }

1 个答案:

答案 0 :(得分:0)

为您的代码添加一些断点并逐步完成。你的代码有点乱,但看起来有可能当你到达setMap代码行时,信息框从未被创建,因为它是在try语句中创建的,并且可能永远不会被创建。

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