简体   繁体   English

Java WorldWind:如何在DragEvent上访问AnalyticSurface

[英]Java WorldWind : how to access AnalyticSurface on DragEvent

I am using extensively Java worldwind for an application displaying data over rectangular sector. 我正在将Java worldwind广泛用于在矩形扇区上显示数据的应用程序。 I want to be able to drag this data over the globe. 我希望能够将此数据拖到全球各地。 Such behavior is already implemented in WorldWind for shapes such as SurfaceCircle (implementing Movable ) as demonstrated through BasicDragger . 这种行为在世界风已经实施了的形状如SurfaceCircle (实现可移动 )通过证实BasicDragger

I am trying to implement such behavior for AnalyticSurface (not implementing Moveable). 我正在尝试为AnalyticSurface实现这种行为(不实现Moveable)。 problem is that DragSelectEvent .getTopObject returns me a protected static class called AnalyticSurface.ClampToGroundSurface with no public accessor to my AnalyticSurface. 问题是DragSelectEvent .getTopObject向我返回了一个受保护的静态类,称为AnalyticSurface.ClampToGroundSurface ,而我的AnalyticSurface没有任何公共访问器。

To sum up : I created an object and I display it in 3d earth rendering, and drag event initiated onto this graphical representation returns me an object with no public accessor to my own object, hence no way to modify it following the mouse behavior. 总结一下:我创建了一个对象,并在3d地球渲染中显示了该对象,并且在此图形表示形式上发起的拖动事件返回了一个对象,该对象没有我自己对象的公共访问器,因此无法按照鼠标行为对其进行修改。

It seems like an architecture mistake on WorldWind side. 在WorldWind方面,这似乎是一个体系结构错误。 With no use of reflection, is there a way to access my own object linked to my drag event ? 不使用反射,是否有办法访问链接到我的拖动事件的我自己的对象?

All you need to do is extend AnalyticSurface and implement Movable , then you can just use BasicDragger instead of writing your own select listener. 您需要做的就是扩展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));
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM