Leaflet 部分 API 笔记

426 阅读1分钟

获取当前视窗中心点的坐标

map.getCenter()

map 请自行查阅文档如何声明 leafletjs.com/

获取当前视窗四个角的坐标

// 左上角 西北方
const northWest = {
    x: map.getBounds().getNorthWest().lng,
    y: map.getBounds().getNorthWest().lat
}
// 右上角 东北方
const northEast = {
    x: map.getBounds().getNorthEast().lng,
    y: map.getBounds().getNorthEast().lat
}
// 左下角 西南方
const southWest = {
    x: map.getBounds().getSouthWest().lng,
    y: map.getBounds().getSouthWest().lat
}
// 右下角:东南方
const southEast = {
    x: map.getBounds().getSouthEast().lng,
    y: map.getBounds().getSouthEast().lat
}

获取当前地图级别

map.getZoom()