pointClusterLayer = new T.MarkerClusterer(map, { markers: pointMarkerArr });
pointClusterLayer.addEventListener("click", () => {
console.log("点击聚合点")
});
console.log("聚合点", pointClusterLayer);
pointClusterLayer.addEventListener("clusterclick", clusterClick);
// 点击聚合点的方法
const clusterClick = (e) => {
console.log(e);
};
// 缩放级别
let zoom = 12;
let maxZoom = 14;
let minZoom = 5;
// 初始化地图
const initMap = () => {
map = new T.Map("mapDiv");
map.setMinZoom(minZoom);
map.setMaxZoom(maxZoom);
...其他代码
}
// 点击聚合点的方法
const clusterClick = (e) => {
// 获取地图层级
const zoom = map.getZoom();
if (zoom < maxZoom) {
return;
}
console.log(e);
};
// 点击聚合点的方法
const clusterClick = (e) => {
// 获取地图层级
const zoom = map.getZoom();
if (zoom < maxZoom) {
return;
}
console.log(e);
console.log("点击的数据", e.layer.LO);
};
const { markers } = e.target.options;
markers.map((item) => {
const itemLayerPoint = map.lngLatToLayerPoint(item.or);
console.log('itemLayerPoint', itemLayerPoint)
});
console.log("getGridSize()", pointClusterLayer.getGridSize())
markers.map((item) => {
const itemLayerPoint = map.lngLatToLayerPoint(item.or);
// 计算综合像素差
const pixelDiff = Math.sqrt(Math.pow(Math.abs(clickLayerPoint.x - itemLayerPoint.x), 2) + Math.pow(Math.abs(clickLayerPoint.y - itemLayerPoint.y), 2));
if (pixelDiff < 81) {
pointData.push(item);
}
});
// 错误的获取聚合点点位数据的方法
const clusterClick = (e) => {
// 获取地图层级
const zoom = map.getZoom();
if (zoom < maxZoom) {
return;
}
console.log(e);
// 拿到的聚合点里的点位数据
let pointData = [];
// 获取所有的聚合点数组
const { markers } = e.target.options;
// 获取标记点
const clickLayerPoint = e.layerPoint;
markers.map((item) => {
const itemLayerPoint = map.lngLatToLayerPoint(item.or);
// 计算综合像素差
const pixelDiff = Math.sqrt(Math.pow(Math.abs(clickLayerPoint.x - itemLayerPoint.x), 2) + Math.pow(Math.abs(clickLayerPoint.y - itemLayerPoint.y), 2));
if (pixelDiff < 81) {
pointData.push(item);
}
});
console.log("pointData", pointData);
};
此页面不支持夜间模式!
已进入夜间模式!
已进入普通模式!
搜索框不允许为空
签到成功!经验+5!芋圆币+2!
签到失败!今日已签到!
需要登录社区账号才可以进入!