Changeset 23769 in osm


Ignore:
Timestamp:
2010-10-23T20:11:07+02:00 (14 years ago)
Author:
oliverw
Message:

Support also elevation values in feet.

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  
    1919import java.util.GregorianCalendar;
    2020import java.util.List;
     21import java.util.Locale;
    2122
    2223import org.openstreetmap.josm.data.gpx.WayPoint;
     
    2728 */
    2829public 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       
    2943        /**
    3044         * The name of the elevation height of a way point.
    3145         */
    3246        public static final String HEIGHT_ATTRIBUTE = "ele";
    33 
     47       
     48        private static UnitMode unitMode = UnitMode.NotSelected;
     49               
    3450        private static GeoidCorrectionKind geoidKind = GeoidCorrectionKind.None;
    3551
     52        /**
     53         * Gets the current mode of GEOID correction.
     54         * @return
     55         */
    3656        public static GeoidCorrectionKind getGeoidKind() {
    3757                return geoidKind;
     
    4161                WayPointHelper.geoidKind = geoidKind;
    4262        }
    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).
    46110         *
    47111         * @param wpt
     
    51115         */
    52116        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) {
    53145                if (wpt != null) {
    54146                        if (!wpt.attr.containsKey(HEIGHT_ATTRIBUTE)) {
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/DefaultElevationProfileRenderer.java

    r23764 r23769  
    194194
    195195                if (kind == ElevationWayPointKind.ElevationLevelGain) {
    196                         drawLabelWithTriangle(String.format("%dm", ele), pnt.x, pnt.y
     196                        drawLabelWithTriangle(WayPointHelper.getElevationText(ele), pnt.x, pnt.y
    197197                                        + g.getFontMetrics().getHeight(), g, c, 8,
    198198                                        getColorForWaypoint(profile, wpt, ElevationWayPointKind.ElevationGain),
     
    201201               
    202202                if (kind == ElevationWayPointKind.ElevationLevelLoss) {
    203                         drawLabelWithTriangle(String.format("%dm", ele), pnt.x, pnt.y
    204                                         + g.getFontMetrics().getHeight(), g, c, 8,
     203                        drawLabelWithTriangle(WayPointHelper.getElevationText(ele),
     204                                        pnt.x, pnt.y+ g.getFontMetrics().getHeight(), g, c, 8,
    205205                                        getColorForWaypoint(profile, wpt, ElevationWayPointKind.ElevationLoss),
    206206                                        TriangleDir.Down);
     
    214214                        drawLabel(String.format("%02d:%02d", hour, min), pnt.x, pnt.y
    215215                                        - g.getFontMetrics().getHeight() - 5, g);
    216                         drawLabel(String.format("%dm", eleH), pnt.x, pnt.y
     216                        drawLabel(WayPointHelper.getElevationText(eleH), pnt.x, pnt.y
    217217                                        + g.getFontMetrics().getHeight() + 5, g);
    218218                }
     
    262262                                DefaultElevationProfileRenderer.TRIANGLE_BASESIZE);
    263263
    264                 drawLabel(String.format("%dm", eleH), pnt.x, pnt.y
     264                drawLabel(WayPointHelper.getElevationText(eleH), pnt.x, pnt.y
    265265                                + g.getFontMetrics().getHeight(), g, c);
    266266        }
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileDialog.java

    r23762 r23769  
    292292                        // Show elevation data
    293293                        minHeightLabel.setText(
    294                                         NavigatableComponent.getSystemOfMeasurement().getDistText(profile.getMinHeight()));
     294                                        WayPointHelper.getElevationText(profile.getMinHeight()));
    295295                        maxHeightLabel.setText(
    296                                         NavigatableComponent.getSystemOfMeasurement().getDistText(profile.getMaxHeight()));
     296                                        WayPointHelper.getElevationText(profile.getMaxHeight()));
    297297                        avrgHeightLabel.setText(
    298                                         NavigatableComponent.getSystemOfMeasurement().getDistText(profile.getAverageHeight()));
     298                                        WayPointHelper.getElevationText(profile.getAverageHeight()));
    299299                        elevationGainLabel.setText(
    300                                         NavigatableComponent.getSystemOfMeasurement().getDistText(profile.getGain()));
     300                                        WayPointHelper.getElevationText(profile.getGain()));
    301301                        }
    302302                       
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfilePanel.java

    r23764 r23769  
    231231         * @param g The graphics context.
    232232         * @return The resulting rectangle of the drawn string.
    233          */
     233         
    234234        private void drawHCenteredString(String s, int x, int y, Graphics g) {
    235235                drawAlignedString(s, x, y, TextAlignment.Centered, g);
    236         }
     236        }*/
    237237
    238238        /**
     
    269269                        // check bounds
    270270                        if (yLine <= getPlotBottom() && yLine >= getPlotTop()) {
    271                                 String txt = String.format("%dm", i);
     271                                String txt = WayPointHelper.getElevationText(i);
    272272                               
    273273                                Rectangle r = drawAlignedString(txt, getPlotHCenter(), yLine - 2,
Note: See TracChangeset for help on using the changeset viewer.