Enhancing the SwingX-WS Projects Map Viewer
The ca.swingx.maps package contains classes that extend and enhance the SwingX-WS project's map viewer. The MapKit class is a direct extension of the SwingX-WS project's JXMapKit class. JXMapKit is extended for two reasons. First, the original setTileFactory method in the JXMapKit class resets the map's zoom and center position if it is invoked. Because you have the ability to plugin a new TileFactory on the fly, the aforementioned behavior is not desirable. Second, the extensions provide a more generic overlay mechanism than the JXMapKit class provided.
For the purposes of this article, the MapKit extension was also wrapped in the Map class. Though the Map class provides only a few delegate methods to the wrapped MapKit instance, you may add other delegate methods as required. There are four main reasons for wrapping the MapKit class:
- Wrapping hides and simplifies the full API to the SwingX-WS project's JXMapKit class.
- Wrapping hides the
setTileFactory method and provides a new setTileFactory method which accepts an XMLTileFactory object and an index.
- Wrapping initializes the wrapped
MapKit.
- Wrapping provides a credit overlay painter to display map credits.
Two other classes in the ca.ansir.swingx.maps package are GeoBounds and GeoUtil. For readers that are familiar with the Google Maps API, the GeoBounds class serves the same purpose as Google's GlatLngBounds class. The GeoBounds class provides access to the northwest corner and the southeast corner of a rectangular geographic region. GeoBounds also provides an intersects method to determine whether or not a GeoBounds object interests another GeoBounds object. The GeoUtil class provides a static method to obtain the visible GeoBounds of the map.
The CreditPainter class is the final class in the ca.ansir.swingx.maps package. CreditPainter extends the AbstractPainter object and implements the MouseListener interface. The CreditPainter also implements the AbstractPainter object's doPaint method generically with the following signature:
protected void doPaint(Graphics2D g, final JXMapViewer mapViewer,
int width, int height)
Part 2 showed how to design the XML configuration to contain metadata which could then be used to model the behavior of applying unique map credits to particular areas and zoom levels. The CreditPainter accomplishes this by using the map's zoom, GeoBounds, and the GeoBounds object's interests method.
Besides the ability to apply unique map credits, the CreditPainter is also responsible for launching a browser if the metadata contains a terms of use link. This is accomplished by adding CreditPainter as a MouseListener to the wrapped MapKit object's map viewer. Additionally, the bounds where the terms link was painted are known and if the map viewer is clicked in those bounds, the the CreditPainter opens the terms link in a browser.
| Home / Articles
/ Deliver On-the-Fly Mapping Services to Your Rich Desktop Java Application, Part 3 / 1 / 2 / |
Next Page
|
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|