tracking mouse position on Java WorldWind
Asked Answered
J

1

1

I am trying to add a mouse listener to my globe using addMouseListener. It does not show any error, I am even able to add a mouseClicked(MouseEvent e), and still no errors. But finally when I am trying to get the current position using worldWindowGLCanvas1.getCurrentPosition() it shows NULL, even if I am clicking on the globe or outside... Can someone help me with doing this? Don't worry about extra spaces. I have modified since the website was not accepting my question :)

Joost answered 23/11, 2013 at 8:50 Comment(1)
Could you add your code to this post? There are still a lot of questions I have. I added an answer that works for me, but I'm not sure what you've already done. Where did you adde a mouseClicked method? See my answer and let me know if that helps.Intraatomic
I
1

I'm not sure if this is what you're asking, but this was working for me:

final WorldWindowGLCanvas aCanvas = new WorldWindowGLCanvas();
aCanvas.setModel(new BasicModel());
aCanvas.getInputHandler().addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent pE) {

        Position aCurrentPosition = aCanvas.getCurrentPosition();

        //Or whatever work:      
        if(aCurrentPosition != null) {

            System.out.println("Current Pos= " + aCurrentPosition);

        } else {

            System.out.println("Current Pos is null!");

        }
    }
});

I added the null check to see if it would ever get null and it did not. The assumption this code is making is that a mouse click will re-center the globe to that position. Calling the aCanvas.getCurrentPosition() should return the center globe. If the canvas is not rendered or isn't visible, then this method would return null.

Intraatomic answered 28/12, 2013 at 15:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.