Changeset 33420 in osm for applications/editors
- Timestamp:
- 2017-06-30T09:17:07+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/livegps/src/livegps
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsLayer.java
r33138 r33420 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Color;7 import java.awt.Graphics2D;8 import java.awt.Point;9 6 import java.awt.Rectangle; 10 7 import java.awt.geom.Point2D; … … 22 19 import org.openstreetmap.josm.data.gpx.GpxTrack; 23 20 import org.openstreetmap.josm.data.gpx.WayPoint; 24 import org.openstreetmap.josm.data.preferences.CachingProperty;25 import org.openstreetmap.josm.data.preferences.ColorProperty;26 import org.openstreetmap.josm.gui.MapView;27 21 import org.openstreetmap.josm.gui.layer.GpxLayer; 28 22 29 23 public class LiveGpsLayer extends GpxLayer implements PropertyChangeListener { 30 24 public static final String LAYER_NAME = tr("LiveGPS layer"); 31 public static final String C_LIVEGPS_COLOR_POSITION = "color.livegps.position";32 public static final String C_LIVEGPS_COLOR_POSITION_ESTIMATE = "color.livegps.position_estimate";33 34 private static final CachingProperty<Color> COLOR_POSITION =35 new ColorProperty(C_LIVEGPS_COLOR_POSITION, Color.RED).cached();36 private static final CachingProperty<Color> COLOR_POSITION_ESTIMATE =37 new ColorProperty(C_LIVEGPS_COLOR_POSITION_ESTIMATE, Color.CYAN).cached();38 25 39 26 private static final int DEFAULT_REFRESH_INTERVAL = 250; … … 44 31 private static final String C_CENTER_INTERVAL = "livegps.center_interval_msec"; /* in msec */ 45 32 private static final String C_CENTER_FACTOR = "livegps.center_factor" /* in percent */; 46 private static final String C_CURSOR_H = "livegps.cursor_height"; /* in pixels */47 private static final String C_CURSOR_W = "livegps.cursor_width"; /* in pixels */48 private static final String C_CURSOR_T = "livegps.cursor_thickness"; /* in pixels */49 33 private int refreshInterval; 50 34 private int centerInterval; … … 71 55 72 56 initIntervals(); 57 } 58 59 @Override 60 protected LayerPainter createMapViewPainter(MapViewEvent event) { 61 return new LiveGpsDrawHelper(this); 73 62 } 74 63 … … 110 99 public void setAutoCenter(boolean ac) { 111 100 autocenter = ac; 112 }113 114 @Override115 public void paint(Graphics2D g, MapView mv, Bounds bounds) {116 super.paint(g, mv, bounds);117 118 if (lastPoint == null)119 return;120 121 Point screen = mv.getPoint(lastPoint.getCoor());122 123 int TriaHeight = Main.pref.getInteger(C_CURSOR_H, 20);124 int TriaWidth = Main.pref.getInteger(C_CURSOR_W, 10);125 int TriaThick = Main.pref.getInteger(C_CURSOR_T, 4);126 127 /*128 * Draw a bold triangle.129 * In case of deep zoom draw also a thin DOP oval.130 */131 132 g.setColor(COLOR_POSITION_ESTIMATE.get());133 int w, h;134 double ppm = 100 / mv.getDist100Pixel(); /* pixels per metre */135 136 w = (int) Math.round(lastData.getEpx() * ppm);137 h = (int) Math.round(lastData.getEpy() * ppm);138 139 if (w > TriaWidth || h > TriaWidth) {140 int xo, yo;141 142 yo = screen.y - Math.round(h/2);143 xo = screen.x - Math.round(w/2);144 145 g.drawOval(xo, yo, w, h);146 }147 148 int[] x = new int[4];149 int[] y = new int[4];150 float course = lastData.getCourse();151 float csin = (float) Math.sin(Math.toRadians(course));152 float ccos = (float) Math.cos(Math.toRadians(course));153 float csin120 = (float) Math.sin(Math.toRadians(course + 120));154 float ccos120 = (float) Math.cos(Math.toRadians(course + 120));155 float csin240 = (float) Math.sin(Math.toRadians(course + 240));156 float ccos240 = (float) Math.cos(Math.toRadians(course + 240));157 158 g.setColor(COLOR_POSITION.get());159 160 for (int i = 0; i < TriaThick; i++, TriaHeight--, TriaWidth--) {161 162 x[0] = screen.x + Math.round(TriaHeight * csin);163 y[0] = screen.y - Math.round(TriaHeight * ccos);164 x[1] = screen.x + Math.round(TriaWidth * csin120);165 y[1] = screen.y - Math.round(TriaWidth * ccos120);166 x[2] = screen.x;167 y[2] = screen.y;168 x[3] = screen.x + Math.round(TriaWidth * csin240);169 y[3] = screen.y - Math.round(TriaWidth * ccos240);170 171 g.drawPolygon(x, y, 4);172 }173 174 101 } 175 102
Note:
See TracChangeset
for help on using the changeset viewer.