• openlayers之地图截图 方法1 2


    方法1

        //this.map._this为初始化地图对象
         this.map._this.once('postcompose', function (event) {
              var canvas = event.context.canvas;
              if (navigator.msSaveBlob) {
                navigator.msSaveBlob(canvas.msToBlob(), 'map.png');
              } else {
                canvas.toBlob(function (blob) {
                  saveAs(blob, 'map.png');
                });
              }
            });
            this.map._this.renderSync();
    
    

    方法2 调用html2canvas插件

       // 调用html2canvas插件
     html2canvas(document.getElementById('map_container'), {
              allowTaint: false,
              foreignObjectRendering: true,
              taintTest: false,
              useCORS: true,//火狐浏览器添加项
              onrendered: function (canvas) {
                var image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
                var userAgent = navigator.userAgent;
                //判断是否是IE11
                if (-1 !== userAgent.indexOf("Trident")) {
                  var arr = image.split(',');
                  var mime = arr[0].match(/:(.*?);/)[1];
                  var bstr = atob(arr[1]);
                  var n = bstr.length;
                  var u8arr = new Uint8Array(n);
                  while (n--) {
                    u8arr[n] = bstr.charCodeAt(n);
                  }
                  window.navigator.msSaveBlob(new Blob([u8arr], { type: mime }), "download.png");
                } else {
                  canvas.id = "mycanvas";
                  //生成base64图片数据
                  var dataUrl = canvas.toDataURL();
                  var newImg = document.createElement("img");
                  newImg.setAttribute('crossOrigin', 'anonymous');
                  newImg.src = dataUrl;
                  var b = document.createElement('a')
                  b.setAttribute("href", dataUrl)
                  b.setAttribute("download", "img.png")
                  document.body.appendChild(b)//火狐浏览器添加项
                  b.click(); b.remove()
                }
              }
            });
    
  • 相关阅读:
    2.pt-table-checksum工具
    Mysql8.0新特性01
    12.redis 之阅读大佬文章随笔
    4.Mysql之Mysqldump命令
    5. 关于高负载服务器Kernel的TCP参数优化
    Mysql Oracle 备份表数据、批量删除表数据
    Mysql limit用法
    Java 字符串数组转字符串
    Layui 自定义年份下拉框并且可输入
    Mysql 生成UUID
  • 原文地址:https://www.cnblogs.com/wwj007/p/11765848.html
Copyright © 2020-2023  润新知