I want to build a desktop application - a map viewer , something like this : http://sunsite.ubc.ca/UBCMap/
in Java . Whenever someone hovers the mouse over a building on the map , there should be a balloon tool-tip saying something about that building on the map like its office phone number etc and that building should glow in the 2-d map. Can someone provide me some directions as to what framework should i use in Java to build something like this(e.g JavaFx) ? Is there any sample code which does something similar ?
views:
439answers:
3JavaFX is a suitable candidate for this type of application. The JavaFX script syntax takes a little bit of getting used to, but once you're up to speed it is easy to create graphical/GUI components.
Also, you can hook into existing Java APIs and web services which might be of use for your application.
Check out here and here for apps similar to the one you described. (also google for Javafx maps)
A word of warning about JavaFX is that it is still in the early part of its life - therefore expect to encounter bugs and be warned of the possibility of breaking changes in later releases.
If your map really is as simple as the example you linked to, I would highly recommend avoiding the use of java (or javaFX altogether). You can do what you want with any of the javascript DHTML mapping apis. See
- Google Maps API
- OpenLayers
Java is overkill. Applets are slow to load and difficult to properly deploy under a varied number of environments. Better to publish a KML file (or something equivalent) and leverage someone else's maps than to write and maintain an entire application yourself.
If really all you have is an image and you want tooltips over it - here is a 30 second description.
- Subclass JPanel
- override paint() method to draw image
- Define some number of Shape objects (polygons, rects, etc...) as your "buildings" along with a text tooltip string
- override getTooltip in JPanel subclass. On each call iterate over your Shape objects, testing if the point is inside shape (shape has a method for this). return tooltip appropriate for Shape, or null if your mouse isn't over shape
- if you want rollover effects, register MouseMotionListener and use it to find the "hover" shape. Call repaint() and render your "hover" in some special way.
- boom! you're done
HINT: You will need to register your JPanel with TooltipManager most likely.