[udig-devel] Capture events when user clicks the map?
Sun Yang
syyzxsyf at gmail.com
Mon Mar 31 02:13:36 PDT 2008
Hi, Jody:
Thanks for your suggestion. I achieve some progress with your suggestion.
Could you have a look and check whether I am in the right direction?
My imaginary scenario is to extend the property example so if user
double-clicks the airport, we could open a view and show some information
for the selected airport (such as the camera view of the airport entrance
from other application). To achieve this goal, I have to get the unique key
for the selected data (eg, the airport name) and then use that key to query
the information from other application source.
I don't want to firstly put the user into some tool mode. So I have a quick
look at the source code and make some hacks there.
1. Add a MouseListener to the ViewportPane.
IToolContext toolContext = ApplicationGIS.createContext(
ApplicationGIS.getActiveMap());
toolContext.getViewportPane().addMouseListener(this);
2. When user double clicks the pane, check whether the event's point is
within 10 points from the airpoint location. So we can get the airport's
name and use it in the further query.
List<ILayer> layers = ApplicationGIS.getActiveMap().getMapLayers();
for (ILayer layer : layers) {
IGeoResource resource = layer.getGeoResource();
PropertyResource pr = resource.resolve(
PropertyResource.class, null);
for (Map.Entry<String, Coordinate> entry :
pr.getValues().entrySet())
{
IToolContext context = ApplicationGIS.createContext(
ApplicationGIS.getActiveMap());
Point p = context.worldToPixel(entry.getValue());
System.err.println("Distance: " + p.distance(
e.getPoint()));
if (p.distance(e.getPoint()) < 10) {
System.err.println("Hacked successfully.");
System.out.println("Airport name is: " +
entry.getKey());
}
}
}
>From this way, I can get the airport name when I double clicks the airport
in the map. But is it the best way to do that? Could I extend some extension
points to achieve the same goal.
Another thinking is that the InfoTool you suggested is based on querying the
feature source. How could I introduce the feature source in the property
example? Could you give me some suggestions?
Thanks for reading this long letter and your help so long.
Best Regards,
Yang Sun
2008/3/27, Jody Garnett <jgarnett at refractions.net>:
>
> Have a look at the normal DistanceTool tutorial; it provides a tool that
> responds to mouse down, and mouse release events. You can modify the
> example to take care of double clicks. When you do get a double click
> you can do a query on your hospital layer to see if they clicked on one.
> You may also enjoy looking at the InfoTool (it operates as a single
> click; and opens a view up to show the result of a query at that
> location).
>
> This email list is a great location for these kinds of questions.
> Jody
>
> > Hi,
> >
> > I want to support some kind of interactivity when user clicks the map.
> > For example, when user double clicks a point in the map, could I get
> > an event notification so I can do corresponding works?
> >
> > To be specific, I finished the tutorials for the custom property
> > resource and property renderer, could I be notified when user double
> > click one of hospitals? Any listener mechanism exists?
> >
> > Pls give me some suggestions or code examples if any. Your help is
> > appreciate.
> >
> > BTW, I am not sure whether this list is the right place to send this
> > email. If this kind of email should go to the users mailing list, pls
> > tell me.
> >
> > Best Regards,
> > Yang Sun
> >
>
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > User-friendly Desktop Internet GIS (uDig)
> > http://udig.refractions.net
> > http://lists.refractions.net/mailman/listinfo/udig-devel
> >
>
>
> _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.refractions.net/pipermail/udig-devel/attachments/20080331/e0974a6f/attachment.html
More information about the udig-devel
mailing list