Changeset 29874 in osm
- Timestamp:
- 2013-08-25T16:26:09+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/ElevationProfile
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ElevationProfile/build.xml
r29873 r29874 4 4 <property name="commit.message" value=""/> 5 5 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 6 <property name="plugin.main.version" value="61 15"/>6 <property name="plugin.main.version" value="6162"/> 7 7 8 8 <!-- Configure these properties (replace "..." accordingly). -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationProfilePlugin.java
r29611 r29874 29 29 */ 30 30 public class ElevationProfilePlugin extends Plugin { 31 32 private ElevationMapMode eleMode;33 private IconToggleButton eleModeButton;34 private static ElevationProfileLayer currentLayer;35 31 36 /** 37 * Initializes the plugin. 38 * @param info Context information about the plugin. 39 */ 40 public ElevationProfilePlugin(PluginInformation info) { 41 super(info); 32 private ElevationMapMode eleMode; 33 private IconToggleButton eleModeButton; 34 private static ElevationProfileLayer currentLayer; 42 35 43 try { 44 eleMode = new ElevationMapMode("Elevation profile", Main.map); 45 eleModeButton = new IconToggleButton(eleMode); 46 } catch (Exception e1) { 47 System.err.println("Init of ElevationProfilePlugin failed: " + e1); 48 e1.printStackTrace(); 49 } 36 /** 37 * Initializes the plugin. 38 * @param info Context information about the plugin. 39 */ 40 public ElevationProfilePlugin(PluginInformation info) { 41 super(info); 42 43 try { 44 eleMode = new ElevationMapMode("Elevation profile", Main.map); 45 eleModeButton = new IconToggleButton(eleMode); 46 } catch (Exception e1) { 47 System.err.println("Init of ElevationProfilePlugin failed: " + e1); 48 e1.printStackTrace(); 50 49 } 51 52 /** 50 } 51 52 /** 53 53 * Called after Main.mapFrame is initialized. (After the first data is loaded). 54 54 * You can use this callback to tweak the newFrame to your needs, as example install 55 55 * an alternative Painter. 56 56 */ 57 @Override 58 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 59 super.mapFrameInitialized(oldFrame, newFrame); 60 61 if (newFrame != null) { 62 newFrame.addMapMode(eleModeButton); 63 ElevationProfileDialog eleProfileDlg = new ElevationProfileDialog(); 64 eleProfileDlg.addModelListener(eleMode); 65 eleProfileDlg.setProfileLayer(getCurrentLayer()); 66 newFrame.addToggleDialog(eleProfileDlg); 67 } 57 @Override 58 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 59 super.mapFrameInitialized(oldFrame, newFrame); 60 61 if (newFrame != null) { 62 newFrame.addMapMode(eleModeButton); 63 ElevationProfileDialog eleProfileDlg = new ElevationProfileDialog(); 64 eleProfileDlg.addModelListener(eleMode); 65 eleProfileDlg.setProfileLayer(getCurrentLayer()); 66 newFrame.addToggleDialog(eleProfileDlg); 68 67 } 69 70 /** 71 * Gets the elevation profile layer which decorates the current layer 72 * with some markers. 73 * @return 74 */ 75 public static ElevationProfileLayer getCurrentLayer(){ 76 if(currentLayer == null){ 77 currentLayer = new ElevationProfileLayer("Elevation profile"); 78 Main.main.addLayer(currentLayer); 79 } 80 return currentLayer; 68 } 69 70 /** 71 * Gets the elevation profile layer which decorates the current layer 72 * with some markers. 73 * @return 74 */ 75 public static ElevationProfileLayer getCurrentLayer(){ 76 if(currentLayer == null){ 77 currentLayer = new ElevationProfileLayer("Elevation profile"); 78 Main.main.addLayer(currentLayer); 81 79 } 80 return currentLayer; 81 } 82 82 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationWayPointKind.java
r23795 r29874 20 20 */ 21 21 public enum ElevationWayPointKind { 22 Plain, // Simple way point 23 Highlighted, // Highlighted waypoint22 Plain, // Simple way point (equal to no or low slope) 23 Highlighted, // Highlighted waypoint 24 24 StartPoint, // First way point 25 25 EndPoint, // Last way point 26 MaxElevation, // Highest way point 27 MinElevation, // Lowest way point 28 ElevationGain, // Elevation gain 29 ElevationLoss, // Elevation loss 26 MaxElevation, // Highest way point 27 MinElevation, // Lowest way point 28 ElevationGainHigh, // Elevation gain (high slope 15-25%) 29 ElevationLossHigh, // Elevation loss (high downward slope) 30 ElevationGainLow, // Elevation gain (low slope, 5-14.9%) 31 ElevationLossLow, // Elevation loss (low downward slope) 30 32 ElevationLevelGain, // Elevation level gain (e. g. crossed 300m from lower elevation) 31 33 ElevationLevelLoss, // Elevation level (e. g. crossed 300m from higher elevation) -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/WayPointHelper.java
r29183 r29874 119 119 if (getUnitMode() == UnitMode.Imperial) { 120 120 // translate to feet 121 return ele * METER_TO_FEET;121 return meter2Feet(ele); 122 122 } 123 123 124 124 return ele; 125 } 126 127 /** 128 * Computes the slope <b>in percent</b> between two way points. E. g. an elevation gain of 12m 129 * within a distance of 100m is equal to a slope of 12%. 130 * 131 * @param w1 the first way point 132 * @param w2 the second way point 133 * @return the slope in percent 134 */ 135 public static double computeSlope(WayPoint w1, WayPoint w2) { 136 // same coordinates? -> return 0, if yes 137 if (w1.getCoor().equals(w2.getCoor())) return 0; 138 139 // get distance in meters and divide it by 100 in advance 140 double distInMeter = w1.getCoor().greatCircleDistance(w2.getCoor()) / 100.0; 141 142 // convert to feet? 143 if (getUnitMode() == UnitMode.Imperial) { 144 distInMeter = meter2Feet(distInMeter); 145 } 146 147 // get elevation (difference) - is converted automatically to feet 148 int ele1 = (int) WayPointHelper.getElevation(w1); 149 int ele2 = (int) WayPointHelper.getElevation(w2); 150 int dH = ele2 - ele1; 151 152 // Slope in percent is define as elevation gain/loss in meters related to a distance of 100m 153 return dH / distInMeter; 154 } 155 156 /** 157 * Converts meter into feet 158 * 159 * @param meter the meter 160 * @return the double 161 */ 162 public static double meter2Feet(double meter) { 163 return meter * METER_TO_FEET; 125 164 } 126 165 -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/DefaultElevationProfileRenderer.java
r28149 r29874 52 52 * 53 53 */ 54 private static final int BASIC_WPT_RADIUS = 2;54 private static final int BASIC_WPT_RADIUS = 3; 55 55 private static final int REGULAR_WPT_RADIUS = BASIC_WPT_RADIUS * 4; 56 56 private static final int BIG_WPT_RADIUS = BASIC_WPT_RADIUS * 10; … … 92 92 switch (kind) { 93 93 case Plain: 94 return Color.LIGHT_GRAY; 94 95 case ElevationLevelLoss: 95 96 case ElevationLevelGain: … … 101 102 case Highlighted: 102 103 return Color.ORANGE; 103 case ElevationGain: 104 return Color.GREEN; 105 case ElevationLoss: 106 return Color.RED; 104 case ElevationGainHigh: 105 return Color.getHSBColor(0.3f, 1.0f, 1.0f); // green 106 case ElevationLossHigh: 107 return Color.getHSBColor(0, 1.0f, 1.0f); // red 108 case ElevationGainLow: 109 return Color.getHSBColor(0.3f, 0.5f, 1.0f); // green with low sat 110 case ElevationLossLow: 111 return Color.getHSBColor(0, 0.5f, 1.0f); // red with low sat 107 112 case FullHour: 108 113 return MARKER_POINT; … … 116 121 case EndPoint: 117 122 return END_POINT; 123 default: 124 break; 118 125 } 119 126 … … 202 209 drawLabelWithTriangle(WayPointHelper.getElevationText(ele), pnt.x, pnt.y 203 210 + g.getFontMetrics().getHeight(), g, c, 8, 204 getColorForWaypoint(profile, wpt, ElevationWayPointKind.ElevationGain ),211 getColorForWaypoint(profile, wpt, ElevationWayPointKind.ElevationGainHigh), 205 212 TriangleDir.Up); 206 213 } … … 209 216 drawLabelWithTriangle(WayPointHelper.getElevationText(ele), 210 217 pnt.x, pnt.y+ g.getFontMetrics().getHeight(), g, c, 8, 211 getColorForWaypoint(profile, wpt, ElevationWayPointKind.ElevationLoss ),218 getColorForWaypoint(profile, wpt, ElevationWayPointKind.ElevationLossHigh), 212 219 TriangleDir.Down); 213 220 } … … 392 399 - (radius * 0.6f)); 393 400 float[] dist = { 0.1f, 0.2f, 1.0f }; 394 Color[] colors = { firstCol, secondCol, Color. BLACK};401 Color[] colors = { firstCol, secondCol, Color.DARK_GRAY }; 395 402 RadialGradientPaint p = new RadialGradientPaint(center, radius, focus, 396 403 dist, colors, CycleMethod.NO_CYCLE); -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileLayer.java
r28149 r29874 43 43 public class ElevationProfileLayer extends 44 44 org.openstreetmap.josm.gui.layer.Layer implements IElevationProfileSelectionListener { 45 private static final double Level_Factor = 100.0; 46 private IElevationProfile profile; 47 private IElevationProfileRenderer renderer = new DefaultElevationProfileRenderer(); 48 private WayPoint selWayPoint = null; 49 50 /** 51 * Creates a new elevation profile layer 52 * 53 * @param name 54 * The name of the layer. 55 */ 56 public ElevationProfileLayer(String name) { 57 super(name); 45 private static final double Level_Factor = 100.0; 46 private IElevationProfile profile; 47 private IElevationProfileRenderer renderer = new DefaultElevationProfileRenderer(); 48 private WayPoint selWayPoint = null; 49 50 /** 51 * Creates a new elevation profile layer 52 * 53 * @param name 54 * The name of the layer. 55 */ 56 public ElevationProfileLayer(String name) { 57 super(name); 58 } 59 60 /** 61 * Gets the current elevation profile shown in this layer. 62 * 63 * @return 64 */ 65 public IElevationProfile getProfile() { 66 return profile; 67 } 68 69 /** 70 * Sets the current elevation profile shown in this layer. 71 * 72 * @param profile 73 * The profile to show in the layer 74 */ 75 public void setProfile(IElevationProfile profile) { 76 this.profile = profile; 77 Main.map.repaint(); 78 } 79 80 /* 81 * (non-Javadoc) 82 * 83 * @see org.openstreetmap.josm.gui.layer.Layer#getIcon() 84 */ 85 @Override 86 public Icon getIcon() { 87 return ImageProvider.get("layer", "elevation_small"); 88 } 89 90 /* 91 * (non-Javadoc) 92 * 93 * @see org.openstreetmap.josm.gui.layer.Layer#getInfoComponent() 94 */ 95 @Override 96 public Object getInfoComponent() { 97 return getToolTipText(); 98 } 99 100 /* 101 * (non-Javadoc) 102 * 103 * @see org.openstreetmap.josm.gui.layer.Layer#getMenuEntries() 104 */ 105 @Override 106 public Action[] getMenuEntries() { 107 // TODO: More entries??? 108 return new Action[] { new LayerListPopup.InfoAction(this) }; 109 } 110 111 /* 112 * (non-Javadoc) 113 * 114 * @see org.openstreetmap.josm.gui.layer.Layer#getToolTipText() 115 */ 116 @Override 117 public String getToolTipText() { 118 if (profile != null) { 119 return tr("Elevation profile for track ''{0}''.", profile.getName()); 120 } else { 121 return tr("Elevation profile"); 58 122 } 59 60 /** 61 * Gets the current elevation profile shown in this layer. 62 * 63 * @return 64 */ 65 public IElevationProfile getProfile() { 66 return profile; 123 } 124 125 /* 126 * (non-Javadoc) 127 * 128 * @see 129 * org.openstreetmap.josm.gui.layer.Layer#isMergable(org.openstreetmap.josm 130 * .gui.layer.Layer) 131 */ 132 @Override 133 public boolean isMergable(Layer other) { 134 return false; 135 } 136 137 /* 138 * (non-Javadoc) 139 * 140 * @see 141 * org.openstreetmap.josm.gui.layer.Layer#mergeFrom(org.openstreetmap.josm 142 * .gui.layer.Layer) 143 */ 144 @Override 145 public void mergeFrom(Layer from) { 146 // nothing to do 147 } 148 149 /* 150 * (non-Javadoc) 151 * 152 * @see org.openstreetmap.josm.gui.layer.Layer#paint(java.awt.Graphics2D, 153 * org.openstreetmap.josm.gui.MapView, org.openstreetmap.josm.data.Bounds) 154 */ 155 @Override 156 public void paint(Graphics2D g, MapView mv, Bounds box) { 157 WayPoint lastWpt = null; 158 int lastEle = 0; 159 160 renderer.beginRendering(); 161 if (profile != null) { 162 // paint way points one by one 163 for (WayPoint wpt : profile.getWayPoints()) { 164 165 166 if (lastWpt != null) { 167 // determine way point 168 ElevationWayPointKind kind = classifyWayPoint(lastWpt, wpt); 169 170 // render way point 171 renderer.renderWayPoint(g, profile, mv, wpt, kind); 172 } // else first way point -> is paint later 173 174 // remember some things for next iteration 175 lastEle = (int) WayPointHelper.getElevation(wpt); 176 lastWpt = wpt; 177 } 178 179 // now we paint special way points in emphasized style 180 181 // paint selected way point, if available 182 if (selWayPoint != null) { 183 renderer.renderWayPoint(g, profile, mv, selWayPoint, 184 ElevationWayPointKind.Highlighted); 185 } 186 187 // paint start/end 188 renderer.renderWayPoint(g, profile, mv, profile.getStartWayPoint(), 189 ElevationWayPointKind.StartPoint); 190 renderer.renderWayPoint(g, profile, mv, profile.getEndWayPoint(), 191 ElevationWayPointKind.EndPoint); 192 // paint min/max 193 renderer.renderWayPoint(g, profile, mv, profile.getMaxWayPoint(), 194 ElevationWayPointKind.MaxElevation); 195 renderer.renderWayPoint(g, profile, mv, profile.getMinWayPoint(), 196 ElevationWayPointKind.MinElevation); 197 } 198 199 renderer.finishRendering(); 200 } 201 202 /** 203 * Checks if the given way point requires special decoration (e. g. elevation gain/loss or level crossing). 204 * 205 * Parameters <tt>ele1</tt> and <tt>ele2</tt> point are used for detecting "level crossings", 206 * e. g. 1 to 2 indicate that we crossed the 200m elevation in upward direction 207 * 208 * @param lastWpt the last way point 209 * @param actWpt the actual way point 210 * @return the elevation way point kind 211 */ 212 private ElevationWayPointKind classifyWayPoint(WayPoint lastWpt, WayPoint actWpt) { 213 // get elevation values 214 int actEle = (int) WayPointHelper.getElevation(actWpt); 215 int lastEle = (int) WayPointHelper.getElevation(lastWpt); 216 217 // normalize elevation to levels 218 int actLevel = (int)(actEle / Level_Factor); 219 int lastLevel = (int)(lastEle / Level_Factor); 220 double slope = Math.abs(WayPointHelper.computeSlope(lastWpt, actWpt)); 221 222 // plain way point by default 223 ElevationWayPointKind kind = ElevationWayPointKind.Plain; 224 System.out.println("Slope: " + slope + "%"); 225 226 // check, if we passed an elevation level 227 // We assume, that we cannot pass more than one levels between two way points ;-) 228 if (actLevel != lastLevel && Math.abs(actLevel - lastLevel) == 1) { 229 if (actLevel > lastLevel) { // we went down? 230 kind =ElevationWayPointKind.ElevationLevelGain; 231 } else { 232 kind =ElevationWayPointKind.ElevationLevelLoss; 233 } 234 } else { // check for elevation gain or loss 235 if (actEle > lastEle) { // we went uphill? 236 // TODO: Provide parameters for high/low thresholds 237 if (slope > 3) kind =ElevationWayPointKind.ElevationGainLow; 238 if (slope > 10) kind =ElevationWayPointKind.ElevationGainHigh; 239 } else { 240 if (slope > 3) kind =ElevationWayPointKind.ElevationLossLow; 241 if (slope > 10) kind =ElevationWayPointKind.ElevationLossHigh; 242 } 67 243 } 68 69 /** 70 * Sets the current elevation profile shown in this layer. 71 * 72 * @param profile 73 * The profile to show in the layer 74 */ 75 public void setProfile(IElevationProfile profile) { 76 this.profile = profile; 77 Main.map.repaint(); 244 return kind; 245 } 246 247 /* 248 * (non-Javadoc) 249 * 250 * @see 251 * org.openstreetmap.josm.gui.layer.Layer#visitBoundingBox(org.openstreetmap 252 * .josm.data.osm.visitor.BoundingXYVisitor) 253 */ 254 @Override 255 public void visitBoundingBox(BoundingXYVisitor v) { 256 // TODO Auto-generated method stub 257 } 258 259 @Override 260 public void selectedWayPointChanged(WayPoint newWayPoint) { 261 if (selWayPoint != newWayPoint) { 262 selWayPoint = newWayPoint; 263 Main.map.repaint(); 78 264 } 79 80 /* 81 * (non-Javadoc) 82 * 83 * @see org.openstreetmap.josm.gui.layer.Layer#getIcon() 84 */ 85 @Override 86 public Icon getIcon() { 87 return ImageProvider.get("layer", "elevation_small"); 88 } 89 90 /* 91 * (non-Javadoc) 92 * 93 * @see org.openstreetmap.josm.gui.layer.Layer#getInfoComponent() 94 */ 95 @Override 96 public Object getInfoComponent() { 97 return getToolTipText(); 98 } 99 100 /* 101 * (non-Javadoc) 102 * 103 * @see org.openstreetmap.josm.gui.layer.Layer#getMenuEntries() 104 */ 105 @Override 106 public Action[] getMenuEntries() { 107 // TODO: More entries??? 108 return new Action[] { new LayerListPopup.InfoAction(this) }; 109 } 110 111 /* 112 * (non-Javadoc) 113 * 114 * @see org.openstreetmap.josm.gui.layer.Layer#getToolTipText() 115 */ 116 @Override 117 public String getToolTipText() { 118 if (profile != null) { 119 return tr("Elevation profile for track ''{0}''.", profile.getName()); 120 } else { 121 return tr("Elevation profile"); 122 } 123 } 124 125 /* 126 * (non-Javadoc) 127 * 128 * @see 129 * org.openstreetmap.josm.gui.layer.Layer#isMergable(org.openstreetmap.josm 130 * .gui.layer.Layer) 131 */ 132 @Override 133 public boolean isMergable(Layer other) { 134 return false; 135 } 136 137 /* 138 * (non-Javadoc) 139 * 140 * @see 141 * org.openstreetmap.josm.gui.layer.Layer#mergeFrom(org.openstreetmap.josm 142 * .gui.layer.Layer) 143 */ 144 @Override 145 public void mergeFrom(Layer from) { 146 // nothing to do 147 } 148 149 /* 150 * (non-Javadoc) 151 * 152 * @see org.openstreetmap.josm.gui.layer.Layer#paint(java.awt.Graphics2D, 153 * org.openstreetmap.josm.gui.MapView, org.openstreetmap.josm.data.Bounds) 154 */ 155 @Override 156 public void paint(Graphics2D g, MapView mv, Bounds box) { 157 WayPoint lastWpt = null; 158 int lastEle = 0; 159 160 renderer.beginRendering(); 161 if (profile != null) { 162 // paint way points one by one 163 for (WayPoint wpt : profile.getWayPoints()) { 164 int ele = (int) WayPointHelper.getElevation(wpt); 165 166 if (lastWpt != null) { 167 // normalize to levels 168 int ele1 = (int)(ele / Level_Factor); 169 int ele2 = (int)(lastEle / Level_Factor); 170 171 // plain way point by default 172 ElevationWayPointKind kind = ElevationWayPointKind.Plain; 173 // check, if we passed an elevation level 174 // We assume, that we cannot pass more than one levels between two way points ;-) 175 if (ele1 != ele2 && Math.abs(ele1 - ele2) == 1) { 176 if (ele1 > ele2) { // we went down? 177 kind =ElevationWayPointKind.ElevationLevelGain; 178 } else { 179 kind =ElevationWayPointKind.ElevationLevelLoss; 180 } 181 } else { // check for elevation gain or loss 182 if (ele > lastEle) { // we went down? 183 kind =ElevationWayPointKind.ElevationGain; 184 } else { 185 kind =ElevationWayPointKind.ElevationLoss; 186 } 187 } 188 189 // render way point 190 renderer.renderWayPoint(g, profile, mv, wpt, kind); 191 } 192 193 // remember some things for next iteration 194 lastEle = (int) WayPointHelper.getElevation(wpt); 195 lastWpt = wpt; 196 } 197 198 // now we paint special way points in emphasized style 199 200 // paint selected way point, if available 201 if (selWayPoint != null) { 202 renderer.renderWayPoint(g, profile, mv, selWayPoint, 203 ElevationWayPointKind.Highlighted); 204 } 205 206 // paint start/end 207 renderer.renderWayPoint(g, profile, mv, profile.getStartWayPoint(), 208 ElevationWayPointKind.StartPoint); 209 renderer.renderWayPoint(g, profile, mv, profile.getEndWayPoint(), 210 ElevationWayPointKind.EndPoint); 211 // paint min/max 212 renderer.renderWayPoint(g, profile, mv, profile.getMaxWayPoint(), 213 ElevationWayPointKind.MaxElevation); 214 renderer.renderWayPoint(g, profile, mv, profile.getMinWayPoint(), 215 ElevationWayPointKind.MinElevation); 216 } 217 218 renderer.finishRendering(); 219 } 220 221 /* 222 * (non-Javadoc) 223 * 224 * @see 225 * org.openstreetmap.josm.gui.layer.Layer#visitBoundingBox(org.openstreetmap 226 * .josm.data.osm.visitor.BoundingXYVisitor) 227 */ 228 @Override 229 public void visitBoundingBox(BoundingXYVisitor v) { 230 // TODO Auto-generated method stub 231 } 232 233 @Override 234 public void selectedWayPointChanged(WayPoint newWayPoint) { 235 if (selWayPoint != newWayPoint) { 236 selWayPoint = newWayPoint; 237 Main.map.repaint(); 238 } 239 } 265 } 240 266 241 267 }
Note:
See TracChangeset
for help on using the changeset viewer.