高德地图设置地图的显示范围

2021-06-08 21:30:05 浏览数 (1)

代码语言:javascript复制
<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title></title>
	<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.11&key=key值"></script>
	<style type="text/css">
		*{margin: 0;padding: 0;}
		#container{width: 100%;height: 100%;position: absolute;left: 0;top: 0;}
	    #setZoomNode,#setCenterNode{width: 400px;height: 100px;position: absolute;z-index: 99;right: 20px;top: 20px;border: 1px solid black;box-shadow: 0 0 5px black;background: white;}
	    #setCenterNode{top: 20px;}
	</style>
</head>
<body>
		<div id="container"></div>
		<div id='setCenterNode'>
		    <div>地图的右上角坐标:<span id='ne'></span></div>
		    <div>地图的左下角坐标:<span id='sw'></span></div>
		</div>
		<script>
			var map=new AMap.Map('container',{
				zoom:11,
				center:[116.379391,39.861536]
			});
			console.log(map.getBounds());
			var myBounds=new AMap.Bounds([88.379391,20.861536],[117.379391,41.861536]);
			map.setBounds(myBounds);
			 map.on('moveend',function(){
				 ne.innerHTML=map.getBounds().northeast.toString();
				 sw.innerHTML=map.getBounds().southwest.toString();
			});
			map.on('zoomend',function(){
			    ne.innerHTML = map.getBounds().northeast.toString();
			    sw.innerHTML = map.getBounds().southwest.toString();
			    
			});
			
		</script>
</body>
</html>

怎么设置地图的显示范围?

0 人点赞