// 投影实例
const projection = map.getMapType().getProjection()
// 地图div宽高
const box = map.getSize()
const zoom = window.Math.pow(2, 18 - map.getZoom())
// 中心坐标 转 平面坐标
const center = projection.lngLatToPoint(map.getCenter())
// 测试坐标 转 平面坐标
const point = projection.lngLatToPoint({ lng: 118.816832, lat: 31.981216 })
// 像素坐标
const x = Math.round((point.x - center.x) / zoom + box.width / 2)
const y = Math.round((center.y - point.y) / zoom + box.height / 2)
// 测试下 与pointToPixel转换是相同的
const pixel = map.pointToPixel({ lng: 118.816832, lat: 31.981216 })
console.log(pixel, x, y)
经纬度 => 墨卡托投影坐标 => 相对中心投影坐标 => 根据地图缩放级别调整 => 最后加上地图窗口宽高