JXMapViewer change orientation to Heading Up

1k views Asked by At

I am trying to use JXMapViewer (from swingx-ws) with Open Street Maps. I was wondering if it would be possible to display the map tiles in the JXMapViewer based on heading up, rather than on North up. For example, the normal car GPS navigation systems let you do that.

I've looked through the documentation and there doesn't seem to be a straightforward way to do this. Is there something else that accomplish this, besides JXMapViewer?

1

There are 1 answers

0
Charlie On

Nevermind, I found a solution. Here is how I did it(if anybody is interested) :

I subclassed JXMapViewer, and overrode the paint method. In the paint method contents of the JPanel are converted to a BufferedImage which is then rotated according to an angle and then painted on top of the panel.

so super.paint()-> BufferedImage-> apply an affineTransformation to it-> draw the new Image.

Of course, you would also need to override the convertGeoPositionToPoint and convertPointToGeoPosition methods taking into account the fact that the image is rotated.