其他分享
首页 > 其他分享> > Leaflet中使用leaflet.easyPring插件实现打印效果

Leaflet中使用leaflet.easyPring插件实现打印效果

作者:互联网

场景

Leaflet快速入门与加载OSM显示地图:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/122290880

在上面的基础上,怎样使用插件实现打印效果如下

 

 

注:

博客:
https://blog.csdn.net/badao_liumang_qizhi
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

1、插件地址

https://github.com/rowanwins/leaflet-easyPrint

2、下载源码,引入所需的bundle.js文件,完整示例代码

<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>leaflet实现打印效果</title>
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
    <style>
        html,
        body,
        #map {
            padding: 0;
            margin: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
    </style>
</head>

<body>
    <div id="map"></div>
    <script type="text/javascript" src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
    <script type="text/javascript" src="./js/bundle.js"></script>
    <script type="text/javascript">
        var map = L.map('map').setView([36.09, 120.35], 13);
        var tiles =
            L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
                attribution: ''
            });
        tiles.addTo(map);

        L.marker([36.09, 120.35]).addTo(map)
            .bindPopup("<b>Hello world!</b><br />I am a popup.").openPopup();

        var printer = L.easyPrint({
            tileLayer: tiles,
            sizeModes: ['Current', 'A4Landscape', 'A4Portrait'],
            filename: 'myMap',
            exportOnly: true,
            hideControlContainer: true
        }).addTo(map);

        function manualPrint() {
            printer.printMap('CurrentSize', 'MyManualPrint')
        }
    </script>
</body>

</html>

 

标签:Leaflet,插件,map,tiles,leaflet,https,var,addTo
来源: https://www.cnblogs.com/badaoliumangqizhi/p/15792514.html