views:

439

answers:

3

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 ?

A: 

JavaFX 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.

Matthew Hegarty
Yes you're right..starting with javafx seems a little weird with the scripting..so i want to keep it simple for now.Let me do it using swing..since,this is not a google/yahoo map..its a gif/bitmap,a map that i have of campus.how do i process it so that a mouseover the individual buildings on the map can show a balloon tip?
iceman
Don't get me wrong - I wouldn't want to put you off working with JavaFX. It's easy to use once you get used to it, and it seems well suited for the type of application you describe.
Matthew Hegarty
+1  A: 

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.

Joel Carranza
Thanks for the suggestion Joel, but if you read my post, I want it in a desktop app...not in a browser. i want some suggestions as to how can i read and process a map ..should it be a tilemap..
iceman
Ah, in that case you may want to look at the GeoTools library. It's a java library that provides a lot of tools for building map software
Joel Carranza
+1  A: 

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.

Joel Carranza