Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 1562 → Rev 1563

/dongfang_FC_rewrite_tool/src/dongfang/mkt/ui/offscreendisplay/MapImageView.java
0,0 → 1,88
package dongfang.mkt.ui.offscreendisplay;
 
/*
* u/l: geotagged geo:lat=47.327450 geo:lon=8.521657
* l/r: geotagged geo:lat=47.321749 geo:lon=8.534403
* house: geotagged geo:lat=47.324614 geo:lon=8.528202
*/
 
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
 
import javax.swing.JFrame;
import javax.swing.JPanel;
 
import dongfang.mkt.datatype.GPSPosition;
 
public class MapImageView extends JPanel {
private Image mapImage;
private Image copterImage;
 
private static final int MAPWIDTH = 600;
private static final int MAPHEIGHT = 400;
 
// It is assumed the map is north/south oriented!
private GPSPosition upperLeft;
private GPSPosition lowerRight;
 
private GPSPosition hightlightPosition;
public MapImageView(GPSPosition upperLeft, GPSPosition lowerRight, String imageFileName) {
setSize(MAPWIDTH, MAPHEIGHT);
this.upperLeft = upperLeft;
this.lowerRight = lowerRight;
mapImage = Toolkit.getDefaultToolkit().getImage(imageFileName);
}
 
private double relativeX(GPSPosition pos) {
double lon = pos.getLongitude();
// The sign should be OK here (positive) both east and west.
double span = lowerRight.getLongitude() - upperLeft.getLongitude();
double offset = lon - upperLeft.getLongitude();
return offset / span;
}
 
private double relativeY(GPSPosition pos) {
double lat = pos.getLatitude();
// The sign should be OK here (positive) both east and west.
double span = lowerRight.getLatitude() - upperLeft.getLatitude();
double offset = lat - upperLeft.getLatitude();
return offset / span;
}
 
public void paintComponent(Graphics g) {
// Draw our Image object.
g.drawImage(mapImage, 0, 0, MAPWIDTH, MAPHEIGHT, this); // at location
g.setColor(Color.red);
int x = (int)(MAPWIDTH * relativeX(hightlightPosition) + 0.5);
int y = (int)(MAPHEIGHT * relativeY(hightlightPosition) + 0.5);
g.drawArc(x, y, 20, 20, 0, 360);
}
public static void main(String[] args) {
GPSPosition upperLeft = new GPSPosition();
GPSPosition lowerRight = new GPSPosition();
GPSPosition highlight = new GPSPosition();
upperLeft.setLatitude((int)(47.327450 * 1E7));
upperLeft.setLongitude((int)(8.521657 * 1E7));
 
// * l/r: geotagged geo:lat=47.321749 geo:lon=8.534403
lowerRight.setLatitude((int)(47.321749 * 1E7));
lowerRight.setLongitude((int)(8.534403 * 1E7));
// geotagged geo:lat=47.324614 geo:lon=8.528202
highlight.setLatitude((int)(47.324714 * 1E7));
highlight.setLongitude((int)(8.528102 * 1E7));
MapImageView v = new MapImageView(upperLeft, lowerRight, "flugplatz_small.png");
v.hightlightPosition = highlight;
JFrame f = new JFrame();
f.getContentPane().add(v);
f.setSize(v.getSize());
f.setVisible(true);
}
}