Changeset 32313 in osm for applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap
- Timestamp:
- 2016-06-18T23:35:48+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationProfilePlugin.java
r30344 r32313 7 7 8 8 import org.openstreetmap.josm.Main; 9 import org.openstreetmap.josm.actions.JosmAction;10 9 import org.openstreetmap.josm.gui.IconToggleButton; 11 10 import org.openstreetmap.josm.gui.MainMenu; … … 20 19 * Plugin class for displaying an elevation profile of the tracks. 21 20 * @author Oliver Wieland <oliver.wieland@online.de> 22 * 21 * 23 22 */ 24 23 public class ElevationProfilePlugin extends Plugin { 25 24 26 private ElevationMapMode eleMode; 27 private IconToggleButton eleModeButton; 28 private static ElevationProfileLayer currentLayer; 25 private static ElevationProfileLayer currentLayer; 29 26 30 31 32 33 34 35 27 /** 28 * Initializes the plugin. 29 * @param info Context information about the plugin. 30 */ 31 public ElevationProfilePlugin(PluginInformation info) { 32 super(info); 36 33 37 try { 38 eleMode = new ElevationMapMode("Elevation profile", Main.map); 39 eleModeButton = new IconToggleButton(eleMode); 34 createColorMaps(); 40 35 41 JosmAction action = new AddElevationLayerAction(); 36 // TODO: Disable this view as long as it is not stable 37 MainMenu.add(Main.main.menu.imagerySubMenu, new AddElevationLayerAction(), false, 0); 38 } 42 39 43 createColorMaps(); 40 /** 41 * Called after Main.mapFrame is initialized. (After the first data is loaded). 42 * You can use this callback to tweak the newFrame to your needs, as example install 43 * an alternative Painter. 44 */ 45 @Override 46 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 47 super.mapFrameInitialized(oldFrame, newFrame); 44 48 45 // TODO: Disable this view as long as it is not stable 46 MainMenu.add(Main.main.menu.imagerySubMenu, action, false, 0); 47 } catch (Exception e1) { 48 System.err.println("Init of ElevationProfilePlugin failed: " + e1); 49 e1.printStackTrace(); 50 } 51 } 49 if (newFrame != null) { 50 ElevationMapMode eleMode = new ElevationMapMode("Elevation profile", newFrame); 51 newFrame.addMapMode(new IconToggleButton(eleMode)); 52 ElevationProfileDialog eleProfileDlg = new ElevationProfileDialog(); 53 eleProfileDlg.addModelListener(eleMode); 54 eleProfileDlg.setProfileLayer(getCurrentLayer()); 55 newFrame.addToggleDialog(eleProfileDlg); 56 } 57 } 52 58 53 /** 54 * Called after Main.mapFrame is initialized. (After the first data is loaded). 55 * You can use this callback to tweak the newFrame to your needs, as example install 56 * an alternative Painter. 57 */ 58 @Override 59 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 60 super.mapFrameInitialized(oldFrame, newFrame); 59 /** 60 * Gets the elevation profile layer which decorates the current layer 61 * with some markers. 62 * @return 63 */ 64 public static ElevationProfileLayer getCurrentLayer(){ 65 if(currentLayer == null){ 66 currentLayer = new ElevationProfileLayer(tr("Elevation Profile")); 67 Main.main.addLayer(currentLayer); 68 } 69 return currentLayer; 70 } 61 71 62 if (newFrame != null) { 63 newFrame.addMapMode(eleModeButton); 64 ElevationProfileDialog eleProfileDlg = new ElevationProfileDialog(); 65 eleProfileDlg.addModelListener(eleMode); 66 eleProfileDlg.setProfileLayer(getCurrentLayer()); 67 newFrame.addToggleDialog(eleProfileDlg); 68 } 69 } 70 71 /** 72 * Gets the elevation profile layer which decorates the current layer 73 * with some markers. 74 * @return 75 */ 76 public static ElevationProfileLayer getCurrentLayer(){ 77 if(currentLayer == null){ 78 currentLayer = new ElevationProfileLayer(tr("Elevation Profile")); 79 Main.main.addLayer(currentLayer); 80 } 81 return currentLayer; 82 } 83 84 private void createColorMaps() { 85 // Data taken from http://proceedings.esri.com/library/userconf/proc98/proceed/to850/pap842/p842.htm 86 ColorMap.create("Physical_US", 87 new Color[]{ 88 new Color(18,129,242), 89 new Color(113,153,89), 90 new Color(117,170,101), 91 new Color(149,190,113), 92 new Color(178,214,117), 93 new Color(202,226,149), 94 new Color(222,238,161), 95 new Color(242,238,161), 96 new Color(238,222,153), 97 new Color(242,206,133), 98 new Color(234,182,129), 99 new Color(218,157,121), 100 new Color(194,141,125), 101 new Color(214,157,145), 102 new Color(226,174,165), 103 new Color(222,186,182), 104 new Color(238,198,210), 105 new Color(255,206,226), 106 new Color(250,218,234), 107 new Color(255,222,230), 108 new Color(255,230,242), 109 new Color(255,242,255) 110 }, 111 // elevation in meters - the page above uses feet, so these values differs slightly 112 new int[]{ 113 -3000, 114 0, 115 150, 116 300, 117 450, 118 600, 119 750, 120 900, 121 1050, 122 1200, 123 1350, 124 1500, 125 1650, 126 1800, 127 1950, 128 2100, 129 2250, 130 2400, 131 2550, 132 2700, 133 2750, 134 3000 135 } 136 ); 137 } 72 private void createColorMaps() { 73 // Data taken from http://proceedings.esri.com/library/userconf/proc98/proceed/to850/pap842/p842.htm 74 ColorMap.create("Physical_US", 75 new Color[]{ 76 new Color(18,129,242), 77 new Color(113,153,89), 78 new Color(117,170,101), 79 new Color(149,190,113), 80 new Color(178,214,117), 81 new Color(202,226,149), 82 new Color(222,238,161), 83 new Color(242,238,161), 84 new Color(238,222,153), 85 new Color(242,206,133), 86 new Color(234,182,129), 87 new Color(218,157,121), 88 new Color(194,141,125), 89 new Color(214,157,145), 90 new Color(226,174,165), 91 new Color(222,186,182), 92 new Color(238,198,210), 93 new Color(255,206,226), 94 new Color(250,218,234), 95 new Color(255,222,230), 96 new Color(255,230,242), 97 new Color(255,242,255) 98 }, 99 // elevation in meters - the page above uses feet, so these values differs slightly 100 new int[]{ 101 -3000, 102 0, 103 150, 104 300, 105 450, 106 600, 107 750, 108 900, 109 1050, 110 1200, 111 1350, 112 1500, 113 1650, 114 1800, 115 1950, 116 2100, 117 2250, 118 2400, 119 2550, 120 2700, 121 2750, 122 3000 123 } 124 ); 125 } 138 126 }
Note:
See TracChangeset
for help on using the changeset viewer.