JXMapViewer 将方向更改为 Heading Up
我正在尝试将 JXMapViewer (来自 swingx-ws)与 Open Street Maps 一起使用。我想知道是否可以在 JXMapViewer 中基于航向向上而不是向北显示地图图块。例如,普通的汽车 GPS 导航系统就可以做到这一点。
我查看了文档,似乎没有一个简单的方法可以做到这一点。除了 JXMapViewer 之外,还有其他东西可以实现此目的吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没关系,我找到了解决方案。这是我的做法(如果有人感兴趣的话):
我将 JXMapViewer 子类化,并覆盖了 Paint 方法。
在paint方法中,JPanel的内容被转换为BufferedImage,然后根据角度旋转,然后绘制在面板的顶部。
所以 super.paint()-> BufferedImage->;对它应用仿射变换 ->绘制新图像。
当然,考虑到图像已旋转的事实,您还需要重写convertGeoPositionToPoint 和convertPointToGeoPosition 方法。
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.