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
})
});
}
react 高德地图点聚合 自定义icon
最新推荐文章于 2025-05-10 14:28:56 发布