ansel0926
2022-05-14 ecdaa37a673565e8e7419ac9062106b89e051c3e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(function (window) {
    'use strict';
 
    function define_CesiumDataView() {
        var CesiumDataView = {};
 
 
        CesiumDataView.exportImg = function (options) {
            let canvas = options.viewer.scene.canvas;
            var image = new Image();  
            canvas.width=canvas.width/options.level; 
            canvas.height=canvas.height/options.level;      
            options.viewer.render();
 
            image = canvas.toDataURL("image/png");  
           
            let link = document.createElement("a");
            let blob = dataURLtoBlob(image);
            let objurl = URL.createObjectURL(blob); 
            link.download = "scene.png";
            link.href = objurl;
            link.click();
        }
 
        function dataURLtoBlob(dataurl) {
            let arr = dataurl.split(','),
                mime = arr[0].match(/:(.*?);/)[1],
                bstr = atob(arr[1]),
                n = bstr.length,
                u8arr = new Uint8Array(n);
            while (n--) {
                u8arr[n] = bstr.charCodeAt(n);
            }
            return new Blob([u8arr], { type: mime });
        }
 
        return CesiumDataView; 
    }
 
 
    if (typeof (CesiumDataView) === 'undefined') {
        window.CesiumDataView = define_CesiumDataView();
    } else {
        console.log("CesiumDraw already defined.");
    }
})(window);