【问题标题】:Printing map from google maps without controls从没有控件的谷歌地图打印地图
【发布时间】:2011-06-12 00:36:34
【问题描述】:

我正在使用谷歌地图 api v2。当我去打印地图时,控件显示在打印输出上。如何设置 GLargeMapControl 和 GMapTypeControl 不打印?

我在 API 中看到有一个 GControl Printable 构造函数,但找不到任何有关其用法的信息。

我尝试过使用这两个功能:

函数 Clickheretoprint() { var disp_setting="toolbar=no,location=no,directories=no,menubar=no,"; disp_setting+="滚动条=no,width=650, 高度=600,左侧=100,顶部=25"; var content_vlue = document.getElementById("gm").innerHTML;

var docprint=window.open("","",disp_setting);

docprint.document.open();
docprint.document.write('<html><head><title>Inel

电力系统');

docprint.document.write('</head><body

class="gmnoprint 打印" onLoad="window.print();window.close()">'); docprint.document.write(content_vlue); docprint.document.write(''); docprint.document.close(); docprint.focus(); }

函数 ClickHereToPrint(){ 尝试 {

  var oIframe =

document.getElementById('ifrmPrint'); var o内容 = document.getElementById('gm').innerHTML; var oDoc = (oIframe.contentWindow || oIframe.contentDocument);如果 (oDoc.document) oDoc = oDoc.document; oDoc.write("title"); oDoc.write(""); oDoc.write(oContent + ""); oDoc.close(); }

捕捉(e){

  self.print();

}

}

在我的 HTML 页面中:

var 纬度,经度,init_zoom; 纬度 = 44.9647979303; lon = -99.84375; init_zoom = 3;
谷歌地图打印测试

<script type="text/javascript" src="mapscripts.js"></script> </head>

打印

            <div id="bottomDiv" class="clsBottomDiv" align="left">
                <table>
                    <tr>
                        <td>
                            Search for Address:
                          <form onSubmit="return Geocode()">
                            <input id="search" type="text" size="60"

/>

                    </tr>
                </table>
            </div>

        </td>
    </tr>
</table> </div> </body> </html>

我也尝试给 iframe 一个 gmnoprint 类,但没有成功。

【问题讨论】:

    标签: javascript google-maps google-maps-api-2


    【解决方案1】:

    只需使用打印样式表 :)

    You can read all about it here

    Google 已经为您提供了方便,只需针对“gmnoprint”类,您就可以摆脱所有这些东西 :)

    如果您不想要额外的打印样式表,您可以将此规则添加到现有样式表中:

    @media print {
       .gmnoprint {display: none;}
    }
    

    或将其内联到您的页面中:

    <style>
    @media print {
       .gmnoprint {display: none;}
    }
    </style>
    

    【讨论】:

    • 你的测试页对我来说很好,并且不打印覆盖 - 你使用什么浏览器?
    • 当我从浏览器菜单栏打印页面时,它打印得很好..但是当我通过 javascript 尝试时(点击页面上的“打印”一词)它没有..
    • 这应该告诉你问题是你的javascript打印实现,而不是打印样式表:)
    猜你喜欢
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多