World Wind Forums

Go Back   World Wind Forums > WorldWind JAVA forums > Development Help

Development Help Help for building applications or diagnosing problems with WWJ

Reply
 
Thread Tools Display Modes
Old 07-18-2012, 03:47 PM   #1
jscWaveLink
Junior Member
 
Join Date: Jul 2012
Posts: 8
jscWaveLink is on a distinguished road
Default Does Terrain Picking Work in 1.4.0?

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.
jscWaveLink is offline   Reply With Quote
Old 07-20-2012, 06:06 PM   #2
tag
WWJ Technical Manager
 
Join Date: May 2007
Location: Seattle
Posts: 1,027
tag is on a distinguished road
Default

You can get the current cursor position either by calling WorldWindow.getCurrentPosition() or by listening for Select events.
tag is offline   Reply With Quote
Old 07-20-2012, 09:38 PM   #3
jscWaveLink
Junior Member
 
Join Date: Jul 2012
Posts: 8
jscWaveLink is on a distinguished road
Default

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());
   }
}
Thanks for the hint.
jscWaveLink is offline   Reply With Quote
Old 07-20-2012, 09:51 PM   #4
tag
WWJ Technical Manager
 
Join Date: May 2007
Location: Seattle
Posts: 1,027
tag is on a distinguished road
Default

See the TerrainIntersections example. Also search for uses of WorldWindow.getCurrentPosition(). There are several examples that use it.
tag is offline   Reply With Quote
Old 07-20-2012, 09:52 PM   #5
jscWaveLink
Junior Member
 
Join Date: Jul 2012
Posts: 8
jscWaveLink is on a distinguished road
Default [SOLVED]

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 ));
and it works swimmingly. Thanks.
jscWaveLink is offline   Reply With Quote
Old 07-21-2012, 05:43 AM   #6
pabercrombie
WW Dev. Team
 
Join Date: Sep 2010
Location: Boston, MA, USA
Posts: 325
pabercrombie is on a distinguished road
Default

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
        }
    });
pabercrombie is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 02:04 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.