Google 地图在 FancyBox 中无法正确渲染,我该如何纠正?

发布于 2025-01-04 15:19:36 字数 1382 浏览 2 评论 0原文

我目前需要在 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

结果几乎就是我想要的,除了渲染混乱,

fancybox+googlemaps

如果我将地图拖入其中,结果是..如下所示:

fancyboxdragged

所以,总而言之,我肯定缺少一个重要的属性或配置,对吗?你能帮我解决这个问题吗?

提前无限感谢,

注意。我在这里阅读并尝试了类似的问题,但仍然不成功。所以我将这里的问题简化为最简单的版本。

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,

fancybox+googlemaps

If I Drag the map inside, the result is.. something like this:

fancyboxdragged

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诗化ㄋ丶相逢 2025-01-11 15:19:36

当 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

谜兔 2025-01-11 15:19:36

您还可以触发调整大小地图 事件a> 获取 Maps API 来调整地图大小 容器。

You can also trigger the resize event on the Map to get the Maps API to resize the map container.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文