Rev 1565 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1565 | Rev 1568 | ||
---|---|---|---|
Line 4... | Line 4... | ||
4 | * u/l: geotagged geo:lat=47.327450 geo:lon=8.521657 |
4 | * u/l: geotagged geo:lat=47.327450 geo:lon=8.521657 |
5 | * l/r: geotagged geo:lat=47.321749 geo:lon=8.534403 |
5 | * l/r: geotagged geo:lat=47.321749 geo:lon=8.534403 |
6 | * house: geotagged geo:lat=47.324614 geo:lon=8.528202 |
6 | * house: geotagged geo:lat=47.324614 geo:lon=8.528202 |
7 | */ |
7 | */ |
Line -... | Line 8... | ||
- | 8 | ||
8 | 9 | import java.awt.BasicStroke; |
|
- | 10 | import java.awt.Color; |
|
9 | import java.awt.Color; |
11 | import java.awt.Font; |
- | 12 | import java.awt.Graphics; |
|
10 | import java.awt.Graphics; |
13 | import java.awt.Graphics2D; |
11 | import java.awt.Image; |
14 | import java.awt.Image; |
- | 15 | import java.awt.Toolkit; |
|
- | 16 | import java.util.Formatter; |
|
Line 12... | Line -... | ||
12 | import java.awt.Toolkit; |
- | |
13 | 17 | import java.util.Locale; |
|
Line 14... | Line 18... | ||
14 | import javax.swing.JFrame; |
18 | |
- | 19 | import javax.swing.JPanel; |
|
Line 15... | Line 20... | ||
15 | import javax.swing.JPanel; |
20 | |
16 | 21 | import dongfang.mkt.datatype.GPSPosition; |
|
17 | import dongfang.mkt.datatype.GPSPosition; |
22 | import dongfang.mkt.frames.OSDDataResponseFrame; |
Line 18... | Line 23... | ||
18 | 23 | ||
19 | public class MapImageView extends JPanel { |
24 | public class MapImageView extends JPanel implements OSDDataConsumer { |
Line 20... | Line 25... | ||
20 | private Image mapImage; |
25 | private Image mapImage; |
21 | private Image copterImage; |
26 | private Image copterImage; |
22 | 27 | ||
Line 23... | Line 28... | ||
23 | private static final int MAPWIDTH = 600; |
28 | private static final int MAPWIDTH = (int)(1132); |
- | 29 | private static final int MAPHEIGHT = (int)(977); |
|
Line 24... | Line 30... | ||
24 | private static final int MAPHEIGHT = 400; |
30 | |
25 | 31 | // It is assumed the map is north/south oriented! |
|
26 | // It is assumed the map is north/south oriented! |
32 | private GPSPosition upperLeft; |
27 | private GPSPosition upperLeft; |
33 | private GPSPosition lowerRight; |
28 | private GPSPosition lowerRight; |
- | |
29 | 34 | ||
- | 35 | private GPSPosition copterPosition; |
|
Line 30... | Line 36... | ||
30 | private GPSPosition hightlightPosition; |
36 | private GPSPosition homePosition; |
31 | 37 | ||
32 | public MapImageView(GPSPosition upperLeft, GPSPosition lowerRight, String imageFileName) { |
38 | private int noseDirection; |
33 | setSize(MAPWIDTH, MAPHEIGHT); |
39 | private int flightDirection; |
34 | this.upperLeft = upperLeft; |
40 | private double speed; |
35 | this.lowerRight = lowerRight; |
41 | private double height; |
- | 42 | ||
- | 43 | private static final double degToRadianFactor = 360 / 2 / Math.PI; |
|
36 | mapImage = Toolkit.getDefaultToolkit().getImage(imageFileName); |
44 | |
Line 37... | Line 45... | ||
37 | } |
45 | private double relativeX(GPSPosition pos) { |
38 | 46 | double lon = pos.getLongitude(); |
|
39 | private double relativeX(GPSPosition pos) { |
47 | // The sign should be OK here (positive) both east and west. |
40 | double lon = pos.getLongitude(); |
48 | double span = lowerRight.getLongitude() - upperLeft.getLongitude(); |
41 | // The sign should be OK here (positive) both east and west. |
49 | double offset = lon - upperLeft.getLongitude(); |
42 | double span = lowerRight.getLongitude() - upperLeft.getLongitude(); |
50 | double result = offset / span; |
- | 51 | if (result<0) result = 0; else if(result>1) result=1; |
|
- | 52 | return result; |
|
43 | double offset = lon - upperLeft.getLongitude(); |
53 | } |
Line 44... | Line 54... | ||
44 | return offset / span; |
54 | |
- | 55 | private double relativeY(GPSPosition pos) { |
|
- | 56 | double lat = pos.getLatitude(); |
|
- | 57 | // The sign should be OK here (positive) both east and west. |
|
- | 58 | double span = lowerRight.getLatitude() - upperLeft.getLatitude(); |
|
- | 59 | double offset = lat - upperLeft.getLatitude(); |
|
- | 60 | double result = offset / span; |
|
45 | } |
61 | if (result<0) result = 0; else if(result>1) result=1; |
- | 62 | return result; |
|
46 | 63 | } |
|
- | 64 | ||
- | 65 | public void paintComponent(Graphics g) { |
|
47 | private double relativeY(GPSPosition pos) { |
66 | int size = 32; |
- | 67 | int noseDotSize = 10; |
|
- | 68 | ||
- | 69 | Graphics2D g2d = (Graphics2D)g; |
|
- | 70 | g2d.setStroke(new BasicStroke(5)); |
|
- | 71 | ||
- | 72 | // Draw our Image object. |
|
48 | double lat = pos.getLatitude(); |
73 | |
49 | // The sign should be OK here (positive) both east and west. |
74 | g2d.drawImage(mapImage, 0, 0, MAPWIDTH, MAPHEIGHT, this); // at location |
- | 75 | ||
- | 76 | if (homePosition != null) { |
|
- | 77 | g.setColor(Color.blue); |
|
- | 78 | int x = (int)(MAPWIDTH * relativeX(homePosition) + 0.5); |
|
- | 79 | int y = (int)(MAPHEIGHT * relativeY(homePosition) + 0.5); |
|
- | 80 | g.drawRect(x-size/2, y-size/2, size, size); |
|
- | 81 | } |
|
- | 82 | ||
- | 83 | if (copterPosition != null) { |
|
- | 84 | int x = (int)(MAPWIDTH * relativeX(copterPosition) + 0.5); |
|
- | 85 | int y = (int)(MAPHEIGHT * relativeY(copterPosition) + 0.5); |
|
- | 86 | ||
- | 87 | //g2d.clearRect(x-100, y-100, 200, 200); |
|
- | 88 | ||
- | 89 | double speedfactor = 15; |
|
- | 90 | ||
- | 91 | int speedArrowX = x + (int)(speedfactor * speed * Math.cos((90 - flightDirection) / degToRadianFactor)); |
|
50 | double span = lowerRight.getLatitude() - upperLeft.getLatitude(); |
92 | int speedArrowY = y - (int)(speedfactor * speed * Math.sin((90 - flightDirection) / degToRadianFactor)); |
- | 93 | ||
- | 94 | int noseDotX = x + (int)(size/2 * Math.cos((90 - noseDirection) / degToRadianFactor)); |
|
- | 95 | int noseDotY = y - (int)(size/2 * Math.sin((90 - noseDirection) / degToRadianFactor)); |
|
- | 96 | int noseDotEndX = x + (int)(size * Math.cos((90 - noseDirection) / degToRadianFactor)); |
|
- | 97 | int noseDotEndY = y - (int)(size * Math.sin((90 - noseDirection) / degToRadianFactor)); |
|
- | 98 | ||
- | 99 | g2d.setColor(Color.yellow); |
|
- | 100 | g.drawLine(x, y, speedArrowX, speedArrowY); |
|
- | 101 | ||
- | 102 | g2d.setColor(Color.red); |
|
- | 103 | g.drawArc(x-size/2, y-size/2, size, size, 0, 360); |
|
- | 104 | ||
- | 105 | //g2d.setStroke(new BasicStroke(5)); |
|
- | 106 | g.drawLine(noseDotX, noseDotY, noseDotEndX, noseDotEndY); |
|
- | 107 | ||
- | 108 | String heightFormatString = "%+10.1f"; |
|
51 | double offset = lat - upperLeft.getLatitude(); |
109 | StringBuilder sb = new StringBuilder(); |
Line -... | Line 110... | ||
- | 110 | Formatter formatter = new Formatter(sb, Locale.US); |
|
- | 111 | formatter.format(heightFormatString, height); |
|
- | 112 | ||
- | 113 | g.setColor(Color.green); |
|
- | 114 | Font f = g2d.getFont(); |
|
- | 115 | f = f.deriveFont(18.0f); |
|
- | 116 | f = f.deriveFont(Font.BOLD); |
|
- | 117 | g2d.setFont(f); |
|
- | 118 | g.drawString(sb.toString(), x-120, y); |
|
- | 119 | } |
|
- | 120 | } |
|
- | 121 | ||
52 | return offset / span; |
122 | public void update(OSDDataResponseFrame data, long timestamp) { |
53 | } |
123 | if (data==null) return; |
54 | 124 | copterPosition = data.getCurrentPosition(); |
|
55 | public void paintComponent(Graphics g) { |
- | |
Line -... | Line 125... | ||
- | 125 | homePosition = data.getHomePosition(); |
|
56 | // Draw our Image object. |
126 | speed = data.getGroundSpeed(); |
57 | g.drawImage(mapImage, 0, 0, MAPWIDTH, MAPHEIGHT, this); // at location |
127 | height = data.getHeightByPressure(); |
Line 58... | Line 128... | ||
58 | g.setColor(Color.red); |
128 | noseDirection = data.getCompassHeading(); |
59 | int x = (int)(MAPWIDTH * relativeX(hightlightPosition) + 0.5); |
129 | flightDirection = data.getDirectionOfFlight(); |
60 | int y = (int)(MAPHEIGHT * relativeY(hightlightPosition) + 0.5); |
130 | |
Line 61... | Line 131... | ||
61 | g.drawArc(x, y, 20, 20, 0, 360); |
131 | repaint(); |
62 | } |
132 | } |
63 | 133 | ||
- | 134 | public void init() { |
|
- | 135 | GPSPosition upperLeft = new GPSPosition(); |
|
- | 136 | GPSPosition lowerRight = new GPSPosition(); |
|
- | 137 | ||
- | 138 | /* |
|
- | 139 | upperLeft.setLatitude(47.328355); |
|
- | 140 | upperLeft.setLongitude(8.518231); |
|
Line 64... | Line -... | ||
64 | public static void main(String[] args) { |
- | |
65 | GPSPosition upperLeft = new GPSPosition(); |
141 | |
66 | GPSPosition lowerRight = new GPSPosition(); |
- | |
67 | GPSPosition highlight = new GPSPosition(); |
142 | // * l/r: geotagged geo:lat=47.321749 geo:lon=8.534403 |
68 | 143 | lowerRight.setLatitude(47.321532); |
|
69 | upperLeft.setLatitude(47.327450); |
144 | lowerRight.setLongitude(8.530822); |
70 | upperLeft.setLongitude(8.521657); |
- | |
71 | 145 | |
|
72 | // * l/r: geotagged geo:lat=47.321749 geo:lon=8.534403 |
146 | // geotagged geo:lat=47.324614 geo:lon=8.528202 |