3

I am implementing a map as a computer game accessory; it should show the geography of the computer game with a few informative overlays. I wonder what's the best way to achieve this in JavaFX, or more precisely ScalaFX.

Right now, I have a very naive implementation:

  • I have tiles for the map in different zoom levels. For each zoom level, I arrange ImageViews in a Group and transform that group, so that all zoom levels use the same coordinates.
  • A separate group with the same coordinates is used for my overlays.
  • I zoom using the mouse wheel and make only one zoom level visible, depending on the current zoom.
  • I pack all this into a ScrollPane.

That has a few limitations:

  • all tiles, for all zoom levels, are loaded at startup. That's ugly, but works in my particular use case.
  • using a ScrollPane only works if the map has limited bounds. Again, fine here, but not for maps in general.
  • the UX is weird: the ScrollPane scrolls with the mouse wheel, while most maps scroll per drag and drop; most maps zoom with the mouse wheel or pinch to zoom. It's critical that zooming preserves the "anchors" (mouse/touch positions) during the gesture. (It would also be nice to be mobile-ready out of the box, but that's just dreaming right now...)
  • different levels of detail in the overlay, depending on the current zoom, are possible, but probably not very efficient or convenient.

Obviously, this is one of the approaches I tried. This question mentions a library by some eppleton, but it doesn't seem to be maintained, and the blog that used to describe the library doesn't exist anymore. Also, it seems to focus on providing a game engine, with a tile having meaning to the game; a tile in a map is just an image, and the overlay doesn't care where one tile begins or ends.

To finish this with a concrete question: Are there any libraries or techniques that I can use to fulfill my needs? I'm especially interested in my third bullet point (UX), but I guess that if there's a suitable approach, it would cover points 1 to 3.

Silly Freak
  • 4,061
  • 1
  • 36
  • 58
  • Here is a (simplistic) [sample of a pannable map](https://gist.github.com/jewelsea/5032398). See also [JavaFX correct scaling](http://stackoverflow.com/questions/16680295/javafx-correct-scaling). Otherwise the question is probably a bit too broad for stack overflow (though there is some good information in there). If you spit it up into separate, very specific questions with some minimal sample code, you might have more luck getting better answers that fit more closely with what you are trying to achieve. – jewelsea Jul 14 '15 at 09:12
  • Instead of drawing the images and layers in your Java code, you might use a JavaFX WebView with an OpenLayers map and do the layering in OpenLayers (JavaScript). That's what I do in my [mapjfx](http://www.sothawo.com/projects/mapjfx/) project. – P.J.Meisch Jul 14 '15 at 09:35

1 Answers1

1

UPDATED: Few more options are on the table now:


One option is not to build but use existing open source project, such as openmapfx

Eugene Ryzhikov
  • 17,131
  • 3
  • 38
  • 60