<!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="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
<style>
html, body, #container {
height: 100%;
width: 100%;
}
.amap-icon img {
width: 25px;
height: 34px;
}
</style>
</head>
<body>
<div id="container"></div>
<div class="input-card">
<h4>删除指定点</h4>
<input id="clearMarker" type="button" class="btn" onclick="clearMarker()" value="从多个点中删除指定点"/>
</div>
<script type="text/javascript"
src="https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值"></script>
<script type="text/javascript">
var map = new AMap.Map("container", {
resizeEnable: true,
center: [116.397428, 39.90923],
zoom: 13
});
// 清除指定点
function clearMarker() {
markers[0].setMap(null);
markers[2].setMap(null);
}
var markers = [];
var positions = [[116.405467, 39.907761], [116.415467, 39.907761], [116.415467, 39.917761], [116.425467,
39.907761], [116.385467, 39.907761]];
for (var i = 0, marker; i < positions.length; i++) {
marker = new AMap.Marker({
map: map,
icon: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-' + (i + 1) + '.png',
position: positions[i]
});
markers.push(marker);
}
</script>
</body>
</html>
订阅评论
0 评论