Google 地图在 FancyBox 中无法正确渲染,我该如何纠正?
我目前需要在 FancyBox 内显示 Google 地图。本教程展示了如何使用“fancybox.iframe”CSS 类以直接的方式执行此操作,但我需要 FancyBox 来显示的不仅仅是地图,即。下面的表格。
到目前为止,这是我的代码(非常简单):
HTML
<div id="fancybox-container"></div>
CSS
#fancybox-container {
display: none;
width: 450px;
height: 500px;
border: 1px solid red;
padding: 3px;
overflow: hidden;
}
和最后一些 CoffeeScript:
$ ->
new FancyMap()
class FancyMap
constructor: ->
@openMap() #once fancybox is open proceed to render the map inside of it
options =
center: new google.maps.LatLng(6.191556, -75.579716)
zoom: 14
mapTypeId: google.maps.MapTypeId.ROADMAP
@map = new google.maps.Map $('#fancybox-container')[0], options
openMap: ->
$('a[href=#fancybox-container]').fancybox
maxWidth: 500
maxHeight: 550
fitToView: false
autoSize: true
closeClick: false
openEffect: 'none'
closeEffect: 'none'
window.FancyMap = FancyMap
结果几乎就是我想要的,除了渲染混乱,
如果我将地图拖入其中,结果是..如下所示:
所以,总而言之,我肯定缺少一个重要的属性或配置,对吗?你能帮我解决这个问题吗?
提前无限感谢,
注意。我在这里阅读并尝试了类似的问题,但仍然不成功。所以我将这里的问题简化为最简单的版本。
I have a present need to display a Google Map, inside a FancyBox. The tutorial shows how to do this in a straight-forward manner by using a "fancybox.iframe" CSS class, But I'll need my FancyBox to display more than just the map, ie. a form below.
So far, here's my code(very simple):
HTML
<div id="fancybox-container"></div>
CSS
#fancybox-container {
display: none;
width: 450px;
height: 500px;
border: 1px solid red;
padding: 3px;
overflow: hidden;
}
and finally some CoffeeScript:
$ ->
new FancyMap()
class FancyMap
constructor: ->
@openMap() #once fancybox is open proceed to render the map inside of it
options =
center: new google.maps.LatLng(6.191556, -75.579716)
zoom: 14
mapTypeId: google.maps.MapTypeId.ROADMAP
@map = new google.maps.Map $('#fancybox-container')[0], options
openMap: ->
$('a[href=#fancybox-container]').fancybox
maxWidth: 500
maxHeight: 550
fitToView: false
autoSize: true
closeClick: false
openEffect: 'none'
closeEffect: 'none'
window.FancyMap = FancyMap
The result of that, is almost what I want except that the rendering is messed up,
If I Drag the map inside, the result is.. something like this:
so, in conclusion, I'm certainly missing an important property or configuration, right? Can you help me solve this issue?
Infinite Thanks in advance,
Note. I have read and tried the similar Questions here, but I'm still unsuccessful. So I reduced my issue here to its simplest version.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当 Google 地图不知道其最终大小时,它会执行此操作,例如,如果您在打开灯箱之前将其分配给灯箱,则地图将不知道它需要多大的大小。
不要在构造函数中添加地图,而是尝试将其添加到回调中,该回调将在盒子打开时触发。
“mu 太短”提供的代码示例
http://goo.gl/t7SOm
Google Maps does this when it doesn't know how big its eventually going to be, for example if you assign it to the light box before opening it the map wont know what size it needs to be.
Rather than adding the map in the constructor try adding it to the callback which will fire when the box has opened.
Code example provided by "mu is too short"
http://goo.gl/t7SOm
您还可以触发
调整大小
地图
事件a> 获取 Maps API 来调整地图大小 容器。You can also trigger the
resize
event on theMap
to get the Maps API to resize the map container.