/**
 * GetViewExtent获取当前视图范围
 * GetViewCenter获取当前视图中心点
 */
var CesiumViewTool = (function () {
    function _() {
    }
    _.GetViewExtent = function (viewer) {
        var extent = {};
        var scene = viewer.scene;
        var ellipsoid = scene.globe.ellipsoid;
        var canvas = scene.canvas;
        var car3_lt = viewer.camera.pickEllipsoid(new Cesium.Cartesian2(0, 0), ellipsoid);// canvas左上角
        var car3_rb = viewer.camera.pickEllipsoid(new Cesium.Cartesian2(canvas.width, canvas.height), ellipsoid); // canvas右下角
        // 当canvas左上角和右下角全部在椭球体上
        if (car3_lt && car3_rb) {
            var carto_lt = ellipsoid.cartesianToCartographic(car3_lt);
            var carto_rb = ellipsoid.cartesianToCartographic(car3_rb);
            extent.xmin = Cesium.Math.toDegrees(carto_lt.longitude);
            extent.ymax = Cesium.Math.toDegrees(carto_lt.latitude);
            extent.xmax = Cesium.Math.toDegrees(carto_rb.longitude);
            extent.ymin = Cesium.Math.toDegrees(carto_rb.latitude);
        } else if (!car3_lt && car3_rb) { // 当canvas左上角不在但右下角在椭球体上
            var car3_lt2 = null;
            var yIndex = 0;
            var xIndex = 0;
            do {
                // 这里每次10像素递加，一是10像素相差不大，二是为了提高程序运行效率
                yIndex <= canvas.height ? yIndex += 10 : canvas.height;
                xIndex <= canvas.width ? xIndex += 10 : canvas.width;
                car3_lt2 = viewer.camera.pickEllipsoid(new Cesium.Cartesian2(xIndex, yIndex), ellipsoid);
            } while (!car3_lt2);
            var carto_lt2 = ellipsoid.cartesianToCartographic(car3_lt2);
            var carto_rb2 = ellipsoid.cartesianToCartographic(car3_rb);
            extent.xmin = Cesium.Math.toDegrees(carto_lt2.longitude);
            extent.ymax = Cesium.Math.toDegrees(carto_lt2.latitude);
            extent.xmax = Cesium.Math.toDegrees(carto_rb2.longitude);
            extent.ymin = Cesium.Math.toDegrees(carto_rb2.latitude);
        }
        else if (car3_lt && !car3_rb) { // 当canvas左上角在但右下角不在椭球体上
            var car3_rb2 = null;
            var yIndex = canvas.height;
            var xIndex = canvas.width;
            do {
                // 这里每次10像素递加，一是10像素相差不大，二是为了提高程序运行效率
                yIndex >= 10 ? yIndex -= 10 : 10;
                xIndex >= 10 ? xIndex -= 10 : 10;
                car3_rb2 = viewer.camera.pickEllipsoid(new Cesium.Cartesian2(yIndex, yIndex), ellipsoid);
            } while (!car3_rb2);
            var carto_lt2 = ellipsoid.cartesianToCartographic(car3_lt);
            var carto_rb2 = ellipsoid.cartesianToCartographic(car3_rb2);
            extent.xmin = Cesium.Math.toDegrees(carto_lt2.longitude);
            extent.ymax = Cesium.Math.toDegrees(carto_lt2.latitude);
            extent.xmax = Cesium.Math.toDegrees(carto_rb2.longitude);
            extent.ymin = Cesium.Math.toDegrees(carto_rb2.latitude);
        } else if (!car3_lt && !car3_rb) {
            var car3_lt2 = null;
            var yIndex = 0;
            var xIndex = 0;
            do {
                // 这里每次10像素递加，一是10像素相差不大，二是为了提高程序运行效率
                yIndex <= canvas.height ? yIndex += 10 : canvas.height;
                xIndex <= canvas.width ? xIndex += 10 : canvas.width;
                car3_lt2 = viewer.camera.pickEllipsoid(new Cesium.Cartesian2(xIndex, yIndex), ellipsoid);
            } while (!car3_lt2);
            var car3_rb2 = null;
            var yIndex = canvas.height;
            var xIndex = canvas.width;
            do {
                // 这里每次10像素递加，一是10像素相差不大，二是为了提高程序运行效率
                yIndex >= 10 ? yIndex -= 10 : 10;
                xIndex >= 10 ? xIndex -= 10 : 10;
                car3_rb2 = viewer.camera.pickEllipsoid(new Cesium.Cartesian2(yIndex, yIndex), ellipsoid);
            } while (!car3_rb2);
            var carto_lt2 = ellipsoid.cartesianToCartographic(car3_lt2);
            var carto_rb2 = ellipsoid.cartesianToCartographic(car3_rb2);
            extent.xmin = Cesium.Math.toDegrees(carto_lt2.longitude);
            extent.ymax = Cesium.Math.toDegrees(carto_lt2.latitude);
            extent.xmax = Cesium.Math.toDegrees(carto_rb2.longitude);
            extent.ymin = Cesium.Math.toDegrees(carto_rb2.latitude);
        }
        // 获取高度
        extent.height = Math.ceil(viewer.camera.positionCartographic.height);
        return extent;
    }
    _.GetViewCenter = function (viewer) {
        var result = viewer.camera.pickEllipsoid(new Cesium.Cartesian2(viewer.canvas.clientWidth / 2, viewer.canvas.clientHeight / 2));
        if (result) { } else { return null; }
        var curPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(result);
        var lon = curPosition.longitude * 180 / Math.PI;
        var lat = curPosition.latitude * 180 / Math.PI;
        var height = viewer.camera.positionCartographic.height;
        return {
            lon: lon,
            lat: lat,
            height: height
        };
    }
    return _;
})();
export default CesiumViewTool