/*
 * @Author: 方泽鹏 1658702527@qq.com
 * @Date: 2023-06-26 09:40:46
 * @LastEditors: 方泽鹏 1658702527@qq.com
 * @LastEditTime: 2023-08-30 10:15:00
 * @FilePath: \xmgissupermaptemplate\src\modules\utils\Projection.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { get, Projection } from 'ol/proj';
import { register } from 'ol/proj/proj4';
import proj4 from 'proj4';
const registerOLProjection = (projOption) => {
    if (projOption.proj4Str) {
        proj4.defs(projOption.code, projOption.proj4Str);
        register(proj4);
        const projection = new Projection({
            code: projOption.code,
            extent: projOption.extent,
            worldExtent: projOption.worldExtent,
            units: projOption.unit
        });
        return projection;
    }
};
export const getProjection = (epsg) => {
    let projection;
    switch (epsg) {
        case 'EPSG:4326':
            projection = get('EPSG:4326');
            break;
        case 'EPSG:4490':
            projection = registerOLProjection({
                code: 'EPSG:4490',
                proj4Str: '+proj=longlat +ellps=GRS80 +no_defs',
                extent: [-180, -90, 180, 90],
                worldExtent: [-180, -90, 180, 90],
                unit: 'degrees'
            });
            break;
        case 'EPSG:4523':
            projection = registerOLProjection({
                code: 'EPSG:4523',
                proj4Str: '+proj=tmerc +lat_0=0 +lon_0=105 +k=1 +x_0=35500000 +y_0=0 +ellps=GRS80 +units=m +no_defs ',
                extent: [25345643.07, 2489940.65, 55623868.1, 4676052.19],
                worldExtent: [35345643.07, 2489940.65, 35623868.1, 4676052.19],
                unit: 'm'
            });
            break;
        case 'EPSG:4548':
            projection = registerOLProjection({
                code: 'EPSG:4548',
                proj4Str: '+proj=tmerc +lat_0=0 +lon_0=117 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs ',
                unit: 'm'
            });
            break;
        default:
            projection = get('EPSG:3857');
            break;
    }
    return projection;
};
