在图层切换直接导致pickEvent事件失效:
// 监听camera倾斜角度
window.viewer.scene.camera.changed.addEventListener(() => {
const pitch = window.viewer.camera.pitch;
console.log(pitch);
const gridLayer = window.viewer.scene.layers.find("xxxx");
const buildLayer = window.viewer.scene.layers.find("xxxxx");
if (pitch > -1.2) {
// 三维
// 隐藏二维网格图层
if (gridLayer) {
gridLayer.visible = false;
}
// 加载三维建筑图层
if (buildLayer) {
buildLayer.visible = true;
}
} else {
// 二维
// 隐藏三维建筑图层
if (buildLayer) {
buildLayer.visible = false;
}
// 加载二维网格图层
if (gridLayer) {
gridLayer.visible = true;
}
}
});
//注册鼠标点击事件
window.viewer.pickEvent.addEventListener((feature) => {
console.log(feature);
}, "我是监听事件");