谷歌地图v3更改信息窗口的大小
我想设置信息窗口的大小以适应其中的内容。标准信息窗口太宽我尝试使用 maxWidth 但它似乎不起作用。调整信息窗口大小的最佳方法是什么?
请参阅代码:
window.setContent( inspStates[i].name+ "<br/>"+"total: "+inspStates[i].totalInsp+ "<br/>"+ info);
气泡中将显示的信息如下所示( \n 表示下一行)
NY \n总计 60 \n2009: 10 \n2010: 20 \n2011: 30
I would like to set the size of an infowindow to fit the content inside. The standard infowindow is too wide I tried to use maxWidth but it doesn't seem to work. What is the best way to resize an infowindow?
see code:
window.setContent( inspStates[i].name+ "<br/>"+"total: "+inspStates[i].totalInsp+ "<br/>"+ info);
the information that will be displayed in the bubble looks like this( \n means next line)
NY \ntotal 60 \n2009: 10 \n2010: 20 \n2011: 30
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您想要做的是将“标准”Googlemaps infoWindow 替换为您自己的信息窗口,并将您的内容放入其中。一旦您更换了标准 GM 信息窗口,您就有很大的工作自由度。我所做的是:
添加一个名为 #infoWindow 的新样式 ID,并设置其宽度。
在 Javascript 中的任何函数之外,我创建一个新的 infoWindow:
在函数中创建一个新的 var,用于设置标记显示的信息,并将其值设置为内容:
使用您的位置信息调用 createMarker 函数会在其他地方创建,并包含 html var 作为参数之一:
您将在其他地方声明的 createMarker 函数,它将把所有信息放在一起,在地图上显示标记,并在单击时显示上面的信息:
What you want to do is replace the "standard" Googlemaps infoWindow with your own, and put your content into it. Once you replace the standard GM infoWindow, you have a lot of latitude to work with. What I did is this:
Add a new style ID called #infoWindow, and set its width.
Outside of any functions within my Javascript, I create a new infoWindow:
Create a new var within the function that sets the information displayed by the marker(s), and set its value to the content:
Call the createMarker function using the location information you would have created elsewhere, and include the html var as one of the arguments:
The createMarker function you would declare elsewhere, which would bring all of the information together, display the marker on your map, and display the information above when it's clicked on:
这样每个人都清楚,如果他们偶然发现了这条线索。
您所需要做的就是在信息窗口内容中设置容器的高度和宽度。
您不需要覆盖谷歌类,也不需要对此变得过于复杂。
在我的 css 中我有这个:
就是这样。这就是设置 Google 地图信息窗口宽度所需要做的全部工作。
Just so everyone is clear, if they stumble on this thread.
All you need to do is set the height and width of a container in the your info window content.
You don't need to override google classes and you don't need to get overly complicated about this.
In my css I have this:
That's it. That's all you need to do to set the width of a Google Maps InfoWindow.
对我来说这个 CSS 工作得很好:
For me this CSS works fine:
请查看以下 API 参考和示例:
Google Map V3 示例:
https://developers.google.com/maps/documentation/javascript/examples/
Google Map V3 API 参考:
https://developers.google.com/maps/documentation/javascript/reference#MapOptions
please take a look at following API references and examples:
Google Map V3 Examples:
https://developers.google.com/maps/documentation/javascript/examples/
Google Map V3 API Ref:
https://developers.google.com/maps/documentation/javascript/reference#MapOptions
要设置 google 地图内气泡信息窗口的大小,只需在 CSS 文件中添加以下 css 即可:
改编自 这个讨论。
To set the size of the bubble info-window inside a google map it's enough to add the following css in your CSS file:
Adapted from this discussion.
JFrancis 的答案是正确的,只是在设置宽度时不要忘记在 CSS 中添加“!important”!这看起来可能是一件小事,但如果你不这样做,你的 CSS 就会被覆盖!
JFrancis answers is the right one, just don't forget to add "!important" in your CSS when you set the width! This might look like a minor thing, but if you don't do it, your CSS will simply get overwritten!