我广泛使用 Java worldwind 作为在矩形扇区上显示数据的应用程序。我希望能够在全局范围内拖动这些数据。这种行为已在 WorldWind 中针对 SurfaceCircle 等形状实现。 (实现 Movable )如通过 BasicDragger 所示.
我正在尝试为 AnalyticSurface 实现这种行为(未实现可移动)。问题是DragSelectEvent .getTopObject 返回一个名为 AnalyticSurface.ClampToGroundSurface 的 protected 静态类没有对我的 AnalyticSurface 的公共(public)访问器。
总而言之:我创建了一个对象,并在 3D 地球渲染中显示它,并且在该图形表示上启动的拖动事件返回一个对象,没有对我自己的对象的公共(public)访问器,因此无法按照鼠标行为修改它。
这似乎是 WorldWind 方面的架构错误。在不使用反射的情况下,有没有办法访问链接到我的拖动事件的我自己的对象?
最佳答案
您需要做的就是扩展 AnalyticSurface
并实现 Movable
,然后您就可以使用 BasicDragger
而不必编写自己的选择监听器。
public class DraggableAnalyticSurface extends AnalyticSurface implements Movable {
@Override
public Position getReferencePosition() {
return this.referencePos;
}
@Override
public void move(Position position) {
// not needed by BasicDragger
}
@Override
public void moveTo(Position position) {
final double latDelta = this.referencePos.getLatitude().degrees
- position.getLatitude().degrees;
final double lonDelta = this.referencePos.getLongitude().degrees
- position.getLongitude().degrees;
final double newMinLat = this.sector.getMinLatitude().degrees - latDelta;
final double newMinLon = this.sector.getMinLongitude().degrees - lonDelta;
final double newMaxLat = this.sector.getMaxLatitude().degrees - latDelta;
final double newMaxLon = this.sector.getMaxLongitude().degrees - lonDelta;
this.setSector(Sector.fromDegrees(newMinLat, newMaxLat, newMinLon, newMaxLon));
}
}
关于Java世界风: how to access AnalyticSurface on DragEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32475385/