參考原文鏈接:https://lbs.amap.com/api/javascript-api/example/map/map-bounds/
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title>地圖顯示范圍</title>
<link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
<style>
html,
body,
#container {
width: 100%;
height: 100%;
}
.lnglat {
color: #0288d1;
}
</style>
</head>
<body>
<div id="container"></div>
<div class="info">
<h4>當前地圖顯示范圍(Bounds)</h4>
<p>NorthEast坐標:<span id="ne" class="lnglat"></span></p>
<p>SouthWest坐標:<span id="sw" class="lnglat"></span></p>
</div>
<div class="input-card" style="width:16rem;">
<h4>控制地圖顯示范圍</h4>
<div class="input-item">
<button class="btn" id="reset-bounds">指定地圖顯示范圍</button>
</div>
</div>
<script src="https://webapi.amap.com/maps?v=1.4.15&key=您申請的key值"></script>
<script src="https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js"></script>
<script>
//創建地圖
var map = new AMap.Map('container', {
resizeEnable: true,
zoom: 10,
center: [116.405285, 39.904989],
showIndoorMap: false
});
//顯示當前地圖邊界范圍坐標
function logMapBounds() {
var bounds = map.getBounds();
document.querySelector("#ne").innerText = bounds.northeast.toString();
document.querySelector("#sw").innerText = bounds.southwest.toString();
}
logMapBounds();
//綁定地圖移動與縮放事件
map.on('moveend', logMapBounds);
map.on('zoomend', logMapBounds);
//綁定按鈕事件
document.querySelector("#reset-bounds").onclick = function() {
//通過 new AMap.Bounds(southWest:LngLat, northEast:LngLat) 或者 map.getBounds() 獲得地圖Bounds信息
var mybounds = new AMap.Bounds([116.319665, 39.855919], [116.468324,39.9756]);
map.setBounds(mybounds);
}
</script>
</body>
</html>