将Google Map DIV转换为图像

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将Google Map DIV转换为图像相关的知识,希望对你有一定的参考价值。

这是我的问题的简化,但我希望澄清。

我有一个安装在div中的Google Maps对象。地图完美地回归。

它上面有一个WMS覆盖图(例如,1990年出生的人的数据图)。地图上的WMS图层完美返回。

我的问题是如何将包含Google Map和WMS的DIV画布转换为PNG / GIF图像?

我查看了静态地图API,但这并不好,因为我正在调用WMS图层。需要使用Google APIv3

答案

You can use this Example and convert div to image

或使用此代码

$(function() { 
    $("#btnSave").click(function() { 
        html2canvas($("#widget"), {
            onrendered: function(canvas) {
                theCanvas = canvas;
                document.body.appendChild(canvas);

                // Convert and download as image 
                Canvas2Image.saveAsPNG(canvas); 
                $("#img-out").append(canvas);
                // Clean up 
                //document.body.removeChild(canvas);
            }
        });
    });
}); 

以上是关于将Google Map DIV转换为图像的主要内容,如果未能解决你的问题,请参考以下文章

如何将带有 SVG 的 div#WareHouse 转换为图像

将 div 转换为可下载的图像

将div转换为可下载的图像

google-map 片段应用程序在模拟器中崩溃后打开 WebView 活动

将 Google Maps Container DIV 宽度和高度设置为 100%

如何使用 Javascript 将 div 转换为图像