<small id='auQQP'></small><noframes id='auQQP'>

<legend id='auQQP'><style id='auQQP'><dir id='auQQP'><q id='auQQP'></q></dir></style></legend>

    <i id='auQQP'><tr id='auQQP'><dt id='auQQP'><q id='auQQP'><span id='auQQP'><b id='auQQP'><form id='auQQP'><ins id='auQQP'></ins><ul id='auQQP'></ul><sub id='auQQP'></sub></form><legend id='auQQP'></legend><bdo id='auQQP'><pre id='auQQP'><center id='auQQP'></center></pre></bdo></b><th id='auQQP'></th></span></q></dt></tr></i><div id='auQQP'><tfoot id='auQQP'></tfoot><dl id='auQQP'><fieldset id='auQQP'></fieldset></dl></div>

      <tfoot id='auQQP'></tfoot>

      • <bdo id='auQQP'></bdo><ul id='auQQP'></ul>

      灰色框出现在模态框中嵌入的谷歌地图的部分中

      时间:2023-06-13

        <tbody id='LNzS6'></tbody>
      <tfoot id='LNzS6'></tfoot>

          • <bdo id='LNzS6'></bdo><ul id='LNzS6'></ul>
            <i id='LNzS6'><tr id='LNzS6'><dt id='LNzS6'><q id='LNzS6'><span id='LNzS6'><b id='LNzS6'><form id='LNzS6'><ins id='LNzS6'></ins><ul id='LNzS6'></ul><sub id='LNzS6'></sub></form><legend id='LNzS6'></legend><bdo id='LNzS6'><pre id='LNzS6'><center id='LNzS6'></center></pre></bdo></b><th id='LNzS6'></th></span></q></dt></tr></i><div id='LNzS6'><tfoot id='LNzS6'></tfoot><dl id='LNzS6'><fieldset id='LNzS6'></fieldset></dl></div>

            <small id='LNzS6'></small><noframes id='LNzS6'>

                <legend id='LNzS6'><style id='LNzS6'><dir id='LNzS6'><q id='LNzS6'></q></dir></style></legend>
                本文介绍了灰色框出现在模态框中嵌入的谷歌地图的部分中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在通过 v3 API 在模态框中嵌入 Google 地图时遇到问题.

                I'm having a problem with embedding a Google Map via the v3 API in a modal box.

                显示模式时地图画布中会出现灰色框. 调整浏览器窗口大小、打开 Web Inspector 等使所有地图图块可见,即它强制重新渲染"地图.

                Grey boxes appear in the map canvas when the modal is shown. Resizing the browser window, bringing up Web Inspector, etc. makes all map tiles visible, i.e. it "force re-render" the map.

                地图元素的父元素(section#map-modal,参见下面的代码)在页面加载时的 CSS 中设置了 display: none.当点击显示按钮时,JS 模态代码会自动设置 display: block.如果我暂时从模态元素中删除 display: none ,则地图会在页面刷新时正确呈现.谷歌地图不喜欢有一个隐藏的父元素吗?

                The parent element of the map element (section#map-modal, see code below) has display: none set in its CSS on page load. The JS modal code automatically sets display: block when the show button is clicked. If I temporarily remove display: none from the modal element, the map renders correctly on page refresh. Isn't the Google Map liking having a hidden parent element?

                我正在使用 Twitter 的 Bootstrap 模态 jQuery 插件,并使用 CSS 控制模态本身.它是固定位置的,有像素宽度等.没什么不寻常的.

                I'm using Twitter's Bootstrap modal jQuery plugin, and am controlling the modal itself with CSS. It's fixed positioned, have a pixel width, etc. Nothing unusual.

                我当然在谷歌上搜索过解决方案,并且很多点都指向了触发 resize 事件的 Google API 方法:

                I've of course googled around for solutions, and many points to the Google API method of triggering the resize event:

                google.maps.event.trigger(map, 'resize');
                

                我确实这样做了,但是没有用.

                I've indeed done so, but to no avail.

                相关代码:https://gist.github.com/1591488

                如你所见,我在第 39 行触发了事件.

                As you can see, I'me triggering the events at line 39.

                (按侧边栏底部的查看大地图按钮).

                (press the View larger map button at the bottom of the sidebar).

                文件:

                • fagerhult.js
                • fagerhult.map.js
                • bootstrap-modal.js
                • master.css

                我将非常感谢任何帮助或额外的一双眼睛,因为我很快就会为它发疯.

                I would deeply appreciate any help or extra pair of eyes in this, as I'm soon going mad over it.

                推荐答案

                尝试使用模态事件处理程序.我认为这是确保在显示模式后调整大小而不重写任何插件的最简洁(和正确)的方法:

                Try using the modal event handlers. I think this is the most concise (and correct) way to ensure that you are resizing after the modal is shown without rewriting any plugins:

                $('#map-modal').on('shown', function () {
                  google.maps.event.trigger(map, 'resize');
                })
                

                更新:我刚刚意识到这个解决方案仍然不能正确地居中地图,所以我需要再添加一个命令:

                UPDATE: I just realized that this solution still does not center the map properly, so I needed to add one more command:

                $('#map-modal').on('shown', function () {
                  google.maps.event.trigger(map, 'resize');
                  map.setCenter(new google.maps.LatLng(42.3605336, -72.6362989));
                })
                

                这篇关于灰色框出现在模态框中嵌入的谷歌地图的部分中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Javascript 在模态窗口关闭时停止 HTML5 视频播放 下一篇:html 模态弹出窗口

                相关文章

              1. <small id='mc28W'></small><noframes id='mc28W'>

                <legend id='mc28W'><style id='mc28W'><dir id='mc28W'><q id='mc28W'></q></dir></style></legend>

                  <tfoot id='mc28W'></tfoot>

                      <bdo id='mc28W'></bdo><ul id='mc28W'></ul>
                    <i id='mc28W'><tr id='mc28W'><dt id='mc28W'><q id='mc28W'><span id='mc28W'><b id='mc28W'><form id='mc28W'><ins id='mc28W'></ins><ul id='mc28W'></ul><sub id='mc28W'></sub></form><legend id='mc28W'></legend><bdo id='mc28W'><pre id='mc28W'><center id='mc28W'></center></pre></bdo></b><th id='mc28W'></th></span></q></dt></tr></i><div id='mc28W'><tfoot id='mc28W'></tfoot><dl id='mc28W'><fieldset id='mc28W'></fieldset></dl></div>