Interactive Map viewer desktop application in Java

2020-07-18 06:31发布

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 ?

4条回答
爷的心禁止访问
2楼-- · 2020-07-18 06:54

Take a look into JxMaps product. It provides functionality to add interactive map to Java desktop application.

查看更多
戒情不戒烟
3楼-- · 2020-07-18 07:08

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.

查看更多
Summer. ? 凉城
4楼-- · 2020-07-18 07:10

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.

查看更多
Bombasti
5楼-- · 2020-07-18 07:11

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.

查看更多
登录 后发表回答