Ignore:
Timestamp:
2013-11-19T02:29:10+01:00 (10 years ago)
Author:
Don-vip
Message:

fix #9333 - Make 'jump to position" more visible (added in view menu) + update to new osm.org url scheme + fix NPE without mapview + javadoc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/JumpToAction.java

    r6380 r6394  
    2626import org.openstreetmap.josm.gui.widgets.JosmTextField;
    2727
     28/**
     29 * Allows to jump to a specific location.
     30 * @since 2575
     31 */
    2832public class JumpToAction extends JosmAction {
     33   
    2934    /**
    3035     * Constructs a new {@code JumpToAction}.
     
    3540    }
    3641
    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();
    4146
     47    /**
     48     * Displays the "Jump to" dialog.
     49     */
    4250    public void showJumpToDialog() {
     51        if (!Main.isDisplayingMapView()) {
     52            return;
     53        }
    4354        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()));
    4958
    5059        double dist = mv.getDist100Pixel();
    5160        double zoomFactor = 1/dist;
    5261
    53         zm.setText(java.lang.Long.toString(Math.round(dist*100)/100));
     62        zm.setText(Long.toString(Math.round(dist*100)/100));
    5463        updateUrl(true);
    5564
     
    123132
    124133    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);
    127137        if (b != null) {
    128138            lat.setText(Double.toString((b.getMinLat() + b.getMaxLat())/2));
     
    130140
    131141            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                }
    139154            }
    140155
     
    162177            dlon = Math.round(dlon * decimals);
    163178            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);
    165180        } catch (NumberFormatException x) {}
    166181    }
Note: See TracChangeset for help on using the changeset viewer.