1

我正在尝试在 Google 地图的信息窗口中添加一些推文。我让推文显示在我的信息窗口内容的 div 中,但它的大小错误。

我想通过在单击标记时调用' content_changed ',信息窗口会调整大小 - 它不会。

我敢肯定这很简单,有人可以帮助我吗?

谢谢,

詹姆士

var myLatlng = new google.maps.LatLng(51.500261,-0.126793);
var myOptions = {
  zoom: 12,
  center: myLatlng,
  mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById("map_canvas"),
    myOptions);

var marker = new google.maps.Marker({
  position: myLatlng,
  map: map,
});

var infowindow = new google.maps.InfoWindow();
infowindow.setContent(document.getElementById("station"));

google.maps.event.addListener(marker, 'click', function() {
    google.maps.event.trigger(infowindow, 'content_changed');
    infowindow.open(map,marker);
});
4

3 回答 3

1

Try to call infowindow.close(); before open(). I'm pretty sure that it will force it to rerender

于 2010-07-17T16:31:20.337 回答
0

这不是一个完全受支持的解决方案,但在 Firebug 中四处寻找之后,我找到了一种强制调整窗口大小的简单方法:

infoWindow.b.contentSize = new google.maps.Size(w, h);
google.maps.event.trigger(infoWindow.b, 'contentsize_changed');

至于真正的 W/H 应该在第一行设置什么,这infoWindow.b.contentNode是通过标准属性或 jQuery 的方法查看并获得真正的宽度/高度的问题。

我不确定到底是什么infoWindow.b,但它似乎是某种“内容”对象。我希望他们能揭露这一点并记录下来。

于 2012-02-29T23:22:46.727 回答
0

我最终得到:

infoWindowLinea.setContent(infoWindowLinea.getContent());
于 2014-03-08T23:04:14.607 回答