map.plugin(["AMap.MarkerClusterer"], function() {
cluster = new AMap.MarkerClusterer(
map, // 地图实例
markers, // 海量点组成的数组
{
styles: styles
}
);
cluster.on("click",({cluster,lnglat,target,marker})=>{
lnglatData = lnglat
})
});
完整代码
loadmap(map, data, icon) {
let _self = this;
var map = new AMap.Map(map, {
zoom: 5,
center: [106.143065, 33.058826],
resizeEnable: true
});
var that = this;
map.setMapStyle("amap://styles/darkblue");
map.on("complete", function() {
that.isshow = false;
});
var cluster;
var markers = [];
for (var i = 0; i < data.length; i++) {
var marker = new AMap.Marker({
icon: icon,
position: [data[i].lng, data[i].lat],
// title: data[i].name
});
marker.on("click",({lnglat})=>{
console.log("点击单个点")
})
markers.push(marker);
}
var styles = [
{
url: icon,
size: new AMap.Size(40, 84),
offset: new AMap.Pixel(-40, -84),
textColor: "#fff",
}
];
// 监听地图缩放等级和聚合点数据
var lnglatData = {}
var getZoom = ""
map.plugin(["AMap.MarkerClusterer"], function() {
cluster = new AMap.MarkerClusterer(
map, // 地图实例
markers, // 海量点组成的数组
{
styles: styles
}
);
cluster.on("click",({cluster,lnglat,target,marker})=>{
console.log("点击聚合")
})
});
},
loadmap(容器ID, 数据源, 图标);