简体   繁体   English

PrimeFaces 对话框中的传单地图渲染不正确

[英]Leaflet map incorrect rendering in PrimeFaces Dialog

Try to input Leaflet map into PrimeFaces Dialog.尝试将 Leaflet 地图输入到 PrimeFaces 对话框中。 And I have a issue with incorrect rendering.我有一个不正确的渲染问题。 Map has incorrect position, looks like map start positioning relative to index.html not to the Dialog.地图位置不正确,看起来地图开始定位相对于 index.html 而不是 Dialog。 The next issue: size is incorrect.下一个问题:尺寸不正确。 The same code outside the dialogue works fine.对话外的相同代码工作正常。 How to change this?如何改变这个?

<h:head>      
        <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
    </h:head>
    <h:body>
        <ui:composition> 
            <script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>           
            <p:dialog  id="map" header="Mapa:" widgetVar="wigetMapDialog" height="800px" width="1200px" showEffect="clip" hideEffect="clip" resizable="false" closable="true" dynamic="true" modal="true">               
                <div id="mapid" style="width: 1180px; height: 780px;"></div>  
                <script>
                    var mymap = L.map('mapid').setView([50.9547215, 16.9126256], 18);
                    L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
                                attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
                    }).addTo(mymap);
                </script>
            </p:dialog> 
        </ui:composition>
    </h:body>     
</html>

My Dialog:我的对话框:

在此处输入图片说明

When I move map inside:当我在里面移动地图时:

You most likely have two problems.你很可能有两个问题。

  1. The first one being that everything outside a ui:composition is ignored第一个是ui:composition之外的所有内容都被忽略
  2. Every non visible ( display: none ) html element has no width when retrieved with javascript 使用 javascript 检索时,每个不可见的 ( display: none ) html 元素都没有宽度

The first issue can be solved by adding the css inside the ui:composition .第一个问题可以通过在ui:composition添加 css 来解决。 The second one, getting the dimensions of a non-visible PrimeFaces (with display: none in the relevant rendered html code) is not (easily) solveable via the way mentioned in the link above.第二个,获取不可见的 PrimeFaces 的尺寸(在相关呈现的 html 代码中display: none )不是(容易)通过上面链接中提到的方式解决的。 This is the case with many frameworks, so other frameworks, like mentioned by @IvanSanchez, often have methods to recalulate the dimensions when something is shown.许多框架都是这种情况,因此其他框架(如@IvanSanchez 提到的)通常具有在显示某些内容时重新计算尺寸的方法。 So should call the mentioned invalidateSize() in the p:dialog onShow="..." like所以应该在p:dialog onShow="..."调用提到的invalidateSize()就像

<p:dialog ... onShow="mymap.invalidateSize()">

...
</p:dialog>

might solve the issue (disclaimer: not tried this, no computer at hand to try it)可能会解决问题(免责声明:没有尝试过,手头没有电脑可以尝试)

This i my solution:这是我的解决方案:

<script type="text/javascript">
       jQuery(document).ready(function ($) {
       mymap.invalidateSize();});
</script>

Thank you for a hint.谢谢你的提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM