Changeset 29977 in osm for applications/editors/josm/plugins/ElevationProfile/src
- Timestamp:
- 2013-09-27T02:00:51+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ColorMap.java
r29964 r29977 1 1 /** 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 11 * You should have received a copy of the GNU General Public License along with this program. 12 12 * If not, see <http://www.gnu.org/licenses/>. 13 13 */ … … 31 31 private String name; 32 32 private static HashMap<String, ColorMap> colorMaps; 33 33 34 34 static { 35 colorMaps = new HashMap<String, ColorMap>(); 36 } 37 35 colorMaps = new HashMap<String, ColorMap>(); 36 } 37 38 38 // Private ctor to enforce use of create 39 private ColorMap() { 40 } 41 39 private ColorMap() { 40 } 41 42 42 public String getName() { 43 43 return name; 44 44 } 45 45 46 46 public void setName(String name) { 47 48 } 49 47 this.name = name; 48 } 49 50 50 /** 51 51 * Gets the color according to the given elevation value. … … 59 59 return Color.white; 60 60 } 61 61 62 62 // out of range? 63 63 if (elevation < colorList.get(0).ele) { 64 64 return colorList.get(0).getColor(); 65 65 } 66 66 67 67 int last = colorList.size() - 1; 68 68 if (elevation > colorList.get(last).ele) { 69 69 return colorList.get(last).getColor(); 70 70 } 71 71 72 72 // find elevation section 73 73 for (int i = 0; i < last; i++) { 74 74 ColorMapEntry e1 = colorList.get(i); 75 75 ColorMapEntry e2 = colorList.get(i + 1); 76 76 77 77 // elevation within range? 78 78 if (e1.getEle() <= elevation && e2.getEle() >= elevation) { 79 79 80 80 // interpolate color between both 81 81 double val = (elevation - e1.getEle()) / (double)(e2.getEle() - e1.getEle()); … … 83 83 } 84 84 } 85 85 86 86 // here we should never end! 87 87 throw new RuntimeException("Inconsistent color map - found no entry for elevation " + elevation); 88 88 } 89 90 89 90 91 91 /** 92 92 * Gets the color map with the given name. … … 98 98 if (colorMaps.containsKey(name)) { 99 99 return colorMaps.get(name); 100 } 100 } 101 101 return null; 102 102 } 103 104 /** 105 * Gets the number of available color maps. 103 104 /** 105 * Gets the number of available color maps. 106 106 * 107 107 * @return the int … … 110 110 return colorMaps != null ? colorMaps.size() : 0; 111 111 } 112 113 112 113 114 114 /** 115 115 * Gets the available color map names. … … 118 118 * @return the map or <code>null</code>, if no such map exists 119 119 */ 120 public static String[] getNames() { 120 public static String[] getNames() { 121 121 return colorMaps.keySet().toArray(new String[size()]); 122 122 } 123 123 124 124 private static void registerColorMap(ColorMap newMap) { 125 125 CheckParameterUtil.ensureParameterNotNull(newMap); … … 132 132 } 133 133 } 134 134 135 135 public static Color interpolate(java.awt.Color c1, java.awt.Color c2, double ratio) { 136 double r1 = ratio;136 double r1 = 1 -ratio; 137 137 // clip 138 138 if (r1 < 0) r1 = 0d; … … 158 158 CheckParameterUtil.ensureParameterNotNull(colors); 159 159 CheckParameterUtil.ensureParameterNotNull(ele); 160 160 161 161 if (colors.length != ele.length) { 162 162 throw new IllegalArgumentException("Arrays colors and ele must have same length: " + colors.length + " vs " + ele.length); 163 163 } 164 164 165 165 ColorMap map = new ColorMap(); 166 map.colorList = new ArrayList<ColorMap.ColorMapEntry>(); 166 map.colorList = new ArrayList<ColorMap.ColorMapEntry>(); 167 167 map.name = name; 168 168 for (int i = 0; i < ele.length; i++) { 169 169 map.colorList.add(map.new ColorMapEntry(colors[i], ele[i])); 170 170 } 171 171 172 172 // sort by elevation 173 173 Collections.sort(map.colorList); 174 174 175 175 registerColorMap(map); 176 176 return map; 177 177 } 178 178 179 179 180 180 class ColorMapEntry implements Comparable<ColorMapEntry> { 181 private int ele; // limit182 private Color color;183 181 private final int ele; // limit 182 private final Color color; 183 184 184 public ColorMapEntry(Color color, int ele) { 185 185 super(); … … 197 197 198 198 @Override 199 public int compareTo(ColorMapEntry o) { 199 public int compareTo(ColorMapEntry o) { 200 200 return this.ele - o.ele; 201 201 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/actions/AddElevationLayerAction.java
r29964 r29977 32 32 33 33 public AddElevationLayerAction() { 34 super(tr("Elevation Grid Layer "), "elevation", tr("Shows elevation grid layer"), null, true);34 super(tr("Elevation Grid Layer (experimental!)"), "elevation", tr("Shows elevation grid layer"), null, true); 35 35 } 36 36 -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridTile.java
r29964 r29977 92 92 if (isLoaded()) return; 93 93 94 // TODO: Save 95 94 96 // We abuse the loadImage method to render the vertices... 95 97 // … … 113 115 } 114 116 117 /** 118 * See also <a href="http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Tile_bounding_box">OSM Wiki</a> 119 * @param x the x 120 * @param y the y 121 * @param zoom the zoom 122 * @return the bounds 123 */ 115 124 private Bounds tile2Bounds(final int x, final int y, final int zoom) { 116 125 Bounds bb = new Bounds(
Note:
See TracChangeset
for help on using the changeset viewer.