var map = new AMap.Map("container", {resizeEnable: true}); var lnglats = [ [116.368904, 39.923423], [116.382122, 39.921176], [116.387271, 39.922501], [116.398258, 39.914600] ]; var infoWindow = new AMap.InfoWindow({offset: new AMap.Pixel(0, -30)}); var markers = [];//标注点信息集合 for (var i = 0, marker; i < lnglats.length; i++) { var marker = new AMap.Marker({ position: lnglats[i], map: map }); marker.content = '我是第' + (i + 1) + '个Marker'; marker.on('click', markerClick); // marker.emit('click', {target: marker}); markers.push(marker); } function markerClick(e) { infoWindow.setContent(e.target.content); infoWindow.open(map, e.target.getPosition()); } map.setFitView(); // 创建覆盖物群组,并将 marker 传给 OverlayGroup var overlayGroups = new AMap.OverlayGroup(markers); //清除标注; function clearMaker() { map.remove(markers) markers = []; } //清除覆盖物; document.getElementById('btn').onclick = function () { clearMaker(); }
lockdatav Done!