根据提供的问题描述,如果在ArcGIS JS API 4.11和4.12中,GraphicsView2D的hitTest方法不工作正确,可能需要进行以下解决方法:
GraphicsView2D
类和其他相关的模块。例如:import GraphicsView2D from "esri/views/2d/layers/graphics/GraphicsView2D";
检查是否使用了正确的版本。请确保使用的是ArcGIS JS API 4.11或4.12版本。如果使用的是其他版本,可能需要更新到4.11或4.12以获得正确的结果。
确认是否正确设置GraphicsView2D对象。请确保GraphicsView2D对象已正确设置,并已关联到地图视图或场景视图。例如:
const graphicsView2D = new GraphicsView2D({
// 设置其他配置项
});
// 关联到地图视图或场景视图
view.ui.add(graphicsView2D, "top-right");
const screenPoint = {
x: event.x,
y: event.y
};
// 调用hitTest方法
const hitResult = graphicsView2D.hitTest(screenPoint);
graphicsView2D.hitTest(screenPoint)
.then(function(hitTestResult){
// 处理命中测试的结果
console.log(hitTestResult);
})
.catch(function(error){
// 处理错误
console.error(error);
});
通过检查以上步骤,您应该能够解决GraphicsView2D的hitTest方法不正确的问题。如果问题仍然存在,请检查ArcGIS JS API的文档和示例,以获取更多关于hitTest方法的使用方法和注意事项。