赣州市洪水风险预警系统三维版本
guoshilong
2023-02-27 4d8c6dd77427e8e581fda17b6b65ba86bfb7a815
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
47
48
49
50
51
52
53
54
55
56
57
import when from '../ThirdParty/when.js';
import Check from './Check.js';
import defaultValue from './defaultValue.js';
import defined from './defined.js';
import Resource from './Resource.js';
 
    /**
     * @private
     */
    function loadImageFromTypedArray(options) {
        var uint8Array = options.uint8Array;
        var format = options.format;
        var request = options.request;
        var flipY = defaultValue(options.flipY, false);
        //>>includeStart('debug', pragmas.debug);
        Check.typeOf.object('uint8Array', uint8Array);
        Check.typeOf.string('format', format);
        //>>includeEnd('debug');
 
        var blob = new Blob([uint8Array], {
            type : format
        });
 
        var blobUrl;
        return Resource.supportsImageBitmapOptions()
            .then(function(result) {
                if (result) {
                    return when(Resource.createImageBitmapFromBlob(blob, {
                        flipY: flipY,
                        premultiplyAlpha: false
                    }));
                }
 
                blobUrl = window.URL.createObjectURL(blob);
                var resource = new Resource({
                    url: blobUrl,
                    request: request
                });
 
                return resource.fetchImage({
                    flipY : flipY
                });
            })
            .then(function(result) {
                if (defined(blobUrl)) {
                    window.URL.revokeObjectURL(blobUrl);
                }
                return result;
            })
            .otherwise(function(error) {
                if (defined(blobUrl)) {
                    window.URL.revokeObjectURL(blobUrl);
                }
                return when.reject(error);
            });
    }
export default loadImageFromTypedArray;