Changeset 6394 in josm


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

Location:
trunk/src/org/openstreetmap/josm
Files:
3 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    }
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r6336 r6394  
    208208    /** View -> "Zoom to"... actions */
    209209    public final Map<String, AutoScaleAction> autoScaleActions = new HashMap<String, AutoScaleAction>();
     210    /** View -> Jump to position */
     211    public final JumpToAction jumpToAct = new JumpToAction();
    210212
    211213    /* Tools menu */
     
    337339    public final JosmAction moveLeftAction = new MoveAction(MoveAction.Direction.LEFT);
    338340    public final JosmAction moveRightAction = new MoveAction(MoveAction.Direction.RIGHT);
    339     public final JumpToAction jumpToAct = new JumpToAction();
    340341
    341342    public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction();
     
    650651
    651652        viewMenu.addSeparator();
     653        add(viewMenu, jumpToAct);
     654        viewMenu.addSeparator();
    652655        add(viewMenu, info);
    653656        add(viewMenu, infoweb);
  • trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java

    r6380 r6394  
    9292        int endIndex = url.indexOf('&', startIndex);
    9393        if (endIndex == -1) endIndex = url.length();
    94         try
    95         {
     94        try {
    9695            String coordPart = url.substring(startIndex+5, endIndex);
    9796            String[] parts = coordPart.split("/");
     
    10099                    Integer.parseInt(parts[0]));
    101100            return b;
    102         }
    103         catch(Exception ex)
    104         {
     101        } catch (Exception ex) {
     102            Main.debug(ex.getMessage());
    105103            return null;
    106104        }
Note: See TracChangeset for help on using the changeset viewer.