JMapViewer,将栅格加载到某个位置
我想在JMapViewer中的地图上加载并显示光栅文件。 光栅文件:
- 应该装在特定的位置,
- 使用缩放操作动态更改大小,
我希望JMapViewer支持这些操作。
目前,我正在使用从MapMarkerCircle派生的类:
public class ImageViewer extends MapMarkerCircle implements MapMarker { private BufferedImage img; public ImageViewer(Coordinate position, BufferedImage img) { this(position, 1, img);} public ImageViewer(Coordinate position, double radius, BufferedImage img) { super(position, radius); this.img = img; } public void paint(Graphics g, Point position, int sc) { int w = (int) (img.getWidth() * sc); int h = (int) (img.getHeight() * sc); g.drawImage(this.img, position.x - w/2;, position.y - h/2, w, h, null); } }
图像将添加为新的地图标记:
List ml = new ArrayList(); ml.add(new RasterRenderer(new Coordinate(0, 0), img)); this.setMapMarkerList(ml);
更新的问题:
不幸的是,该实现将标度sc提供为整数值
public void paint(Graphics g, Point position, int sc) {
这对于精确绘制光栅是不够的…假设光栅文件是一个用红色填充的透明矩形。
左图描绘了佛罗里达州的sc = 12 ,它位于栅格内部(从边界开始)。
不幸的是,在缩放级别sc = 183 ,佛罗里达在光栅之外(从边界左侧)……
同样的问题也出现在西北方向……
这种行为很奇怪,由于不同缩放级别的移位,无法使用地理参考栅格数据。
我试图从中重新定义MapMarker接口
public interface MapMarker extends MapObject, ICoordinate { void paint(Graphics g, Point position, int radius);
将比例值作为double返回
void paint(Graphics g, Point position, double radius);
不幸的是,半径由double表示,但没有小数位:
12 -> 12.0 183 -> 183.0 etc.
可能有一种不同的方法将光栅文件加载到JMapViewer组件,这样更舒适,没有这些“低级”步骤……
谢谢你的帮助。 一个例子会有所帮助……