/** * @file 地理坐标转换工具 * @description * 提供高性能、高精度的坐标系统转换功能,支持: * - WGS84(GPS全球卫星定位系统) * - GCJ02(国测局火星坐标系) * - BD09(百度坐标系) * * 特性: * - 高性能:采用函数式编程范式,优化计算性能 * - 高精度:使用迭代逼近算法,确保转换精度 * - 类型安全:完整的 TypeScript 类型定义 * - 多格式支持:兼容多种坐标输入/输出格式 */ /** * 标准坐标点接口 * @interface Coordinate * @property {number} longitude - 经度,范围:[-180, 180] * @property {number} latitude - 纬度,范围:[-90, 90] */ type Coordinate = { longitude: number; latitude: number; }; /** * 坐标系统枚举 * @enum {string} */ declare enum CoordSystem { /** 全球卫星定位系统坐标,国际标准 */ WGS84 = "WGS84", /** 国测局02坐标系,中国国家标准,在WGS84基础上加密 */ GCJ02 = "GCJ02", /** 百度坐标系,在GCJ02基础上进行进一步偏移 */ BD09 = "BD09" } /** * 坐标点元组类型 [经度, 纬度] * @typedef {[number, number]} Point */ export type Point = [number, number]; /** * 通用经纬度对象类型 * @interface LatLng * @property {number} lat - 纬度 * @property {number} lng - 经度 */ export type LatLng = { lat: number; lng: number; }; /** * 边界框类型定义 * @interface BoundingBox * @property {number} minLat - 最小纬度 * @property {number} maxLat - 最大纬度 * @property {number} minLng - 最小经度 * @property {number} maxLng - 最大经度 */ export type BoundingBox = { minLat: number; maxLat: number; minLng: number; maxLng: number; }; /** * 坐标转换器类 * 采用单例模式,确保全局唯一实例 * * @class CoordinateTransformer * @example * ```typescript * // 基础使用 * const result = transform([116.404, 39.915], CoordSystem.WGS84, CoordSystem.GCJ02); * * // 批量转换 * const points = batchTransform(coordinates, CoordSystem.WGS84, CoordSystem.BD09); * * // 计算距离 * const distance = getDistance(point1, point2, CoordSystem.GCJ02); * ``` */ declare class CoordinateTransformer { private static instance; private constructor(); /** * 获取单例实例 */ static getInstance(): CoordinateTransformer; /** * 统一坐标转换入口 * 支持多种输入格式,自动进行标准化处理 * * @param {Coordinate | Point | LatLng} coord - 源坐标 * @param {CoordSystem} from - 源坐标系 * @param {CoordSystem} to - 目标坐标系 * @returns {Coordinate} 转换后的标准坐标对象 * @throws {CoordinateError} 当输入坐标无效时抛出错误 * * @example * ```typescript * // 支持多种输入格式 * transform([116.404, 39.915], CoordSystem.WGS84, CoordSystem.GCJ02); * transform({ lat: 39.915, lng: 116.404 }, CoordSystem.WGS84, CoordSystem.GCJ02); * transform({ latitude: 39.915, longitude: 116.404 }, CoordSystem.WGS84, CoordSystem.GCJ02); * ``` */ transform(coord: Coordinate | Point | LatLng, from: CoordSystem, to: CoordSystem): Coordinate; /** * 标准化不同格式的坐标输入 */ private normalizeCoordinate; /** * 将任意坐标系转换为WGS84 */ private toWGS84; /** * 将WGS84转换为目标坐标系 */ private fromWGS84; /** * GCJ02 转 WGS84 */ private gcj02ToWGS84; /** * WGS84 转 GCJ02 */ private wgs84ToGCJ02; /** * BD09 转 GCJ02 */ private bd09ToGCJ02; /** * GCJ02 转 BD09 */ private gcj02ToBD09; private isOutOfChina; private calculateOffset; private transformLng; private transformLat; private validateCoordinate; private roundCoordinate; private cloneCoordinate; /** * 批量转换坐标点 * @param coords - 坐标点数组 * @param from - 源坐标系 * @param to - 目标坐标系 */ batchTransform(coords: Coordinate[], from: CoordSystem, to: CoordSystem): Coordinate[]; /** * 计算两点之间的大圆距离 * 使用 Haversine 公式计算地球表面两点间的最短距离 * * @param {Coordinate} coord1 - 第一个坐标点 * @param {Coordinate} coord2 - 第二个坐标点 * @param {CoordSystem} [system=CoordSystem.WGS84] - 坐标系统 * @returns {number} 距离,单位:米 * * @example * ```typescript * const distance = getDistance( * { longitude: 116.404, latitude: 39.915 }, * { longitude: 116.405, latitude: 39.916 }, * CoordSystem.GCJ02 * ); * ``` */ getDistance(coord1: Coordinate, coord2: Coordinate, system?: CoordSystem): number; /** * 检查点是否在多边形内 * @param point - 待检查的点 * @param polygon - 多边形的顶点数组 * @param system - 坐标系统 */ isPointInPolygon(point: Coordinate, polygon: Coordinate[], system?: CoordSystem): boolean; /** * 计算多边形面积(平方米) * @param polygon - 多边形顶点数组 * @param system - 坐标系统 */ calculatePolygonArea(polygon: Coordinate[], system?: CoordSystem): number; /** * 获取坐标点的偏移坐标 * @param coord - 原始坐标 * @param distance - 偏移距离(米) * @param bearing - 方位角(度) * @param system - 坐标系统 */ getOffsetCoordinate(coord: Coordinate, distance: number, bearing: number, system?: CoordSystem): Coordinate; /** * 转换为指定格式输出 */ toPoint(coord: Coordinate): Point; toLatLng(coord: Coordinate): LatLng; } export declare const transformer: CoordinateTransformer; export { CoordSystem, type Coordinate }; export declare const transform: (coord: Coordinate | Point | LatLng, from: CoordSystem, to: CoordSystem) => Coordinate; export declare const getDistance: (coord1: Coordinate, coord2: Coordinate, system?: CoordSystem) => number; export declare const isPointInPolygon: (point: Coordinate, polygon: Coordinate[], system?: CoordSystem) => boolean; export declare const calculatePolygonArea: (polygon: Coordinate[], system?: CoordSystem) => number; export declare const getOffsetCoordinate: (coord: Coordinate, distance: number, bearing: number, system?: CoordSystem) => Coordinate; export declare const toGCJ02: (coord: Coordinate | Point | LatLng) => Coordinate; export declare const toBD09: (coord: Coordinate | Point | LatLng) => Coordinate; export declare const toWGS84: (coord: Coordinate | Point | LatLng, from: CoordSystem) => Coordinate; export declare const toPoint: (coord: Coordinate) => Point; export declare const toLatLng: (coord: Coordinate) => LatLng; export declare class CoordinateError extends Error { constructor(message: string); } export declare const EARTH_RADIUS = 6371000; export declare const DEGREES_TO_RADIANS: number; export declare const RADIANS_TO_DEGREES: number; export declare const createBoundingBox: (coords: Coordinate[]) => BoundingBox; //# sourceMappingURL=index.d.ts.map