JMapViewer, load raster to a position

萝らか妹 提交于 2019-12-08 12:52:37

问题


I would like to load and display a raster file over the map in the JMapViewer. The raster file:

  • should be loaded at a specific position,
  • size dynamically changes using the zoom operations,

I hope these operations are supported by JMapViewer.

Currently, I am using a class derived from the 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);
   }
 }

The image is added as a new map mark:

List<MapMarker> ml = new ArrayList<>();
ml.add(new RasterRenderer(new Coordinate(0, 0), img));
this.setMapMarkerList(ml);

Updated question:

Unfortunately, this implementation provides the scale sc as an integer value

public void paint(Graphics g, Point position, int sc) {

which is not sufficient for the accurate drawing of the raster... Suppose the raster file to be a transparent rectangle filled with the red color.

The left figure depicts Florida at the scale sc=12, which is inside the raster (right from the boundary).

Unfortunately, at the zoom level sc=183, Florida is outside the raster (left from the boundary)...

The same issue appears also in the north-west direction...

Such behavior is strange, the georeferenced raster data cannot be used because of shifts at the different zoom levels.

I tried to redefine the MapMarker Interface from

public interface MapMarker extends MapObject, ICoordinate {

   void paint(Graphics g, Point position, int radius);

to return the scale value as the double

   void paint(Graphics g, Point position, double radius);

Unfortunately, the radius is represented by the double, but without decimal places:

12  -> 12.0
183 -> 183.0
etc.

There may be a different way of loading raster file to the JMapViewer component, which is more comfortable and without these "low-level" steps...

Thanks for your help. An example would be helpful...

来源:https://stackoverflow.com/questions/44955859/jmapviewer-load-raster-to-a-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!