Changeset 23769 in osm for applications/editors
- Timestamp:
- 2010-10-23T20:11:07+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/WayPointHelper.java
r23709 r23769 19 19 import java.util.GregorianCalendar; 20 20 import java.util.List; 21 import java.util.Locale; 21 22 22 23 import org.openstreetmap.josm.data.gpx.WayPoint; … … 27 28 */ 28 29 public class WayPointHelper { 30 public static double METER_TO_FEET = 3.280948; 31 32 /* Countries which use the imperial system instead of the metric system. */ 33 private static String IMPERIAL_SYSTEM_COUNTRIES[] = { 34 "en_US", /* USA */ 35 "en_CA", /* Canada */ 36 "en_GB", /* Great Britain */ 37 "en_AU", /* Australia */ 38 "en_NZ", /* New Zealand */ 39 // "de_DE", /* for testing only */ 40 "en_ZA" /* South Africa */ 41 }; 42 29 43 /** 30 44 * The name of the elevation height of a way point. 31 45 */ 32 46 public static final String HEIGHT_ATTRIBUTE = "ele"; 33 47 48 private static UnitMode unitMode = UnitMode.NotSelected; 49 34 50 private static GeoidCorrectionKind geoidKind = GeoidCorrectionKind.None; 35 51 52 /** 53 * Gets the current mode of GEOID correction. 54 * @return 55 */ 36 56 public static GeoidCorrectionKind getGeoidKind() { 37 57 return geoidKind; … … 41 61 WayPointHelper.geoidKind = geoidKind; 42 62 } 43 44 /** 45 * Gets the elevation (Z coordinate) of a JOSM way point. 63 64 /** 65 * Gets the current unit mode (metric or imperial). 66 * @return 67 */ 68 public static UnitMode getUnitMode() { 69 //TODO: Use this until /JOSM/src/org/openstreetmap/josm/gui/NavigatableComponent.java 70 // has a an appropriate method 71 72 // unit mode already determined? 73 if (unitMode != UnitMode.NotSelected) { 74 return unitMode; 75 } 76 77 // Set default 78 unitMode = UnitMode.Metric; 79 80 // Check if user could prefer imperial system 81 Locale l = Locale.getDefault(); 82 for (int i = 0; i < IMPERIAL_SYSTEM_COUNTRIES.length; i++) { 83 String ctry = l.toString(); 84 if (IMPERIAL_SYSTEM_COUNTRIES[i].equals(ctry)) { 85 unitMode = UnitMode.Imperial; 86 } 87 } 88 89 return unitMode; 90 } 91 92 /** 93 * Gets the unit string for elevation ("m" or "ft"). 94 * @return 95 */ 96 public static String getUnit() { 97 switch (getUnitMode()) { 98 case Metric: 99 return "m"; 100 case Imperial: 101 return "ft"; 102 default: 103 throw new RuntimeException("Invalid or unsupported unit mode: " + unitMode); 104 } 105 } 106 107 /** 108 * Gets the elevation (Z coordinate) of a GPX way point in meter or feet (for 109 * US, UK, ZA, AU, NZ and CA). 46 110 * 47 111 * @param wpt … … 51 115 */ 52 116 public static double getElevation(WayPoint wpt) { 117 double ele = getInternalElevation(wpt); 118 119 if (getUnitMode() == UnitMode.Imperial) { 120 // translate to feet 121 return ele * METER_TO_FEET; 122 } 123 124 return ele; 125 } 126 127 /** 128 * Gets the elevation string for a given elevation, e. g "300m" or "800ft". 129 * @param elevation 130 * @return 131 */ 132 public static String getElevationText(int elevation) { 133 return String.format("%d %s", elevation, getUnit()); 134 } 135 136 /** 137 * Gets the elevation (Z coordinate) of a GPX way point. 138 * 139 * @param wpt 140 * The way point instance. 141 * @return The x coordinate or 0, if the given way point is null or contains 142 * not height attribute. 143 */ 144 private static double getInternalElevation(WayPoint wpt) { 53 145 if (wpt != null) { 54 146 if (!wpt.attr.containsKey(HEIGHT_ATTRIBUTE)) { -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/DefaultElevationProfileRenderer.java
r23764 r23769 194 194 195 195 if (kind == ElevationWayPointKind.ElevationLevelGain) { 196 drawLabelWithTriangle( String.format("%dm",ele), pnt.x, pnt.y196 drawLabelWithTriangle(WayPointHelper.getElevationText(ele), pnt.x, pnt.y 197 197 + g.getFontMetrics().getHeight(), g, c, 8, 198 198 getColorForWaypoint(profile, wpt, ElevationWayPointKind.ElevationGain), … … 201 201 202 202 if (kind == ElevationWayPointKind.ElevationLevelLoss) { 203 drawLabelWithTriangle( String.format("%dm", ele), pnt.x, pnt.y204 + g.getFontMetrics().getHeight(), g, c, 8,203 drawLabelWithTriangle(WayPointHelper.getElevationText(ele), 204 pnt.x, pnt.y+ g.getFontMetrics().getHeight(), g, c, 8, 205 205 getColorForWaypoint(profile, wpt, ElevationWayPointKind.ElevationLoss), 206 206 TriangleDir.Down); … … 214 214 drawLabel(String.format("%02d:%02d", hour, min), pnt.x, pnt.y 215 215 - g.getFontMetrics().getHeight() - 5, g); 216 drawLabel( String.format("%dm",eleH), pnt.x, pnt.y216 drawLabel(WayPointHelper.getElevationText(eleH), pnt.x, pnt.y 217 217 + g.getFontMetrics().getHeight() + 5, g); 218 218 } … … 262 262 DefaultElevationProfileRenderer.TRIANGLE_BASESIZE); 263 263 264 drawLabel( String.format("%dm",eleH), pnt.x, pnt.y264 drawLabel(WayPointHelper.getElevationText(eleH), pnt.x, pnt.y 265 265 + g.getFontMetrics().getHeight(), g, c); 266 266 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileDialog.java
r23762 r23769 292 292 // Show elevation data 293 293 minHeightLabel.setText( 294 NavigatableComponent.getSystemOfMeasurement().getDistText(profile.getMinHeight()));294 WayPointHelper.getElevationText(profile.getMinHeight())); 295 295 maxHeightLabel.setText( 296 NavigatableComponent.getSystemOfMeasurement().getDistText(profile.getMaxHeight()));296 WayPointHelper.getElevationText(profile.getMaxHeight())); 297 297 avrgHeightLabel.setText( 298 NavigatableComponent.getSystemOfMeasurement().getDistText(profile.getAverageHeight()));298 WayPointHelper.getElevationText(profile.getAverageHeight())); 299 299 elevationGainLabel.setText( 300 NavigatableComponent.getSystemOfMeasurement().getDistText(profile.getGain()));300 WayPointHelper.getElevationText(profile.getGain())); 301 301 } 302 302 -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfilePanel.java
r23764 r23769 231 231 * @param g The graphics context. 232 232 * @return The resulting rectangle of the drawn string. 233 */233 234 234 private void drawHCenteredString(String s, int x, int y, Graphics g) { 235 235 drawAlignedString(s, x, y, TextAlignment.Centered, g); 236 } 236 }*/ 237 237 238 238 /** … … 269 269 // check bounds 270 270 if (yLine <= getPlotBottom() && yLine >= getPlotTop()) { 271 String txt = String.format("%dm",i);271 String txt = WayPointHelper.getElevationText(i); 272 272 273 273 Rectangle r = drawAlignedString(txt, getPlotHCenter(), yLine - 2,
Note:
See TracChangeset
for help on using the changeset viewer.