高德地圖-刪除多個點標記
阿新 • • 發佈:2019-02-13
amp 標記 attr ber class lse head zoom 1.0
1、問題背景
高德地圖上有自己創建的marker,單擊刪除按鈕,可以刪除多個標記
2、實現源碼
<!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>
<div id="container"></div>
<div class="button-group">
<input type="button" class="button" value="刪除" id="delMarker"/>
</div>
<script>
var map = new AMap.Map("container", {
resizeEnable: true,
center : [114.20495,30.407079],
zoom: 14
});
AMap.event.addDomListener(document.getElementById(‘delMarker‘), ‘click‘, function() {
map.remove(markers);
}, 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,
position: positions[i]
});
markers.push(marker);
}
</script>
</body>
</html>
3、實現結果
(1)初始化時
再分享一下我老師大神的人工智能教程吧。零基礎!通俗易懂!風趣幽默!還帶黃段子!希望你也加入到我們人工智能的隊伍中來!https://blog.csdn.net/jiangjunshow
高德地圖-刪除多個點標記