import * as OpenLayersUtils from './openlayers/OpenLayersUtils';
import * as CesiumUtils from './cesium/CesiumUtils';
import ScreenShot from '@/modules/utils/screenshot/ScreenShot';
/**
 * @function SuperMapUtils.setMapConfig
 * @description 设置地图配置
 * @param {object} config - 地图配置
 */
const setMapConfig = (config) => {
    if (config) {
        OpenLayersUtils.setMapConfig(config);
        CesiumUtils.setMapConfig(config);
    }
};
/**
 * @function SuperMapUtils.fullExtent
 * @description 全图
 * @param {SuperMapType} instance - 地图对象
 */
const fullExtent = (instance) => {
    switch (instance.instanceType) {
        case 'OpenLayers':
            return OpenLayersUtils.fullExtent(instance);
        case 'Cesium':
            return CesiumUtils.fullExtent(instance);
    }
};
/**
 * @function SuperMapUtils.initFullScreen
 * @description 初始化全屏地图（绑定按钮)
 * @param {Vue} vm Vue实例
 * @param {string} [key] 需要控制的按钮显示对应的属性名 默认值：isFullScreen
 */
const initFullScreen = (vm, key = 'isFullScreen') => {
    window.addEventListener('keydown', () => {
        const e = event || window.event;
        if (e && e.keyCode === 122) {
            // 捕捉F11键盘动作
            e.preventDefault(); // 阻止F11默认动作
            const el = document.documentElement;
            const rfs = el.requestFullScreen ||
                el.webkitRequestFullScreen ||
                el.mozRequestFullScreen ||
                el.msRequestFullScreen; // 定义不同浏览器的全屏API
            // 执行全屏
            const win = window;
            if (typeof rfs !== 'undefined' && rfs) {
                rfs.call(el);
            }
            else if (typeof win.ActiveXObject !== 'undefined') {
                const wScript = new win.ActiveXObject('WScript.Shell');
                if (wScript !== null) {
                    wScript.SendKeys('{F11}');
                }
            }
        }
    });
    [
        'webkitfullscreenchange',
        'fullscreenchange',
        'mozfullscreenchange',
        'msfullscreenchange'
    ].forEach((item) => {
        document.addEventListener(item, function () {
            const el = document;
            if (el.webkitIsFullScreen ||
                el.fullscreen ||
                el.mozFullScreen ||
                el.msFullScreen) {
                // 全屏后要执行的代码
                vm[key] = true;
            }
            else {
                // 退出全屏后执行的代码
                vm[key] = false;
            }
        }, false);
    });
};
/**
 * @function SuperMapUtils.fullScreen
 * @description 打开全屏地图
 */
const openFullScreen = () => {
    const el = document.getElementById('container'); // 全局地图容器
    const rfs = el.requestFullScreen ||
        el.webkitRequestFullScreen ||
        el.mozRequestFullScreen ||
        el.msRequestFullScreen;
    if (typeof rfs !== 'undefined' && rfs) {
        rfs.call(el);
    }
};
/**
 * @function SuperMapUtils.fullScreen
 * @description 退出全屏地图
 */
const exitFullScreen = () => {
    const el = document;
    const cfs = el.cancelFullScreen ||
        el.webkitCancelFullScreen ||
        el.mozCancelFullScreen ||
        el.exitFullScreen;
    if (typeof cfs !== 'undefined' && cfs) {
        cfs.call(el);
    }
};
/**
 * @function SuperMapUtils.zoomIn
 * @description 放大地图
 * @param {SuperMapType} instance - 地图对象
 */
const zoomIn = (instance) => {
    switch (instance.instanceType) {
        case 'OpenLayers':
            return OpenLayersUtils.zoomIn(instance);
        case 'Cesium':
            return CesiumUtils.zoomIn(instance);
    }
};
/**
 * @function SuperMapUtils.draw
 * @description 手动绘制
 * @param {SuperMapType} instance - 地图对象
 * @param {DrawingMode} drawingMode - 绘制模式
 * @param {object} options - 绘制配置参数
 * @param {boolean} options.continueDraw - 是否连续绘制 默认：true
 * @param {boolean} options.removeLast - 是否移除上一次绘制的图形 默认：true
 * @param {Function} callback
 */
const draw = (instance, drawingMode, options, callback) => {
    switch (instance.instanceType) {
        case 'OpenLayers':
            return OpenLayersUtils.draw(instance, drawingMode, options, callback);
        case 'Cesium':
            return CesiumUtils.draw(instance, drawingMode, options, callback);
    }
};
/**
 * @function SuperMapUtils.zoomOut
 * @description 缩小地图
 * @param {SuperMapType} instance - 地图对象
 */
const zoomOut = (instance) => {
    switch (instance.instanceType) {
        case 'OpenLayers':
            return OpenLayersUtils.zoomOut(instance);
        case 'Cesium':
            return CesiumUtils.zoomOut(instance);
    }
};
/**
 * @function SuperMapUtils.moveTo
 * @description 地图平移至目标位置
 * @param {SuperMapType} instance - 地图对象
 * @param {[number,number]} lnglat - 坐标
 */
const moveTo = (instance, lnglat) => {
    switch (instance.instanceType) {
        case 'OpenLayers':
            return OpenLayersUtils.moveTo(instance, lnglat);
        case 'Cesium':
            return CesiumUtils.moveTo(instance, lnglat);
    }
};
/**
 * @function SuperMapUtils.measureDistance
 * @description 测量距离
 * @param {OpenLayersMapType} instance
 */
const measureDistance = (instance, options) => {
    switch (instance.instanceType) {
        case 'OpenLayers':
            return OpenLayersUtils.startMeasure(instance, 'LineString');
        case 'Cesium':
            return CesiumUtils.startMeasureDistance(instance, options);
    }
};
/**
 * @function SuperMapUtils.measureArea
 * @description 测量面积
 * @param {OpenLayersMapType} instance
 */
const measureArea = (instance, options) => {
    switch (instance.instanceType) {
        case 'OpenLayers':
            return OpenLayersUtils.startMeasure(instance, 'Polygon');
        case 'Cesium':
            return CesiumUtils.startMeasureArea(instance, options);
    }
};
/**
 * @function SuperMapUtils.addMiniMap
 * @description 创建鹰眼图
 * @param {SuperMapType} instance - 地图对象
 */
const addMiniMap = (instance, options) => {
    switch (instance.instanceType) {
        case 'OpenLayers':
            return OpenLayersUtils.addMiniMap(instance, options);
        case 'Cesium':
            return CesiumUtils.addMiniMap(instance);
    }
};
/**
 * @function SuperMapUtils.startCoordPick
 * @description 坐标拾取
 * @param {SuperMapType} instance - 地图对象
 */
const startCoordPick = (instance) => {
    switch (instance.instanceType) {
        case 'OpenLayers':
            return OpenLayersUtils.startCoordPick(instance);
        case 'Cesium':
            return CesiumUtils.startCoordPick(instance);
    }
};
/**
 * @function SuperMapUtils.changeLayerOpacity
 * @description 调整图层透明度
 * @param {SuperMapType} instance - 地图对象
 * @param {LayerOption[]} option - 服务图层参数
 * @param {number} opacity - 透明度
 */
const changeLayerOpacity = (instance, option, opacity) => {
    switch (instance.instanceType) {
        case 'OpenLayers':
            return OpenLayersUtils.changeLayerOpacity(instance, option, opacity);
        case 'Cesium':
            return CesiumUtils.changeLayerOpacity(instance, option, opacity);
    }
};
/**
 * @function SuperMapUtils.addLayer
 * @description 加载图层
 * @param {SuperMapType} instance - 地图对象
 * @param {LayerOption} option - 图层参数
 */
const addLayer = (instance, option) => {
    switch (instance.instanceType) {
        case 'OpenLayers':
            return OpenLayersUtils.addLayer(instance, option);
        case 'Cesium':
            return CesiumUtils.addLayer(instance, option);
    }
};
/**
 * @function SuperMapUtils.removeLayer
 * @description 去除图层
 * @param {SuperMapType} instance - 地图对象
 * @param {LayerOption} option - 图层参数
 */
const removeLayer = (instance, option) => {
    switch (instance.instanceType) {
        case 'OpenLayers':
            return OpenLayersUtils.removeLayer(instance, option);
        case 'Cesium':
            return CesiumUtils.removeLayer(instance, option);
    }
};
/**
 * @function SuperMapUtils.queryLayerData
 * @description 查询图层数据
 * @param {string} type - 地图类型 OpenLayers|Cesium
 * @param {OpenLayersQueryOption | CesiumQueryOption} option - 查询参数对象 1、url:图层地址 2、type：查询类型  3、查询参数
 */
const queryLayerData = (type, option) => {
    switch (type) {
        case 'OpenLayers':
            return OpenLayersUtils.queryLayerData(option);
        case 'Cesium':
            return CesiumUtils.queryLayerData(option);
    }
};
/**
 * @function SuperMapUtils.setLocateCoordinate
 * @description 坐标定位
 * @param {SuperMapType} instance - 地图对象
 * @param {number[]} coordinate - 坐标数组
 * @param {'Point' | 'Polyline' | 'Polygon'} type - 类型
 */
const setLocateCoordinate = (instance, coordinate, type) => {
    switch (instance.instanceType) {
        case 'OpenLayers':
            return OpenLayersUtils.setLocateCoordinate(instance, coordinate, type);
        case 'Cesium':
            return CesiumUtils.setLocateCoordinate(instance, coordinate, type);
    }
};
/**
 * @function SuperMapUtils.syntaxView
 * @description 视图同步
 * @param {OpenLayersMapType} map - 二维地图
 * @param {CesiumMapType} viewer - 三维地图
 * @param {string} type - 地图类型 OpenLayers|Cesium
 */
const syntaxView = (map, viewer, type) => {
    switch (type) {
        case 'OpenLayers':
            return OpenLayersUtils.syntaxView(map, viewer);
        case 'Cesium':
            return CesiumUtils.syntaxView(map, viewer);
    }
};
/**
 * @function SuperMapUtils.changeLayerSwipe
 * @description 设置卷帘分析
 * @param {SuperMapType} instance - 地图对象
 * @param {string[]} leadingLayerIds - 卷帘左侧/上侧图层id集合
 * @param {string[]} trailingLayerIds - 卷帘右侧/下侧图层id集合
 * @param {'horizontal' | 'vertical'} direction - 卷帘方向: horizontal-水平、vertical-垂直
 * @param {number} [swipeRatio] - 卷帘比例数值 默认值:0.5
 */
const changeLayerSwipe = (instance, leadingLayerIds = [], trailingLayerIds = [], direction = 'horizontal', swipeRatio = 0.5) => {
    switch (instance.instanceType) {
        case 'OpenLayers':
            return OpenLayersUtils.changeLayerSwipe(instance, leadingLayerIds, trailingLayerIds, direction, swipeRatio);
        case 'Cesium':
            return CesiumUtils.changeLayerSwipe(instance, leadingLayerIds, trailingLayerIds, direction, swipeRatio);
    }
};
/**
 * @function SuperMapUtils.screenShot
 * @description 鼠标拖拽区域截图保存下载
 */
const screenShot = () => {
    ScreenShot();
};
/**
 * @function SuperMapUtils.layerClear
 * @description 图层清理
 * @param {SuperMapType} instance - 地图对象
 * @param {string[]} 底图图层ID
 */
const layerClear = (instance, baseLayerIds) => {
    switch (instance.instanceType) {
        case 'OpenLayers':
            OpenLayersUtils.layerClear(instance, baseLayerIds);
            break;
        case 'Cesium':
            CesiumUtils.layerClear(instance);
            break;
    }
};
/**
 * @function SuperMapUtils.clear
 * @description 清除地图
 * @param {OpenLayersMapType} map - 二维地图对象
 * @param {CesiumMapType} viewer - 三维地图对象
 */
const clear = (map, viewer) => {
    map && OpenLayersUtils.clear(map);
    viewer && CesiumUtils.clear(viewer);
};
export { setMapConfig, fullExtent, zoomIn, zoomOut, moveTo, measureDistance, measureArea, addMiniMap, initFullScreen, openFullScreen, exitFullScreen, changeLayerOpacity, startCoordPick, addLayer, removeLayer, queryLayerData, setLocateCoordinate, layerClear, clear, changeLayerSwipe, syntaxView, draw, screenShot };
