功能描述
经纬度座标是一个一个从后台取出,加载在地图上,确保所有点都在屏幕之内
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>动态将所有点放在最佳视野方位内</title>
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<script type="text/javascript" src="jquery-1.7.1.min.js" ></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4"></script>
</head>
<body style="padding: 0; background: #f7f7f7;">
动态将所有点放在最佳视野方位内(每隔3秒新增一个点)
<!--百度地图容器-->
<div style="width:500px;height:560px;" id="allmap"></div>
</div>
<script type="text/javascript">
var map = new BMap.Map("allmap"); // 创建Map实例
map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
map.enableScrollWheelZoom(); //启用滚轮放大缩小,默认禁用
map.enableContinuousZoom(); //启用地图惯性拖拽,默认禁用
var pointsView = []; //存放点的数组
window.setInterval(createPt, 3 * 1000); //设置动态加点,3秒一次
function createPt() {
var pt = new BMap.Point(Math.random()*40 + 85, Math.random() * 30 + 21);
pointsView.push(pt);
var marker = new BMap.Marker(pt);
map.addOverlay(marker);
map.setViewport(pointsView); //将所有的点放置在最佳视野内
}
</script>
</body>
</html>