Home >Web Front-end >JS Tutorial >Amap-Delete multiple point markers

Amap-Delete multiple point markers

黄舟
黄舟Original
2017-02-16 13:55:392036browse

1. Problem background

There are markers created by you on the Gaode map. Click the delete button to delete multiple markers


2. Implementation source code

<!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: 14
		    });
		    
		    AMap.event.addDomListener(document.getElementById(&#39;delMarker&#39;), &#39;click&#39;, 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. Implementation result

(1) During initialization

Amap-Delete multiple point markers


##(2) Click the delete button

Amap-Delete multiple point markers

## The above is the Amap - delete the content marked by multiple points. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn