View Full Version : shape layer: best way to receive mouse click events
gilou
05-24-2007, 11:24 AM
Hello
I am doing a vector layer which display satellite image footprints.
I extend a RenderableLayer. I am able to display the footprints.
Now I would like to have my layer listen to mouse click, to determine on which footprint(a) the user has clicked.
What is the way of doing it? Is there a way of directly knowing the list of object at the click location?
Thanks
Gilles
patmurris
05-24-2007, 01:02 PM
There is some quite adavanced 'picking' code in there. You may just need to invoke pick() on WorldWindow and get a 'PickedObjectList... I havent experimented with it yet.
ghchinoy
05-24-2007, 01:41 PM
A RenderableLayer should have pick support so that you can add a select listener...
Add a SelectListener to your WorldWindowGLCanvas (or GLPanel), either a separate class or an inner/anonymous class, and iterate through the objects in the event.
wwd.addSelectListener( new SelectListener() {
@Override
public void selected( SelectEvent event ) {
if (event.getEventAction().equals( SelectEvent.LEFT_CLICK ) { // there are many of these
if (event.hasObjects())
System.out.println( event.getTopObject().toString() ); // iterate through the objects, this is the top
}
}
});
Printing out the the toString() of the first object's not horribly useful, but it's an example. You can do things like if (event.getTopObject() instanceof SurfacePolygon) { Sector s = ((SurfacePolygon)event.getTopObject()).g etSector(); } and then use the sector info (max lat, max lon, min lat, min lon) to tell you information about it (for example). You can get access to your specific subclass's information that way.
gilou
05-25-2007, 12:24 PM
Hello
Thanks guys, i worked perfectly.
I was suspecting this picking stuff, but I expected to have a way to register as selectListener(or mouseListener) into something from inside my layer class.
gilles
what_nick
05-29-2007, 02:46 PM
The selectlistener is global to the canvas. You can filter through it and pass it on the the appropriate object.
Sylar
07-03-2007, 12:24 PM
Hey there,
Im doing a project which involves getting a series of images to appear on the top layer of the window when a placemark on the Earth is clicked. I want to be able to drag around these images and more useful stuff.
The problem is that Im a noob when it comes to World Wind, and it is a more complicated program than Im used to, but Im willing to learn from others.
I have implemented the addSelectListener without too much hassle, Im having issues with the way that it receives mouse events and the like.
Can anyone give me a heads up on how this works in more detail?
Or somewhere I can see a similar implementation?
Thanks very much,
Dave
toolshed
07-03-2007, 02:48 PM
I want to be able to drag around these images and more useful stuff.
The drag event is not working. It is listed on the issue tracker (http://issues.worldwind.arc.nasa.gov/browse/WWJ-44). My guess is that it will be fixed with the next release (Friday).
Sylar
07-03-2007, 03:02 PM
The drag event is not working. It is listed on the issue tracker (http://issues.worldwind.arc.nasa.gov/browse/WWJ-44). My guess is that it will be fixed with the next release (Friday).
Cool thanks for the heads up!
But could I get an idea of how to get some basic mouse event working?
toolshed
07-03-2007, 03:06 PM
But could I get an idea of how to get some basic mouse event working?
Have you looked at the AWT1Up example?
rnrivas
10-26-2007, 10:20 PM
I'm drawing plane images as WWIcons, and like the previous post, I'm trying to figure out which icon is being clicked on. I'm using SelectEvent, but getTopObject returns the image file path, but not the actual WWIcon. I cant get the coordinates from the image file. So I wondering how to get the actual WWIcon, so I can figure out the position and move the Icon.
thanks!!
A RenderableLayer should have pick support so that you can add a select listener...
Add a SelectListener to your WorldWindowGLCanvas (or GLPanel), either a separate class or an inner/anonymous class, and iterate through the objects in the event.
wwd.addSelectListener( new SelectListener() {
@Override
public void selected( SelectEvent event ) {
if (event.getEventAction().equals( SelectEvent.LEFT_CLICK ) { // there are many of these
if (event.hasObjects())
System.out.println( event.getTopObject().toString() ); // iterate through the objects, this is the top
}
}
});
Printing out the the toString() of the first object's not horribly useful, but it's an example. You can do things like if (event.getTopObject() instanceof SurfacePolygon) { Sector s = ((SurfacePolygon)event.getTopObject()).g etSector(); } and then use the sector info (max lat, max lon, min lat, min lon) to tell you information about it (for example). You can get access to your specific subclass's information that way.
toolshed
10-27-2007, 01:29 AM
I'm drawing plane images as WWIcons, and like the previous post, I'm trying to figure out which icon is being clicked on. I'm using SelectEvent, but getTopObject returns the image file path, but not the actual WWIcon. I cant get the coordinates from the image file. So I wondering how to get the actual WWIcon, so I can figure out the position and move the Icon.
thanks!!
You are getting the WWIcon. The reason you get the path printed out is because UserFacingIcon overides the toString method and returns the image source (which is the file path in your case).
Try this...
wwd.addSelectListener( new SelectListener() {
@Override
public void selected(SelectEvent event) {
if (event.getEventAction().equals(SelectEve nt.LEFT_CLICK)
if (event.hasObjects()) {
Object obj = event.getTopObject();
if (obj instanceof WWIcon)
System.out.println("Clicked an icon.");
}
}
}
});
BTW, if you are trying to move the icon (drag it), there is an easier way. Check out the dragging example in the latest release.
rnrivas
10-27-2007, 01:45 AM
Thanks! I used the instance check and casted it, and now it has options I need. I'm not trying to drag it, but have it move itself to the point the user clicks. So, it should work now, thanks for the help!
vBulletin® v3.7.1, Copyright ©2000-2013, Jelsoft Enterprises Ltd.