javascript高德地图实现点击marker消失marker
var markers = [];
var positions = [[120.17718, 30.21772], [120.17718, 30.21872]];
for (var i = 0, marker; i < positions.length; i++) {
marker = new AMap.Marker({
map: map,
icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
position: positions[i],
content: '
' //自定义点标记覆盖物内容
});
markers.push(marker);
}
$.each(markers, function (k, v) {
markers[k].on('click', function () {
if ( markers[k]) {
markers[k].setMap(null);
markers[k] = null;
}
/* var str2 = {"personid":
, "type": 1, "shuzhi": 10, "tag": 3};
str2 = JSON.stringify(str2);
ws.send(str2);*/
});
})
ps:原理就是 先循环遍历marker 显示并且添加到markers数组 然后循环遍历markers数组添加事件就好了
查看原文:http://newmiracle.cn/?p=1497