2011-11-02 64 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))。