The Coordinate Viewer bean is represented by the IlvJMouseCoordinateViewer class. This bean
displays the current coordinates of the mouse when it is moved over
a map view.
An example of the Coordinate Viewer is shown in Coordinate Viewer .
![mapsprg_code16.gif](../usrprgmaps/_media/mapsprg_code16_default.gif)
Coordinate Viewer
Including the bean in an application
To include the Coordinate Viewer bean in
your application, write the following lines of code:
IlvJMouseCoordinateViewer coordViewer = new IlvJMouseCoordinateViewer(); coordViewer.setView(view);
Adding the bean to a Swing hierarchy
You can then add this bean to your Swing
hierarchy.
panel.add(coordViewer, BorderLayout.SOUTH);
The Coordinate Viewer bean then attaches a
Mouse Motion Listener to the view and displays the information
according to the properties of the manager:
- The IlvCoordinateSystemPropertyEditor is used to transform screen location coordinates into longitude/latitude information.
- The IlvAltitudeProviderProperty is used to retrieve the altitude at that longitude/latitude location, if available.
The coordinates and altitude are then transformed into human
readable strings using IlvDisplayPreferencesProperty unit
management and formatters.
Depending on the coordinate formatter,
latitude/longitude/altitude may not be the only fields. For
example, a UTM coordinate system displays the zone, zone number,
easting and northing information. The Coordinate Viewer uses
JLabel
HTML capabilities to display the different parts of the
coordinates as an HTML table.
Customizing the appearance
You can configure the appearance of the
bean using, for example:
coordViewer.setHtmlTableProperties("border=1 cellpadding=0 cellspacing=0");