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
ImageView
s in aGroup
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.