必应地图信息框集 Html内容不起作用



我的网站上有以下Bing地图的代码。它遵循上给出的示例http://www.bingmapsportal.com/isdk/ajaxv7#Infobox20.但是infoboxOptions中的htmlContent属性和setHtmlContent()方法似乎都没有为Infobox添加我想要的背景色。信息框本身会正确渲染。其他属性似乎也起作用。

$(document).ready(function () {
    var map = null;
    function getMap() {
        // Get the Map
        var map = new Microsoft.Maps.Map(document.getElementById('mapDiv'),
                  {
                      credentials: "Bing Maps Key",
                      center: new Microsoft.Maps.Location(42, -120.5),
                      mapTypeId: Microsoft.Maps.MapTypeId.road,
                      zoom: 4
                  });
        // Specify InfoBoxOptions
        var infoboxOptions = {
            showPointer: false,
            showCloseButton: false,
            width: 500, height: 700,
            title: 'Results',
            offset: new Microsoft.Maps.Point(-900, -400),
            htmlContent: '<div style="background-color:red; width:500px; height:700px;"></div>',
            visible: true
        };
        var defaultInfobox = new Microsoft.Maps.Infobox(map.getCenter(), infoboxOptions);
        map.entities.push(defaultInfobox);
        defaultInfobox.setHtmlContent('<div style="background-color:red; min-width:500px; min-height:700px;"></div>');
    }
    getMap();
});

如何将HTML添加到信息框?我在这里使用了背景色,但我的想法是,我将显示一个自定义HTML,可能有几个点击事件。

我有一篇关于如何在这里设置信息框的客户HTML的博客文章:http://rbrundritt.wordpress.com/2011/11/08/simple-custom-infoboxes-in-bing-maps-v7/

单独创建HTML:

var html = '<table class="table table-striped table-hover table-responsive">';
    html = html + '<thead>';
    html = html +    '<tr>';
    html = html +       '<th>VIN</th>';
    html = html +       '<th>Location</th>';
    html = html +       '<th>Estimated Delivery</th>';
    html = html +    '</tr>';
    html = html + '</thead>';
    html = html + '<tbody>';
    html = html +    '<tr>';
    html = html +       '<td>XYZ</td>';
    html = html +       '<td>(40, -120.5)</td>';
    html = html +       '<td>9/25</td>';
    html = html +    '</tr>';
    html = html + '</tbody>';
    html = html +'</table>';
    var popupHtml = '<div style="background-color:whitesmoke; min-width:480px; min-height:680px;">{content}</div>';

然后,我们可以指定:

    defaultInfobox.setHtmlContent(popupHtml.replace('{content}', html));

最新更新