我使用 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/