import { __awaiter, __generator } from "tslib";
window['CESIUM_BASE_URL'] =
    window['CESIUM_BASE_URL'] ||
        '//gis.7cdn.msign.net/assets/angularis_js_api/1.63.1-0.1.0/';
import '@msign/angularis/Build/Cesium/Widgets/widgets.css';
import { Viewer, SkyBox, Color, RequestScheduler } from '@msign/angularis';
import Instance from '../core/Instance';
var CesiumControl = /** @class */ (function () {
    function CesiumControl() {
    }
    /** *******************************************************************************
     *  Cesium 库必须异步引入, 这并不是单纯为了切分代码.
     *  因为 Cesium 在导入时会自动执行, 并读取 window.requestAnimationFrame 函数
     *
     *  检视 ./Loop.ts 里的代码可明白
     *  应用层在初始化的时候会尝试替换默认的 requestAnimationFrame 函数, 以实现底层控制.
     *
     *  需要等应用层初始化好(即不可以同步方式导入 Cesium 依赖). 才能导入 Cesium 库.
     **********************************************************************************/
    CesiumControl.prototype._fetchCesium = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: 
                    // await import('cesium/Build/Cesium/Cesium.js');
                    // await import('cesium/Build/CesiumUnminified/Cesium_new.js');
                    return [4 /*yield*/, import('../core/CesiumFix')];
                    case 1:
                        // await import('cesium/Build/Cesium/Cesium.js');
                        // await import('cesium/Build/CesiumUnminified/Cesium_new.js');
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    CesiumControl.constructorAsync = function (container, option) {
        if (option === void 0) { option = {}; }
        return __awaiter(this, void 0, void 0, function () {
            var inst, noSky, viewer;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        console.time('构造cesium实例');
                        if (container) {
                            Instance.resetInstance();
                        }
                        inst = new CesiumControl();
                        return [4 /*yield*/, inst._fetchCesium()];
                    case 1:
                        _a.sent();
                        while (container.childNodes && container.childNodes[0]) {
                            container.removeChild(container.childNodes[0]);
                        }
                        noSky = new SkyBox({});
                        viewer = (inst._viewer = new Viewer(container, {
                            animation: false,
                            baseLayerPicker: false,
                            creditContainer: document.createElement('div'),
                            contextOptions: {
                                webgl: {
                                    alpha: true,
                                    preserveDrawingBuffer: true
                                }
                            },
                            geocoder: false,
                            global: true,
                            homeButton: false,
                            maximumRenderTimeChange: 4,
                            navigationHelpButton: false,
                            // requestRenderMode: true,
                            sceneModePicker: false,
                            selectionIndicator: false,
                            skyBox: noSky,
                            timeline: false,
                            skyAtmosphere: false
                            // imageryProvider: new Cesium.UrlTemplateImageryProvider({
                            //   url:
                            //     '//gis.7cdn.msign.net/maps/google_map_cn/vt/lyrs=s@716,h@245000000&gl=CN&x={x}&y={y}&z={z}',
                            //   credit: '',
                            //   tilingScheme: new Cesium.WebMercatorTilingScheme(),
                            //   maximumLevel: 18
                            // })
                        }));
                        viewer.scene.globe.baseColor = new Color(0, 0, 0, 0);
                        viewer.scene.globe.imageryLayers.get(0).alpha = 0.5;
                        viewer.scene.highDynamicRange = false;
                        viewer.scene.backgroundColor = new Color(0, 0, 0, 1);
                        viewer.scene.moon && (viewer.scene.moon.show = false);
                        console.timeEnd('构造cesium实例');
                        return [2 /*return*/, inst];
                }
            });
        });
    };
    Object.defineProperty(CesiumControl.prototype, "viewer", {
        get: function () {
            return this._viewer;
        },
        enumerable: true,
        configurable: true
    });
    CesiumControl.prototype.bustMode = function (bust) {
        if (bust === void 0) { bust = true; }
        if (bust) {
            RequestScheduler.maximumRequestsPerServer = 256;
            RequestScheduler.maximumRequests = 512;
        }
        else {
            RequestScheduler.maximumRequestsPerServer = 6;
            RequestScheduler.maximumRequests = 50;
        }
    };
    return CesiumControl;
}());
export default CesiumControl;
