0

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).

enter image description here

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...

justik
  • 4,145
  • 6
  • 32
  • 53
  • Maybe a custom `TileSource`? – trashgod Jul 07 '17 at 23:38
  • @ trashgod: I tried to look at the TileSource class. However, there are two main problems: How to set parameters of the source for processing a local file and how to store a file to enable its loading using the TileSource. – justik Jul 08 '17 at 08:45
  • moreover, you'd have to create a tile set for each supported zoom level; it looks like the URLs could resolve to a local filesystem. – trashgod Jul 08 '17 at 14:26
  • @ trashgod: Is it possible to combine the both tile sources (OSM loaded from map server and my raster)? – justik Jul 08 '17 at 20:08
  • I've not tried. Won't the raster have unacceptable resampling artifact at higher scales? – trashgod Jul 08 '17 at 23:18

0 Answers0