function addGraphicLayer() {
graphicLayer = new mars3d.layer.GraphicLayer({
clustering: {
enabled: true,
pixelRange: 20,
clampToGround: false,
addHeight: 1000
},
popup: "all",
center: { lat: 31.639275, lng: 117.388877, alt: 52574.8, heading: 339.3, pitch: -65 },
flyTo: true
})
map.addLayer(graphicLayer)
// 单击事件
graphicLayer.on(mars3d.EventType.click, function (event) {
console.log("你单击了", event)
})
mars3d.Util.fetchJson({
url: "//data.mars3d.cn/file/geojson/hfty-point.json"
}).then((res) => {
for (let i = 0; i < res.features.length; i++) {
const item = res.features[i]
const label = new mars3d.graphic.BillboardPrimitive({
position: item.geometry.coordinates,
style: {
image: "img/marker/mark-blue.png",
}
})
graphicLayer.addGraphic(label)
}
})
}
1.不是聚合的图标点在单击的时候可以查到找到那个attr,但是点击聚合就找不到了。
2.期望在单击聚合点的时候,拿到聚合数据的详细信息。BillboardEntity 使用这个是可以获取的到聚合的数组n个图标点的信息的。但是BillboardPrimitive的attr携带赋值了参数,但是在点击聚合的时候好像没有这个参数。
解决方案:
// 单击事件
graphicLayer.on(mars3d.EventType.click, function (event) {
console.log("你单击了", event)
if (map.camera.positionCartographic.height > 90000) {
const graphic = event.graphic
// graphic.closePopup()
if (graphic?.cluster) {
// 单击了聚合的点
console.log("单击了聚合的点", graphic.getGraphics())
} else {
// 单击了具体的点对象
const position = graphic.positionShow
map.flyToPoint(position, {
radius: 5000, // 距离目标点的距离
duration: 4,
complete: function (e) {
// 飞行完成回调方法
// graphic.openPopup()
}
})
}
}
})