1.在地图上点击画标注,点Clear按钮清空所有点
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text ml; charset=utf-8" />
<title>SOSOMap</title>
<script charset="utf-8" src="http://api.map.soso.com/v1.0/main.js"></script>
<script>
var poly;
var map;
var markersArray=[];
function initialize() {
var chicago = new soso.maps.LatLng(39.916527,116.397128);
var mapOptions = {
zoomLevel: 7,
center: chicago,
mapTypeId: soso.maps.MapTypeId.ROADMAP
};
map = new soso.maps.Map(document.getElementById('map_canvas'), mapOptions);
var polyOptions = {
strokeColor: '#000000',
strokeOpacity: 1.0,
strokeWeight: 3
}
poly = new soso.maps.Polyline(polyOptions);
soso.maps.Event.addListener(map, 'click', addLatLng);
}
function addLatLng(event){
poly.setMap(map); //设置地图折线容器
var path = poly.getPath();//获取折线坐标
path.push(event.latLng);
poly.setPath(path) //设置折线坐标
var marker = new soso.maps.Marker({
position: event.latLng,
map: map
});
markersArray.push(marker);
}
//清除线和Marker
function ClearMarker(){
if(poly==null){
return;
}
else{
poly.setPath([]); //清空线的缓存
poly.setMap(null);//清空画线
if (markersArray){
for(i in markersArray) {
markersArray[i].setMap(null);//清空标注
}
markersArray.length = 0;
}
}
}
</script>
</head>
<body οnlοad="initialize()">
<div style="width:603px;height:300px" id="map_canvas"></div>
<button οnclick="ClearMarker()">Clear</button>
</body>
<html>