Changeset 11301 in josm for trunk/src/org
- Timestamp:
- 2016-11-23T23:39:50+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JumpToAction.java
r11300 r11301 9 9 import java.awt.event.ActionEvent; 10 10 import java.awt.event.KeyEvent; 11 import java.util.Optional; 11 12 12 13 import javax.swing.JLabel; … … 21 22 import org.openstreetmap.josm.gui.ExtendedDialog; 22 23 import org.openstreetmap.josm.gui.MapView; 24 import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils; 23 25 import org.openstreetmap.josm.gui.widgets.JosmTextField; 24 26 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator; … … 91 93 } 92 94 MapView mv = Main.map.mapView; 93 LatLon curPos = mv.getProjection().eastNorth2latlon(mv.getCenter()); 94 lat.setText(Double.toString(curPos.lat())); 95 lon.setText(Double.toString(curPos.lon())); 96 97 double dist = mv.getDist100Pixel(); 98 zm.setText(Long.toString(Math.round(dist*100)/100)); 95 96 final Optional<Bounds> boundsFromClipboard = Optional 97 .ofNullable(ClipboardUtils.getClipboardStringContent()) 98 .map(OsmUrlToBounds::parse); 99 if (boundsFromClipboard.isPresent()) { 100 setBounds(boundsFromClipboard.get()); 101 } else { 102 setBounds(mv.getState().getViewArea().getCornerBounds()); 103 } 99 104 updateUrl(true); 100 105 … … 158 163 } 159 164 160 double zoomFactor = 1/ dist;165 double zoomFactor = 1/ mv.getDist100Pixel(); 161 166 mv.zoomToFactor(mv.getProjection().latlon2eastNorth(ll), zoomFactor * zoomLvl); 162 167 } … … 166 171 String urlText = url.getText(); 167 172 Bounds b = OsmUrlToBounds.parse(urlText); 173 setBounds(b); 174 } 175 176 private void setBounds(Bounds b) { 168 177 if (b != null) { 169 lat.setText(Double.toString((b.getMinLat() + b.getMaxLat())/2)); 170 lon.setText(Double.toString((b.getMinLon() + b.getMaxLon())/2)); 171 172 int zoomLvl = 16; 173 int hashIndex = urlText.indexOf("#map"); 174 if (hashIndex >= 0) { 175 zoomLvl = Integer.parseInt(urlText.substring(hashIndex+5, urlText.indexOf('/', hashIndex))); 176 } else { 177 String[] args = urlText.substring(urlText.indexOf('?')+1).split("&"); 178 for (String arg : args) { 179 int eq = arg.indexOf('='); 180 if (eq == -1 || !"zoom".equalsIgnoreCase(arg.substring(0, eq))) continue; 181 182 zoomLvl = Integer.parseInt(arg.substring(eq + 1)); 183 break; 184 } 185 } 186 187 // 10 000 000 = 10 000 * 1000 = World * (km -> m) 188 zm.setText(Double.toString(Math.round(10000000d * Math.pow(2d, (-1d) * zoomLvl)))); 178 final LatLon center = b.getCenter(); 179 lat.setText(Double.toString(center.lat())); 180 lon.setText(Double.toString(center.lon())); 181 zm.setText(Double.toString(OsmUrlToBounds.getZoom(b))); 189 182 } 190 183 } … … 195 188 double dlat = Double.parseDouble(lat.getText()); 196 189 double dlon = Double.parseDouble(lon.getText()); 197 double m = Double.parseDouble(zm.getText()); 198 // Inverse function to the one above. 18 is the current maximum zoom 199 // available on standard renderers, so choose this is in case m should be zero 200 int zoomLvl = 18; 201 if (m > 0) 202 zoomLvl = (int) Math.round((-1) * Math.log(m/10_000_000)/Math.log(2)); 203 204 url.setText(OsmUrlToBounds.getURL(dlat, dlon, zoomLvl)); 190 double zoomLvl = Double.parseDouble(zm.getText()); 191 url.setText(OsmUrlToBounds.getURL(dlat, dlon, (int) zoomLvl)); 205 192 } catch (NumberFormatException x) { 206 193 Main.debug(x.getMessage());
Note:
See TracChangeset
for help on using the changeset viewer.