Hi Michael,
 
This method looks promising. I will try it and let you know :)
 
Many thanks for your help.
 
Kakpo
 
 

> Date: Tue, 14 Aug 2012 22:09:45 +1000
> Subject: Re: Adding Tool Tip text in JMapFrame
> From: michael.bedw...@gmail.com
> To: adok...@hotmail.com
> CC: geotools-gt2-users@lists.sourceforge.net
> 
> Hi Kakpo,
> 
> > I have searching for this for a while. Is there any quick way to add a
> > toolTipText on features in JMapFrame when the cursor is hovering above them
> > ?
> 
> Nice question. It depends what you call quick :)
> 
> This facility is not in the JMapFrame or JMapPane API but I think you
> could do it by sub-classing JMapPane and overriding the JComponent
> methods for tool tips...
> 
> /*
> * WARNING: I haven't tested this at all !!!
> */
> public class ToolTipMapPane extends JMapPane {
> 
> @Override
> public String getToolTipText(MouseEvent ev) {
> // use the map pane's MapMouseEventDispatcher to convert the
> // AWT mouse event into a MapMouseEvent with world coordinates
> MapMouseEvent mapEv = mouseEventDispatcher.convertEvent(ev);
> 
> SimpleFeature feature = getFeatureAtMousePos( mapEv );
> if (feature != null) {
> return getTextForFeature( feature );
> }
> 
> // returning null means no tool tip is displayed
> return null;
> }
> 
> @Override
> public Point getToolTipLocation(MouseEvent event) {
> // return null to let Swing choose the location of the tooltip
> // or return a position based on the input event position to
> // set a custom tooltip location.
> 
> return null;
> }
> 
> private SimpleFeature getFeatureAtMousePos(MapMouseEvent mapEv) {
> // Use the world coordinates of the map mouse event to filter
> // the feature(s) at this location. Return null if nothing
> // that you want to display a tool tip for is there.
> 
> SimpleFeature featureUnderCursor = null;
> 
> // --- your filtering code here ---
> 
> return featureUnderCursor;
> }
> 
> private String getTextForFeature(SimpleFeature feature) {
> String text = null;
> 
> // --- Your code here to extract text from the feature ---
> 
> return text;
> }
> 
> }
> 
> 
> Now when using this class you need to register it with the Swing tool
> tip manager, otherwise your tool tip methods will not be called. The
> easiest way to do this is to call myMapPane.setToolTip( "foo" ) which
> will register your map pane with the manager as a side-effect.
> 
> If you need a head start with the code for your getFeatureAtMousePos
> method, you might like to look at this tutorial code:
> 
> http://docs.geotools.org/latest/userguide/tutorial/map/style.html#what-features-did-the-user-click-on
> 
> Hope that helps. Let me know how you go with it.
> 
> Michael
                                          
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to