简体   繁体   English

最大化对话框素数中的gmap

[英]Maximize gmap in dialog primefaces

I want to display a dialog which has a gmap as element, it works fine when I set height and width, but what I need is show it as maximized full screen map. 我想显示一个以gmap为元素的对话框,当我设置高度和宽度时,它可以正常工作,但是我需要将其显示为最大化的全屏地图。 The Dialog is shown in fullscreen, but map is empty, only when I back to default size it is shown. 对话框以全屏显示,但地图为空,仅当我返回默认大小时才显示。

My code is 我的代码是

<p:commandLink id="id" value="Modal" onclick="PF('dlg').show(); PF('dlg').toggleMaximize();"/>
<p:dialog appendTo="@(body)" id="dlg" widgetVar="dlg" maximizable="true" width="1920" height="1080">
    <p:gmap id="gmap" center="41.381542, 2.122893" zoom="15" type="HYBRID" style="width:100%;height:100%;"> 
    </p:gmap>
</p:dialog>

How can I solve my problem? 我该如何解决我的问题?

You can add following JavaScript on your page 您可以在页面上添加以下JavaScript

<script>
            function resizeElement(elementId,width,height){
                console.log("Resizing element " + elementId + " W/H="+ width + "/" + height);

                var element = document.getElementById(elementId);

                element.style.width=width+"px";
                element.style.height=height+"px"
            }

            function resizePfGmapInsideWrapperElement(wrapperElementId){
                var wrapperElement=document.getElementById(wrapperElementId);
                var width=wrapperElement.clientWidth-40;
                var height=wrapperElement.clientHeight-60;

                resizeElement("gmap",width,height);
            }

            function resizePfGmapInsideDialog(){
                resizePfGmapInsideWrapperElement("dlg");
            }
</script>

and then add resizePfGmapInsideDialog() into p:commandLink onclick 然后将resizePfGmapInsideDialog()添加到p:commandLink onclick

<p:commandLink id="id" 
               value="Modal" 
               onclick="PF('dlg').show(); PF('dlg').toggleMaximize(); resizePfGmapInsideDialog();"/>

Actually whenever you call PF('dlg').toggleMaximize(); 实际上,无论何时调用PF('dlg').toggleMaximize(); also call resizePfGmapInsideDialog() right after and p:gmap will automatically resize inside dialog's content area. 还可以在之后立即调用resizePfGmapInsideDialog() ,而p:gmap将在对话框的内容区域内自动调整大小。

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

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