![]() |
|
|||||||
| Development Help Help for building applications or diagnosing problems with WWJ |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Jul 2012
Posts: 8
![]() |
I'd like to get the coordinates of the terrain when the user clicks the right mouse button. I modified the ClickAndGoSelectListener, but it seems to not get called for mouse clicks on the terrain. Is there something that I'm missing? Thanks for your help.
|
|
|
|
|
|
#2 |
|
WWJ Technical Manager
Join Date: May 2007
Location: Seattle
Posts: 1,027
![]() |
You can get the current cursor position either by calling WorldWindow.getCurrentPosition() or by listening for Select events.
|
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jul 2012
Posts: 8
![]() |
It seems that when listening for select events, the listener doesn't get called when the terrain is picked. I've tried adding a MouseAdapter to the AppPanel (e.g. in the ApplicationTemplate example), but that listener doesn't get called either. The WorldWindow doesn't accept a MouseListener and a PositionListener doesn't identify mouse clicks.
My idea is to have a listener get called on a mouse click. If it is a RIGHT_CLICK, then the code below should print out the coordinates. My problem is that the listener never gets called. Code:
PickedObjectList pickedObjects = this.wwd.getObjectsAtCurrentPosition();
if (pickedObjects != null && pickedObjects.getTopPickedObject() != null)
{
if (pickedObjects.getTopPickedObject().isTerrain())
{
System.out.println("was on Terrain");
Position targetPos = pickedObjects.getTopPickedObject().getPosition();
System.out.println("Lat "+targetPos.getLatitude().getDegrees()+
"Lon "+targetPos.getLongitude().getDegrees());
}
}
|
|
|
|
|
|
#4 |
|
WWJ Technical Manager
Join Date: May 2007
Location: Seattle
Posts: 1,027
![]() |
See the TerrainIntersections example. Also search for uses of WorldWindow.getCurrentPosition(). There are several examples that use it.
|
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Jul 2012
Posts: 8
![]() |
Ok, solved this one. When adding the MouseListener, one must add it to the WorldWindow, even though that class isn't a subclass of Component. The object really is a WorldWindowGLCanvas which is an AWT Component. Added the cast...
Code:
((Component) this.wwd).addMouseListener(new TerrainSelector( this.wwd )); |
|
|
|
|
|
#6 |
|
WW Dev. Team
Join Date: Sep 2010
Location: Boston, MA, USA
Posts: 325
![]() |
You need to add the mouse listener to the World Wind InputHandler. This is how I usually capture clicks on terrain:
Code:
final WorldWindow wwd = ...
wwd.getInputHandler().addMouseListener(new MouseAdapter()
{
@Override
public void mouseClicked(MouseEvent e)
{
System.out.println(wwd.getCurrentPosition());
e.consume(); // Prevents globe moving in response to click
}
});
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Update/Fix for World Wind 1.4.0 Imagery and Terrain | pangloss | Technical Support | 56 | 03-30-2013 04:26 PM |
| Picking Terrain | jscWaveLink | Development Help | 1 | 07-21-2012 06:01 AM |
| Problem picking terrain with vertical exaggeration set to 0 | NathanKronenfeld | Development Help | 3 | 01-21-2011 04:50 PM |
| Bug in the visualization for the terrain of CompoundElevationModel? | mao | Development Help | 8 | 03-20-2009 05:12 AM |