Hi,
I've got an Openmap layer which displays several OMLines, representing legs
of a flight route.
I am attempting to handle mouse clicks to identify which flight route has
been clicked on. I'm trying to do this as follows:
1. My Layer adds the appropriate OMLines to the OMGraphicList, and I can see
these on the map, as expected. Each OMLine has the relevant flight route
object linked to it via setAppObject()
2. My Layer implements MapMouseListener and defines the appropriate event
handling methods
3. In the mouseClicked() method, I'm trying to use the the
OMGraphicList.findClosest() method to identify the closest OMGraphic to the
mouse click event.
I have successfully used this exact same method to handle mouse events in
layers displaying OMRaster images and other OMGraphics.
My Code looks something like this:
public boolean mouseClicked(MouseEvent evt) {
OMGraphic closestPlanImage = (OMGraphic)
omgraphics.findClosest(evt.getX(), evt.getY());
if (closestPlanImage != null) {
FlightPlan closestPlan = (FlightPlan) closestPlanImage.getAppObject();
if(closestPlan !=null) {
// Do stuff with the plan
}
else {
// No route attached to the closest OMGraphic (shouldn't happen)
}
}
else {
// No OMGraphic returned from the findClosest() method
}
// Don't consume the mouse event
return false;
}
I know that the OMGraphicList contains a bunch of OMLines (and I can confirm
this by querying the OMGraphicList at the time of the mouse event).
Unfortunately, the findClosest() method *always* returns null, no matter
where I click on the map.
If I add some other OMGraphics to my layer (such as an OMPoint at each
waypoint in the route), then findClosest() does return the OMPoint when I
click close to it (but still never returns any OMLines, regardless of where
the mouse clicks occur).
Any ideas of where the problem might lie? Is there something specific about
OMLine that doesn't work with findClosest()? If so, any ideas of an
alternate way to achieve what I'm trying to do?
Thanks in advance,
Andrew Lampert
--------------
Research/Software Engineer
CSIRO ICT Centre
http://www.cmis.csiro.au/Andrew.Lampert/
-- [To unsubscribe to this list send an email to "majdart@bbn.com" with the following text in the BODY of the message "unsubscribe openmap-users"]Received on Fri Oct 10 05:09:37 2003
This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:36 EDT