tg-map-vue3
Version:
封装 百度地图, Google地图, Here地图(未完成) 的Vue3组件库
158 lines (157 loc) • 5.87 kB
TypeScript
import { type LngLatTuple } from 'coordtransform';
import { type StringEnumValue } from '../utils/mapped-types';
export declare enum CoordType {
wgs84 = "wgs84",
gcj02 = "gcj02",
bd09 = "bd09"
}
export interface CoordTypeSupplier {
readonly coordType: CoordType;
}
export interface LatLngLiteral {
readonly lat: number;
readonly lng: number;
readonly coord?: CoordType;
}
export interface WeightedLatLng {
position: LatLng;
weight: number;
}
export declare class LatLng {
/**
* 纬度, 分南北, [-90, 90], 0点为赤道
*/
readonly lat: number;
/**
* 经度, 分东西, [-180, 180], 0点为本初子午线
*/
readonly lng: number;
/** 坐标系 */
readonly coord: CoordType;
static ZERO: LatLng;
/**
* {@template latlng_normalize}
*
* 对经纬度进行标准化, 参考google的实现
*
* ## 行为不一致
* - google: google.maps.LatLng的构造器会对经纬度进行标准化, 所有点都能正常显示
* - baidu: BMap.Point的构造器不会对经纬度进行标准化, 超出范围的点显示到(0, 0)位置
*
* {@endtemplate}
*/
static _normalize(lng: number, lat: number): number[];
/** @param coord Baidu Map的坐标一般都是bd09 */
static fromBaidu(point: BMap.Point, coord: CoordType): LatLng;
/** @param coord Google Map的坐标依据地图类型不同是不一样的 */
static fromGoogle(latlng: google.maps.LatLng, coord: CoordType): LatLng;
static fromHere(point: H.geo.IPoint, coord: CoordType): LatLng;
static fromLiteral(latlng: LatLngLiteral): LatLng;
static fromLngLat(lng: number, lat: number, coord?: CoordType): LatLng;
static create(lat: number, lng: number, coord?: CoordType): LatLng;
constructor(
/**
* 纬度, 分南北, [-90, 90], 0点为赤道
*/
lat: number,
/**
* 经度, 分东西, [-180, 180], 0点为本初子午线
*/
lng: number,
/** 坐标系 */
coord: CoordType);
/** 转换坐标到指定坐标系 */
to(coordType: StringEnumValue<typeof CoordType>): LatLng;
/**
* TODO: normalize要不要默认设为true, 和google的行为保持一致?
* 转换成baidu的经纬度
* @param normalize 转换时是否进行标准化, 默认false
* @see _normalize {@macro latlng_normalize}
*/
toBaidu(coord: CoordType, normalize?: boolean): BMap.Point;
/**
* 转换成google的经纬度, 内部会自动进行标准化
* @see _normalize {@macro latlng_normalize}
*/
toGoogle(coord: CoordType): google.maps.LatLng;
toHere(coord: CoordType): H.geo.Point;
/**
* 该方法之所以设计的这么不友好, 是为了防止不必要的开销(大概有点影响😅)
*
* 私有方法, 外部需要转换坐标系, 请使用{@link to}/toBaidu/Google/Here, 之所以不添加private关键字, 是因为设成私有后, 有的地方会报类型错误...
*
* @returns `[lng, lat]` 注意不要取错顺序
* @throws 若当前coord和targetCoord相同, 会抛异常, 故请在外部判断
*/
_convert(targetCoord: CoordType): LngLatTuple;
/**
* 标准化, 返回合法的坐标点
* @see _normalize {@macro latlng_normalize}
*/
normalize(): LatLng;
equals(other: LatLng): boolean;
toString(): string;
}
/** 少数接口同时支持对象形式和字面量形式 */
export type LatLngType = LatLng | LatLngLiteral;
/**
* 反编译自{@link com.google.android.gms.maps.model.LatLngBounds}
*/
export declare class LatLngBounds {
sw: LatLng;
ne: LatLng;
static EMPTY: LatLngBounds;
static isBetweenLng(minLng: number, maxLng: number, lng: number): boolean;
/**
* 从数组创建bounds
*
* 只有{@link positions}为空时, 才会返回`undefined`, 可以借助{@link Arrays.isNotEmpty}协助进行类型推断
*/
static fromArray(positions: readonly []): undefined;
/** @see Arrays.isNotEmpty */
static fromArray(positions: readonly [LatLng, ...LatLng[]]): LatLngBounds;
static fromArray(positions: readonly LatLng[]): LatLngBounds | undefined;
static from(...positions: LatLng[]): LatLngBounds;
static fromGoogle(bounds: google.maps.LatLngBounds, coord: CoordType): LatLngBounds;
static fromBaidu(bounds: BMap.Bounds, coord: CoordType): LatLngBounds;
static create(sw: LatLng, ne: LatLng): LatLngBounds;
coord: CoordType;
/**
* 不推荐直接创建LatLngBounds, sw和ne的大小关系可能没法保证, 推荐用LatLngBounds.Builder或者LatLngBounds.from等静态方法来创建
* @param sw 西南, lat/lng更小
* @param ne 东北, lat/lng更大
*/
constructor(sw: LatLng, ne: LatLng);
isEmpty(): boolean;
contains(position: LatLng): boolean;
getCenter(): LatLng;
toString(): string;
equals(other: LatLngBounds): boolean;
/**
* 矩形的四个点数组
* 顺时针: sw(西南) -> nw(西北) -> ne(东北) -> se(东南)
* */
toRectArray(): LatLng[];
toGoogle(coord: CoordType): google.maps.LatLngBounds;
toBaidu(coord: CoordType): BMap.Bounds;
toBaiduArray(coord: CoordType): BMap.Point[];
}
export declare namespace LatLngBounds {
class Builder {
private coord;
private minLat;
private minLng;
private maxLat;
private maxLng;
constructor(start: LatLng);
build(): LatLngBounds;
include(position: LatLng): this;
private delta;
}
}
/** 在导航/搜索等接口中使用的 位置 */
export type Location = string | LatLng;
export declare namespace Location {
function toString(place: Location | undefined, coordType: CoordType): string | undefined;
function getCoordType(place: Location | undefined): CoordType | undefined;
}