Changeset 6394 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2013-11-19T02:29:10+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JumpToAction.java
r6380 r6394 26 26 import org.openstreetmap.josm.gui.widgets.JosmTextField; 27 27 28 /** 29 * Allows to jump to a specific location. 30 * @since 2575 31 */ 28 32 public class JumpToAction extends JosmAction { 33 29 34 /** 30 35 * Constructs a new {@code JumpToAction}. … … 35 40 } 36 41 37 private JosmTextField url = new JosmTextField();38 private JosmTextField lat = new JosmTextField();39 private JosmTextField lon = new JosmTextField();40 private JosmTextField zm = new JosmTextField();42 private final JosmTextField url = new JosmTextField(); 43 private final JosmTextField lat = new JosmTextField(); 44 private final JosmTextField lon = new JosmTextField(); 45 private final JosmTextField zm = new JosmTextField(); 41 46 47 /** 48 * Displays the "Jump to" dialog. 49 */ 42 50 public void showJumpToDialog() { 51 if (!Main.isDisplayingMapView()) { 52 return; 53 } 43 54 MapView mv = Main.map.mapView; 44 if(mv == null) 45 return; 46 LatLon curPos=mv.getProjection().eastNorth2latlon(mv.getCenter()); 47 lat.setText(java.lang.Double.toString(curPos.lat())); 48 lon.setText(java.lang.Double.toString(curPos.lon())); 55 LatLon curPos = mv.getProjection().eastNorth2latlon(mv.getCenter()); 56 lat.setText(Double.toString(curPos.lat())); 57 lon.setText(Double.toString(curPos.lon())); 49 58 50 59 double dist = mv.getDist100Pixel(); 51 60 double zoomFactor = 1/dist; 52 61 53 zm.setText( java.lang.Long.toString(Math.round(dist*100)/100));62 zm.setText(Long.toString(Math.round(dist*100)/100)); 54 63 updateUrl(true); 55 64 … … 123 132 124 133 private void parseURL() { 125 if(!url.hasFocus()) return; 126 Bounds b = OsmUrlToBounds.parse(url.getText()); 134 if (!url.hasFocus()) return; 135 String urlText = url.getText(); 136 Bounds b = OsmUrlToBounds.parse(urlText); 127 137 if (b != null) { 128 138 lat.setText(Double.toString((b.getMinLat() + b.getMaxLat())/2)); … … 130 140 131 141 int zoomLvl = 16; 132 String[] args = url.getText().substring(url.getText().indexOf('?')+1).split("&"); 133 for (String arg : args) { 134 int eq = arg.indexOf('='); 135 if (eq == -1 || !arg.substring(0, eq).equalsIgnoreCase("zoom")) continue; 136 137 zoomLvl = Integer.parseInt(arg.substring(eq + 1)); 138 break; 142 int hashIndex = urlText.indexOf("#map"); 143 if (hashIndex >= 0) { 144 zoomLvl = Integer.parseInt(urlText.substring(hashIndex+5, urlText.indexOf('/', hashIndex))); 145 } else { 146 String[] args = urlText.substring(urlText.indexOf('?')+1).split("&"); 147 for (String arg : args) { 148 int eq = arg.indexOf('='); 149 if (eq == -1 || !arg.substring(0, eq).equalsIgnoreCase("zoom")) continue; 150 151 zoomLvl = Integer.parseInt(arg.substring(eq + 1)); 152 break; 153 } 139 154 } 140 155 … … 162 177 dlon = Math.round(dlon * decimals); 163 178 dlon /= decimals; 164 url.setText("http://www.openstreetmap.org/ ?lat="+dlat+"&lon="+dlon+"&zoom="+zoomLvl);179 url.setText("http://www.openstreetmap.org/#map="+zoomLvl+"/"+dlat+"/"+dlon); 165 180 } catch (NumberFormatException x) {} 166 181 } -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r6336 r6394 208 208 /** View -> "Zoom to"... actions */ 209 209 public final Map<String, AutoScaleAction> autoScaleActions = new HashMap<String, AutoScaleAction>(); 210 /** View -> Jump to position */ 211 public final JumpToAction jumpToAct = new JumpToAction(); 210 212 211 213 /* Tools menu */ … … 337 339 public final JosmAction moveLeftAction = new MoveAction(MoveAction.Direction.LEFT); 338 340 public final JosmAction moveRightAction = new MoveAction(MoveAction.Direction.RIGHT); 339 public final JumpToAction jumpToAct = new JumpToAction();340 341 341 342 public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction(); … … 650 651 651 652 viewMenu.addSeparator(); 653 add(viewMenu, jumpToAct); 654 viewMenu.addSeparator(); 652 655 add(viewMenu, info); 653 656 add(viewMenu, infoweb); -
trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java
r6380 r6394 92 92 int endIndex = url.indexOf('&', startIndex); 93 93 if (endIndex == -1) endIndex = url.length(); 94 try 95 { 94 try { 96 95 String coordPart = url.substring(startIndex+5, endIndex); 97 96 String[] parts = coordPart.split("/"); … … 100 99 Integer.parseInt(parts[0])); 101 100 return b; 102 } 103 catch(Exception ex) 104 { 101 } catch (Exception ex) { 102 Main.debug(ex.getMessage()); 105 103 return null; 106 104 }
Note:
See TracChangeset
for help on using the changeset viewer.