高德地图-删除多个点标记

1、问题背景

     高德地图上有自己创建的marker,单击删除按钮,可以删除多个标记


2、实现源码

[html]  view plain  copy
 print ?
  1. >  
  2. <html>  
  3.     <head>  
  4.         <meta charset="UTF-8">  
  5.         <meta http-equiv="X-UA-Compatible" content="IE=edge">  
  6.         <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">  
  7.         <title>高德地图-删除多个点标记title>  
  8.         <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>  
  9.         <script src="http://webapi.amap.com/maps?v=1.3&key=您申请的key值">script>  
  10.         <script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js">script>  
  11.     head>  
  12.     <body>  
  13.         <div id="container">div>  
  14.         <div class="button-group">  
  15.             <input type="button" class="button" value="删除" id="delMarker"/>  
  16.         div>  
  17.         <script>  
  18.             var map = new AMap.Map("container", {  
  19.                 resizeEnable: true,  
  20.                 center: [114.20495,30.407079],  
  21.                 zoom: 14  
  22.             });  
  23.               
  24.             AMap.event.addDomListener(document.getElementById('delMarker'), 'click', function() {  
  25.                 map.remove(markers);  
  26.             }, false);  
  27.           
  28.             var markers = [],   
  29.                 positions = [  
  30.                     [114.195423,30.405821],   
  31.                     [114.203662,30.404636],   
  32.                     [114.220828,30.404784],   
  33.                     [114.222202,30.393976],   
  34.                     [114.201431,30.392051],  
  35.                     [114.193448,30.413149],  
  36.                     [114.220657,30.414777],  
  37.                     [114.205379,30.414629],  
  38.                     [114.202976,30.398492],  
  39.                     [114.208812,30.400121]  
  40.                 ];  
  41.             for(var i = 0, marker; i < positions.length; i++)  
  42.             {  
  43.                 marker = new AMap.Marker({  
  44.                     map: map,  
  45.                     position: positions[i]  
  46.                 });  
  47.                 markers.push(marker);  
  48.             }  
  49.         script>  
  50.     body>  
  51. html>  

3、实现结果

(1)初始化时

高德地图-删除多个点标记_第1张图片

(2)点击删除按钮


高德地图-删除多个点标记_第2张图片

你可能感兴趣的:(jquery,js)