Skip to content

mxcad_2d API 文档 / mapbox / MxMap

Class: MxMap

mapbox.MxMap

Mapbox 地图与 CAD 坐标系统桥接类,用于将地图坐标和 CAD 绘图坐标相互转换。

Description

MxMap 是一个用于连接 Mapbox 地图和 MxCAD/AutoCAD 坐标体系的桥接对象,主要用于在地理地图场景中与 CAD 图纸协同工作。 它能够完成:

  • 绑定 Mapbox map 实例;
  • 在经纬度、墨卡托坐标和 CAD 坐标之间进行转换;
  • 处理地图缩放和 CAD 坐标系的对齐;
  • 通过 create() 方法生成地图自定义图层并接入 CAD 渲染环境;
  • 适配旧版和新版地图创建方式。

使用方式:

  1. 实例化 MxMap,并可选择传入已有的 McObject;
  2. 调用 setCoordinatePointAlignment() 设置地图原点和 CAD 原点关系;
  3. 通过 initMapbox() 绑定 mapbox 实例;
  4. 调用 create(map, config) 启动地图与 CAD 的集成渲染;
  5. 使用 lnglatToCAD()、mercatorCoord2CAD() 等方法执行坐标转换。

总结:MxMap 是连接地图地理坐标与 CAD 绘图坐标的核心工具,适合做地理信息、地图定位、测绘数据与工程图协同展示场景。

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new MxMap(inMxcad?)

Parameters

NameType
inMxcad?McObject

Properties

mxcad

mxcad: McObject

mxcad对象

Methods

cadLongToMercatorCoord

cadLongToMercatorCoord(len): number

将经度坐标转换为墨卡托投影下的坐标

Parameters

NameTypeDescription
lennumber经度

Returns

number

墨卡托投影下的坐标


cadToMercatorCoord

cadToMercatorCoord(pt): Vector3

cad到mapbox的墨卡托坐标系

Parameters

NameTypeDescription
ptVector3三维点对象

Returns

Vector3

三维点对象


cadTolnglat

cadTolnglat(pt): number[]

cad坐标转换为经度和纬度

Parameters

NameTypeDescription
ptVector3三维点对象

Returns

number[]

经纬度


create

create(map, config): Promise<void>

创建地图

Parameters

NameTypeDescription
mapanymap对象
configany-

Returns

Promise<void>


getMapbox

getMapbox(): any

获取mapbox的map对象

Returns

any

map对象


getMxDrawObject

getMxDrawObject(): MxDrawObject

获取当前mxdraw对象

Returns

MxDrawObject

mxdraw对象


initMapbox

initMapbox(map): void

初始化mapbox

Parameters

NameTypeDescription
mapanymap对象

Returns

void


lnglatToCAD

lnglatToCAD(lng, lat): Vector3

经纬度到cad坐标

Parameters

NameTypeDescription
lngnumber经度
latnumber纬度

Returns

Vector3

三维点对象


lnglat_to_mercator

lnglat_to_mercator(lng, lat): Vector3

经纬度到mapbox的墨卡托坐标系坐标

Parameters

NameTypeDescription
lngnumber经度
latnumber维度

Returns

Vector3

三维点对象


map_lnglat_to_meters

map_lnglat_to_meters(lng, lat): number[]

将地理坐标系下的坐标(经度和纬度)转换为平面坐标系下的坐标(米)

Parameters

NameTypeDescription
lngnumber经度
latnumber维度

Returns

number[]

平面坐标


map_meters_to_lnglat

map_meters_to_lnglat(x, y): number[]

地图墨卡托坐标系到经纬度

Parameters

NameTypeDescription
xnumberX轴坐标
ynumberY轴坐标

Returns

number[]

经纬度


mercatorCoord2CAD

mercatorCoord2CAD(x, y): Vector3

mapbox的墨卡托坐标系到cad

Parameters

NameTypeDescription
xnumberX轴坐标
ynumberY轴坐标

Returns

Vector3

三维点对象


mercatorCoordToCAD

mercatorCoordToCAD(x, y): Vector3

mapbox的墨卡托坐标系到cad

Parameters

NameTypeDescription
xnumberX轴坐标
ynumberY轴坐标

Returns

Vector3

三维点对象


mercator_to_lnglat

mercator_to_lnglat(x, y, z): number[]

mapbox的墨卡托坐标系到经纬度

Parameters

NameTypeDescription
xnumberX轴坐标
ynumberY轴坐标
znumberZ轴坐标

Returns

number[]

经纬度


outOfChina

outOfChina(lng, lat): boolean

是否超出中国范围

Parameters

NameTypeDescription
lngnumber经度
latnumber维度

Returns

boolean

布尔值


setCoordinatePointAlignment

setCoordinatePointAlignment(originLngLatLike, originCAD, meterInCADUnits): void

设置坐标点的对齐方式

Parameters

NameTypeDescription
originLngLatLikenumber[]经度和纬度的原点坐标
originCADnumber[]绘图坐标系下的起始点,即AutoCAD 中的原点坐标。
meterInCADUnitsnumber地理坐标系和 AutoCAD 绘图使用的坐标单位转换

Returns

void


setLoadOldEditionMethod

setLoadOldEditionMethod(): void

用于设置加载旧版本地图

Returns

void