Bing Map V8 Infobox导致错误

时间:2017-08-03 10:43:06

标签: jquery bing-maps

我正在尝试将Bing Map V7迁移到V8,同时这样做我面临显示Info Box的问题,这是在显示信息框后给Map SDK带来错误。 应用程序中的代码片段:

        function DisplayLoc(e) {
                var map = null;
                var pinInfobox = null;
                var pinInfoBox; // the pop up info box
                var infoboxLayer = new Microsoft.Maps.EntityCollection();
                var pinLayer = new Microsoft.Maps.EntityCollection();
                var pins = statewithcities;
                map = new 
               Microsoft.Maps.Map(document.getElementById('bing_map'), {
                    mapTypeId: Microsoft.Maps.MapTypeId.road,
                    showDashboard: false,
                    enableSearchLogo: false,
                    enableClickableLogo: false,
                    showMapTypeSelector: false,
                    showScalebar: false,
                    disablePanning: false,
                    disableZooming: false,
                    showBreadcrumb: false,
                    disableBirdseye: true,
                    showCopyright: false,
                    credentials: mapID
                });
                 pinInfobox = new Microsoft.Maps.Infobox(new 
                  Microsoft.Maps.Location(0, 0), {
                    visible: false,
                    titleClickHandler: InfoboxHandler
                });
                infoboxLayer.push(pinInfobox);
                $.each(pins, function(index, pin) {
                 var pinLocation = new Microsoft.Maps.Location(
                 pin.latitude, pin.longitude)
                   NewPin.metadata.Title = pin.zipCode; 
                    NewPin.metadata.Id = pin.state;
                    NewPin.metadata.Description = "test";
                    pinLayer.push(NewPin); // add pushpin to pinLayer
           Microsoft.Maps.Events.addHandler(NewPin, 'click',displayInfobox);
                    map.entities.push(NewPin);
                });
                map.entities.push(pinInfobox);
               function displayInfobox(e) {
                if(e.target.metadata){
                  pinInfobox.setOptions({
                        id: e.target.metadataId,
                        title: e.target.metadata.Title,
                        description: e.target.metadata.Description,
                        visible: true,
                        offset: new Microsoft.Maps.Point(0, 0),
                        location:e.target.getLocation()
                    });
                }
              }

请检查并帮助我,因为我不确定在遵循Bing文档后错误发生在哪里。

1 个答案:

答案 0 :(得分:1)

删除以下代码行:

infoboxLayer.push(pinInfobox);

map.entities.push(pinInfobox);

创建信息框后,添加以下代码行:

pinInfobox.setMap(map);