javascript - 移动 map 时,Bing map 信息框会移动 FireFox 和 Chrome 中的位置

标签 javascript position bing-maps bing bing-api

我使用 setHtmlContent 来设置 infoBox 的内容。根据文档,信息框最初固定在左上角。如果我移动 map (即使只是一点点),信息框就会跳转位置。在 IE8 中没问题,但在 FireFox 和 Chrome 中也行。

有人有解决这个问题的任何想法/经验或任何解决方案吗?

信息框添加方式如下(仅供引用)...

var infoboxOptions = { width: 300, height: 150, htmlContent: html, showCloseButton: true, zIndex: 99, offset: new Microsoft.Maps.Point(0, 0), showPointer: true, visible: false };
var location = new Microsoft.Maps.Location(pinArray[i].DPLat, pinArray[i].DPLong)
infobox = new Microsoft.Maps.Infobox(location, infoboxOptions);

然后推送到 map 上。

最佳答案

我在 FF 和 Chrome 中遇到了同样的问题。我使用的修复方法是监听 viewendchange 事件,然后在事件调度时重置信息框的位置。这适用于 IE7、IE8、IE9、FF、Chrome 和 Safari。不理想,但它有效。

function showInfoBox( event ) {
    var
        location = event.target.getLocation(), // event from pushpin click
        map = this.map, // my map reference
        _that = this
    ;

    // create the infobox
    var infoboxOptions = { width: 300, height: 150, htmlContent: html, showCloseButton: true, zIndex: 99, offset: new Microsoft.Maps.Point(0, 0), showPointer: true, visible: false };
    this._infoBox = new Microsoft.Maps.Infobox( location , infoboxOptions );
    map.entities.push( this._infoBox );

    // local function to reset our position
    function updateInfoboxLocation() {
        _that._infoBox.setLocation( location );
    }

    // reset only on new display of a box, this fixes the other issues of a user moving
    // the box and it being offset
    if( this._infoEventId ) Microsoft.Maps.Events.removeHandler( this._infoEventId );

    // listen for the end event, update location
    this._infoEventId = Microsoft.Maps.Events.addHandler(map, 'viewchangeend', updateInfoboxLocation);

    // center the view on the pin location
    map.setView( { center: location } );
}

关于javascript - 移动 map 时,Bing map 信息框会移动 FireFox 和 Chrome 中的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7979552/

相关文章:

javascript - 捕获 iframe jQuery 中的所有事件并复制

javascript - Highcharts 使用 json 将点添加到折线图

mysql - 查找字符串位置并连接另一个表的行

c - 如何在 Linux 上的 C 中设置鼠标光标位置?

javascript - 为什么 jQuery 会删除我的 <img> 元素?

JavaScript 循环以容纳从 Webhook 接收的已过滤对象数组

html - 将图像放置在我想要 HTML 的位置

c# - 双向绑定(bind)导致 wp7 的 map 控件出现奇怪的行为

silverlight - WP7 bing map 控件中图钉的 ZIndex

javascript - 未捕获的类型错误:无法读取 undefined::javascript::bing map 的属性 'add'