Subversion Repositories Projects

Rev

Rev 1565 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1563 - 1
package dongfang.mkt.ui.offscreendisplay;
2
 
3
/*
4
 * u/l:         geotagged geo:lat=47.327450 geo:lon=8.521657
5
 * l/r:         geotagged geo:lat=47.321749 geo:lon=8.534403
6
 * house:       geotagged geo:lat=47.324614 geo:lon=8.528202
7
 */
8
 
9
import java.awt.Color;
10
import java.awt.Graphics;
11
import java.awt.Image;
12
import java.awt.Toolkit;
13
 
14
import javax.swing.JFrame;
15
import javax.swing.JPanel;
16
 
17
import dongfang.mkt.datatype.GPSPosition;
18
 
19
public class MapImageView extends JPanel {
20
        private Image mapImage;
21
        private Image copterImage;
22
 
23
        private static final int MAPWIDTH = 600;
24
        private static final int MAPHEIGHT = 400;
25
 
26
        // It is assumed the map is north/south oriented!
27
        private GPSPosition upperLeft;
28
        private GPSPosition lowerRight;
29
 
30
        private GPSPosition hightlightPosition;
31
 
32
        public MapImageView(GPSPosition upperLeft, GPSPosition lowerRight, String imageFileName) {
33
                setSize(MAPWIDTH, MAPHEIGHT);
34
                this.upperLeft = upperLeft;
35
                this.lowerRight = lowerRight;
36
                mapImage = Toolkit.getDefaultToolkit().getImage(imageFileName);
37
        }
38
 
39
        private double relativeX(GPSPosition pos) {
40
                double lon = pos.getLongitude();
41
                // The sign should be OK here (positive) both east and west.
42
                double span = lowerRight.getLongitude() - upperLeft.getLongitude();
43
                double offset = lon - upperLeft.getLongitude();
44
                return offset / span;
45
        }
46
 
47
        private double relativeY(GPSPosition pos) {
48
                double lat = pos.getLatitude();
49
                // The sign should be OK here (positive) both east and west.
50
                double span = lowerRight.getLatitude() - upperLeft.getLatitude();
51
                double offset = lat - upperLeft.getLatitude();
52
                return offset / span;
53
        }
54
 
55
        public void paintComponent(Graphics g) {
56
                // Draw our Image object.
57
                g.drawImage(mapImage, 0, 0, MAPWIDTH, MAPHEIGHT, this); // at location
58
                g.setColor(Color.red);
59
                int x = (int)(MAPWIDTH * relativeX(hightlightPosition) + 0.5);
60
                int y = (int)(MAPHEIGHT * relativeY(hightlightPosition) + 0.5);
61
                g.drawArc(x, y, 20, 20, 0, 360);
62
        }
63
 
64
        public static void main(String[] args) {
65
                GPSPosition upperLeft = new GPSPosition();
66
                GPSPosition lowerRight = new GPSPosition();
67
                GPSPosition highlight = new GPSPosition();
68
 
69
                upperLeft.setLatitude((int)(47.327450 * 1E7));
70
                upperLeft.setLongitude((int)(8.521657 * 1E7));
71
 
72
                // * l/r:               geotagged geo:lat=47.321749 geo:lon=8.534403
73
                lowerRight.setLatitude((int)(47.321749 * 1E7));
74
                lowerRight.setLongitude((int)(8.534403 * 1E7));
75
 
76
                // geotagged geo:lat=47.324614 geo:lon=8.528202 
77
                highlight.setLatitude((int)(47.324714 * 1E7));
78
                highlight.setLongitude((int)(8.528102 * 1E7));
79
 
80
                MapImageView v = new MapImageView(upperLeft, lowerRight, "flugplatz_small.png");
81
                v.hightlightPosition = highlight;
82
 
83
                JFrame f = new JFrame();
84
                f.getContentPane().add(v);
85
                f.setSize(v.getSize());
86
                f.setVisible(true);
87
        }
88
}