1. 如下圖所示,定位到了四邊形
1. 第一種方法:flyToBounds
var polygon = new L.Rectangle(L.latLngBounds([
[39.9031855750273, 116.39760275470988],
[39.88132436586913, 116.36142920205131]
]), {
weight: 5,
draggable: true,
transform: true,
color: 'blue',
fillColor: "transport",
fillOpacity: 0,
}).addTo(map);
//polygon.getBounds(),獲取經緯度邊界,flyToBounds飛入到多邊形
map.flyToBounds(polygon.getBounds());
2. 第二種方法: setView
//點位
var position= [centerY, centerX];
//把map定位到點位上,13爲地圖的級別,也可以直接marker.getLatLng()
map.setView(position, 13);
3. 第三種方法:fitBounds
var corner1 = L.latLng(maxLat, minLng) // 左上角經緯度
var corner2 = L.latLng(minLat, maxLng) // 右上角經緯度
var bounds = L.latLngBounds(corner1, corner2)
//定位到矩形
map.fitBounds(bounds);