Tracking mouse position in Java WorldWind

I am trying to add a mouse listener to my globe using addMouseListener . It does not show any error, I can even add mouseClicked(MouseEvent e) , and there are still no errors. But finally, when I try to get the current position using worldWindowGLCanvas1.getCurrentPosition() , it shows NULL even if I click on the globe or outside ... Can someone help me with this? Do not worry about extra spaces. I changed since the website did not accept my question :)

+1
source share
1 answer

I'm not sure if this is what you are asking for, but it worked 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 a null check to see if it will ever get null, and that is not the case. The assumption that this code makes is that clicking the mouse will block the globe to this position. Calling aCanvas.getCurrentPosition () should return the center of the globe. If the canvas is not displayed or not displayed, then this method returns null.

+1
source

All Articles