首頁  >  文章  >  web前端  >  高德地圖-刪除多個指定點標記

高德地圖-刪除多個指定點標記

黄舟
黄舟原創
2017-02-16 13:51:292261瀏覽

1、問題背景

     高德地圖上標記多個標記,點選刪除按鈕,可以刪除指定的幾個點標記


<!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="http://cache.amap.com/lbs/static/main1119.css"/>
	    <script src="http://webapi.amap.com/maps?v=1.3&key=您申请的key值"></script>
	    <script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
	</head>
	<body>
		<p id="container"></p>
		<p class="button-group">
		    <input type="button" class="button" value="删除" id="delMarker"/>
		</p>
		<script>
		    var map = new AMap.Map("container", {
		        resizeEnable: true,
		        center: [114.20495,30.407079],
		        zoom: 13
		    });
		    
		    AMap.event.addDomListener(document.getElementById(&#39;delMarker&#39;), &#39;click&#39;, function() {
		        markers[1].setMap(null);
		        markers[3].setMap(null);
		        markers[5].setMap(null);
		        markers[7].setMap(null);
		        markers[9].setMap(null);
		    }, false);
		    var markers = [], 
		    	positions = [
		            [114.195423,30.405821], 
		            [114.203662,30.404636], 
		            [114.220828,30.404784], 
		            [114.222202,30.393976], 
		            [114.201431,30.392051],
		            [114.193448,30.413149],
		            [114.220657,30.414777],
		            [114.205379,30.414629],
		            [114.202976,30.398492],
		            [114.208812,30.400121]
		        ];
		    for (var i = 0, marker; i < positions.length; i++) 
		    {
		        marker = new AMap.Marker({
		            map: map,
		            icon: &#39;http://webapi.amap.com/theme/v1.3/markers/n/mark_b&#39;+(i+1)+&#39;.png&#39;,
		            position: positions[i]
		        });
		        markers.push(marker);
		    }
		</script>
	</body>
</html>

3、實現結果

(1)初始化時


(2)點擊刪除按鈕

高德地圖-刪除多個指定點標記

 以上就是高德地圖-刪除多個指定點標記 的內容,更多相關內容請關注PHP中文網(www.php.cn)! 高德地圖-刪除多個指定點標記

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn