如何使用 Javascript 调整 Google Maps v3 中推文的信息窗口大小
我正在尝试向 Google 地图中的信息窗口添加一些推文。我将推文显示在一个 div 中,该 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);
});
I'm trying to add a few tweets to an infowindow in Google Maps. I get the tweets to display in a div that is the content of my infowindow, but it's the wrong size.
I thought by calling 'content_changed' when the marker is clicked, the infowindow would resize - it doesn't.
I'm sure this is pretty straightforward, can someone help me out?
Thanks,
James
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);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试在
open()
之前调用infowindow.close();
。我很确定它会强制它重新渲染Try to call
infowindow.close();
beforeopen()
. I'm pretty sure that it will force it to rerender这并不完全是受支持的解决方案,但在 Firebug 中进行研究后,我发现了一种强制调整窗口大小的简单方法:
至于第一行的实际 W/H 应该设置为多少,这是一个问题查看 infoWindow.b.contentNode 并通过标准属性或 jQuery 方法获取真实的宽度/高度。
我不确定 infoWindow.b 到底是什么,但它似乎是某种“内容”对象。我希望他们能够揭露这一点并记录下来。
This isn't exactly a supported solution, but after poking around in Firebug, I found an easy way to force a resize on the window:
As far as what the real W/H should be set to on the first line, that's a matter of looking at
infoWindow.b.contentNode
and getting a real width/height either through the standard properties or jQuery's methods.I'm not sure exactly what
infoWindow.b
is, but it seems like it's some sort of "content" object. I wish they would expose this and document it.我最终得到:
I ended up with: