0

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

$(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。

4

2 回答 2

0

单独创建 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));
于 2014-09-16T17:12:22.200 回答
0

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

于 2014-09-17T08:41:14.843 回答