1

我正在广泛使用 Java worldwind 来在矩形扇区上显示数据的应用程序。我希望能够将这些数据拖到全球。如通过BasicDragger演示的那样,此类行为已在 WorldWind 中针对SurfaceCircle(实现Movable)等形状实现。

我正在尝试为AnalyticSurface实现这种行为(不实现可移动)。问题是DragSelectEvent .getTopObject 向我返回了一个名为AnalyticSurface.ClampToGroundSurface的受保护静态类,而我的 AnalyticSurface 没有公共访问器。

总结一下:我创建了一个对象并在 3d 地球渲染中显示它,并且在此图形表示上启动的拖动事件返回给我一个对象,该对象没有对我自己的对象的公共访问器,因此无法根据鼠标行为对其进行修改。

这似乎是 WorldWind 方面的架构错误。不使用反射,有没有办法访问我自己的对象链接到我的拖动事件?

4

1 回答 1

0

您需要做的就是扩展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));
    }
}
于 2015-09-17T22:02:15.323 回答