• <tfoot id='GDMGj'></tfoot>
  • <small id='GDMGj'></small><noframes id='GDMGj'>

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

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

          <bdo id='GDMGj'></bdo><ul id='GDMGj'></ul>

      1. 在容器调整大小时调整传单地图的大小

        时间:2023-05-28

          • <tfoot id='DaxER'></tfoot>
          • <legend id='DaxER'><style id='DaxER'><dir id='DaxER'><q id='DaxER'></q></dir></style></legend>

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

                  <tbody id='DaxER'></tbody>
                  <bdo id='DaxER'></bdo><ul id='DaxER'></ul>
                  <i id='DaxER'><tr id='DaxER'><dt id='DaxER'><q id='DaxER'><span id='DaxER'><b id='DaxER'><form id='DaxER'><ins id='DaxER'></ins><ul id='DaxER'></ul><sub id='DaxER'></sub></form><legend id='DaxER'></legend><bdo id='DaxER'><pre id='DaxER'><center id='DaxER'></center></pre></bdo></b><th id='DaxER'></th></span></q></dt></tr></i><div id='DaxER'><tfoot id='DaxER'></tfoot><dl id='DaxER'><fieldset id='DaxER'></fieldset></dl></div>
                • 本文介绍了在容器调整大小时调整传单地图的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有一个包含传单地图的 <div>.在某些事件中,<div> 的高度将会改变.我想让地图调整到其周围 <div> 的新尺寸,以便旧中心在调整后的更小或更大的地图中居中.我尝试使用 invalidateSize() 函数,但它似乎根本不起作用.在 map-container-resize 事件之后如何调整地图大小和居中?

                  I have a <div> containing a leaflet map. Upon certain events the height of the <div> will be altered. I'd like for the map to resize to the new dimensions of its surrounding <div> so that the old center is centered in the resized smaller or larger map. I tried using the invalidateSize() function, but it doesn't seem to work at all. How can I resize and center the map after that map-container-resize event?

                  $mapContainer.on('map-container-resize', function () {
                     map.invalidateSize(); // doesn't seem to do anything
                  });
                  

                  编辑以提供更多上下文:

                  地图容器最初的样式为

                  #map-container {
                      width: 100%;
                      height: 100%;
                      position: absolute;
                      top: 0;
                      left: 0;
                  
                      transition: height 0.5s ease-in-out;
                  }
                  

                  用户单击某个按钮后,页面底部会显示另一个面板,并且地图容器的高度将降低到小于 100%(例如 80%).

                  After a user clicks a certain button, another panel shows at the bottom of the page and the map-container's height will be reduced to something less than 100% (say 80%).

                  单击此按钮后,将触发 map-container-resize 事件,以便我可以使地图调整大小并以旧的(即在调整大小之前)中心为中心.然后,地图本身也应调整为其初始高度的 80%.

                  Upon click on this button, the map-container-resize event is triggered so that I can make the map resize and center on its old (i.e. before the resizing happened) center. The map itself should then also be resized to 80% of its initial height.

                  invalidateSize 的 APi 文档似乎是我想要的:

                  The APi doc for invalidateSize seemed to be what I wanted:

                  "检查地图容器大小是否改变,如果改变则更新地图[...]"

                  "Checks if the map container size changed and updates the map if so [...]"

                  但是看看调用 invalidateSize 前后 getSize 函数的输出,没有什么不同,地图保持原来的大小.

                  But having a look with the output of the getSize function before and after the call to invalidateSize, nothing is different, the map remains at its old size.

                  推荐答案

                  问题是 #map-container div 的大小调整是通过 css 转换完成的.转换尚未开始,更不用说结束了,此时调用了 invalidateSize,因此传单地图无法识别其周围 div 的任何尺寸变化.

                  The problem is that the resizing of the #map-container div is done via a css transition. The transition hasn't started yet, let alone ended, when the call to invalidateSize happens so the leaflet map cannot recognize any change of dimensions of its surrounding div.

                  延迟触发 map-container-resize 事件解决了这个问题.这样:

                  Triggering the map-container-resize event with a delay solved the problem. This way :

                  setTimeout(function(){ map.invalidateSize()}, 400);
                  

                  这篇关于在容器调整大小时调整传单地图的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何保护 JavaScript API 访问令牌? 下一篇:将传单输出保存为 html

                  相关文章

                  最新文章

                  • <bdo id='b9sbO'></bdo><ul id='b9sbO'></ul>
                  <tfoot id='b9sbO'></tfoot>

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

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

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