""" initMap() {
let that = this
this.map.mapObj = uni.createMapContext("map", this);
//仅调用初始化,才会触发 on.("markerClusterCreate", (e) => {})
that.map.mapObj.initMarkerCluster({
enableDefaultStyle: false,
zoomOnClick: true,
gridSize: 10,
complete(res) {
console.log('initMarkerCluster', res)
}
});
console.log("test")
that.map.mapObj.on("markerClusterCreate", (res) => {
let clusterMarkers = []
const clusters = res.clusters // 新产生的聚合簇
clusters.forEach((cluster, index) => {
const {
center, // 聚合点的经纬度数组
clusterId, // 聚合簇id
markerIds // 已经聚合了的标记点id数组
} = cluster
var iconPath = '/static/images/map/blue.png'
if (that.markerHasRed(markerIds)) {
iconPath = '/static/images/map/red.png'
} else if (that.markerHasYellow(markerIds)) {
iconPath = '/static/images/map/yellow-2.png'
}
console.log(center)
console.log(markerIds)
console.log(iconPath)
let clusterObj = {
clusterId, //必须
...center,
width: 30,
height: 30,
iconPath: iconPath,
label: { // 定制聚合簇样式
content: markerIds.length + '',
// aria-label: markerIds.length + '',
fontSize: 11,
width: 40,
height: 20,
color: "#000000",
bgColor: '#ffffff',
borderWidth: 1,
borderColor: "#aaa",
borderRadius: 5,
textAlign: 'center',
anchorX: -21,
anchorY: -50,
// padding:10
}
}
clusterMarkers.push(clusterObj)
})
// 添加聚合簇
that.map.mapObj.addMarkers({
markers: clusterMarkers,
clear: false, //是否先清空地图上所有的marker
complete(res) {
console.log('addMarkers', res)
}
})
});
that.map.mapObj.on('markerClusterClick', (res) => {
console.log("markerClusterClick", res);
})
}, """