【问题标题】:Can't capture the content of the google-maps's 'infowindow' with html2canvas无法使用 html2canvas 捕获 google-maps 的“信息窗口”的内容
【发布时间】:2019-12-13 00:32:43
【问题描述】:

我在使用 html2canvas 捕获谷歌地图时遇到问题。

当我选择一个地点时,谷歌地图会显示一个包含该地点信息的信息窗口,但是当我在打印中捕获地图时,只会出现一个白色矩形。

当你在这个例子中选择任何地方并且你将地图保存为 png 时,你会看到这个问题

http://jsfiddle.net/Lindow/60yn2hss/

<script>
$(function() { 
    $("#btnSave").click(function() { 
            $("#img-out").children().remove();
        html2canvas($("#map"), {
            useCORS: true,
            onrendered: function(canvas) {
                theCanvas = canvas;
                document.body.appendChild(canvas);
                $("#img-out").append(canvas);
            }
        });
    });
}); 

var map = new GMaps({
    div: '#map',
    lat: -12.043333,
    lng: -77.028333
    });
</script>

<style>
#map {
  width:300px;
  height:300px;
}

.elements {
  display:inline-block;
}
</style>

<input type="button" id="btnSave" value="Save PNG"/>
<hr>
<div class="elements" id="map"></div>
<div class="elements" id="img-out"></div>

这个例子在三个月前有效。

有什么想法吗?

提前致谢

【问题讨论】:

    标签: google-maps html2canvas


    【解决方案1】:

    发现错误,需要使用html2canvas的属性“use Overflow: false”

    html2canvas($("#map"), {
                    useCORS: true,
                    useOverflow: false,
                    onrendered: function(canvas) {
                        theCanvas = canvas;
                        document.body.appendChild(canvas);
                        $("#img-out").append(canvas);
                    }
                });
    

    【讨论】:

    • 很好,你让它工作了,但是......这是在哪里记录的?我在官方文档中找不到任何关于 useOverflow 的信息...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-23
    • 2011-08-08
    • 2014-10-16
    • 2013-01-25
    • 1970-01-01
    • 1970-01-01
    • 2014-11-13
    相关资源
    最近更新 更多