import icon1 from './xxxx'
import icon2 from './xxxx'
// 点聚合
switchChange(e) {
if (!e) {
this.state.cluster.setMap(null);
return
}
let that = this
AMap.plugin(["AMap.MarkerClusterer"], function () {
let markerClusterer = new AMap.MarkerClusterer(that.map, []);
for (var i = 0; i < 30; i += 1) {
// 随机生成坐标点
let position = [114.95 + i * Math.random() * 0.05, 27.80 + i * 0.01];
var markera = new AMap.Marker({
position: position,
icon: new AMap.Icon({
size: new AMap.Size(26, 32),
imageSize: new AMap.Size(26, 32),
image: i < 15 ? icon1: icon2,
offset: new AMap.Pixel(-13, -16)
})
})
markera.on("click", function (e) {//给每一个点位增加点击事件
console.log(e, '111')
});
markerClusterer.addMarker(markera);
}
that.setState({
cluster: markerClusterer
})
});
}
11-01
374
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-09
1794
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-21
3322
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)