<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<title>Marker 性能</title>
<style type="text/css">/*<![CDATA[*/
body{margin:0;padding:0;font-family:Times New Roman, serif}
p{margin:0;padding:0}
#wrapper{width:100%;margin:auto;text-align:left;height:100%}
#map_container{height:480px;margin:0}
#notes{position:absolute;right:10px;width:200px;top:10px}
@media print{
input{display:none}
#notes{display:none}
#map_container{margin:10px;border:none}
}
/*]]>*/</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?key=25f144bb4491f54b83a7a7b39198c11e&v=1.1&services=true">
</script>
</head>
<body>
<div id="map_container"></div>
<div id="test_container">
<input type="button" onclick="test_mem()" value="mem_test" />
<input type="button" onclick="stop_mem()" value="stop_test" />
</div>
</div>
</body>
<script type="text/javascript">
if (typeof console == "undefined"){
window.console = {
log: function(){
}
}
}
</script>
<script type="text/javascript">
// 创建地图对象并初始化
var mp = new BMap.Map("map_container");
var point = new BMap.Point(116.404, 39.915);
mp.centerAndZoom(point, 14);
// 内存性能测试
var count = 0;
function createInfo() {
mp.clearOverlays();
if (count > 3000) {
clearInterval(window._timer);
alert("测试结束");
}
createMarkers();
}
function createMarkers(){
var bounds = mp.getBounds();
var lngSpan = bounds.maxX - bounds.minX;
var latSpan = bounds.maxY - bounds.minY;
for (var i = 0; i < 9; i ++) {
count ++;
var point = new BMap.Point(bounds.minX + lngSpan * (Math.random() * 0.7 + 0.15),
bounds.minY + latSpan * (Math.random() * 0.7 + 0.15));
var marker = new BMap.Marker(point);
mp.addOverlay(marker);
}
}
function test_mem() {
window._timer = setInterval(createInfo, 1);
}
function stop_mem() {
clearInterval(window._timer);
alert("运行了"+count+"次");
}
</script>
</html>