2011-11-02 51 views
0

我使用setHtmlContent设置infoBox的内容。根据文档信息框最初锚定在左上角。如果我移动地图(即使只是一点点),infoBox跳转位置。它在IE8中很好,但在FireFox和Chrome中都有。Bing地图InfoBox在移动地图时在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); 

然后推到地图中。

回答

1

我在FF和Chrome中遇到同样的问题。我使用的修复程序是听取事件的事件,然后在调度事件时重置信息框的位置。这适用于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 }); 
} 
1

看来,当您在地图上推入信息框时,其偏移量是默认的。当mapView发生变化时,它会在正确的时候更新(设置htmlContent时((0,0))。

相关问题