0

我使用 setHtmlContent 来设置 infoBox 的内容。根据文档,信息框最初锚定在左上角。如果我移动地图(即使只是一点点),信息框也会跳转位置。它在 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);

然后推到地图上。

4

2 回答 2

1

我在 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 } );
}
于 2011-12-16T17:57:44.930 回答
1

似乎当您在地图上推送信息框时,它的偏移量是默认值。当 mapView 发生变化时,它会更新为正确的(设置 htmlContent 时 (0,0) )。

于 2012-09-27T13:37:09.630 回答