Ticket #8945: osmURLtoBoundsPatch.diff

File osmURLtoBoundsPatch.diff, 1.8 KB (added by peter.wendorff@…, 13 years ago)

patch dazu

  • JOSM/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java

     
    2727        if (b != null)
    2828            return b;
    2929        int i = url.indexOf('?');
    30         if (i == -1)
    31             return null;
     30        if (i == -1) {
     31            //probably it's a URL following the new scheme?
     32            if (url.indexOf('#') >= 0)
     33                return parseHashURLs(url);
     34            else
     35                return null;
     36        }
    3237        String[] args = url.substring(i+1).split("&");
    3338        HashMap<String, String> map = new HashMap<String, String>();
    3439        for (String arg : args) {
     
    7075        return b;
    7176    }
    7277
     78    /**
     79     * Openstreetmap.org changed it's URL scheme in August 2013, which breaks the URL parsing.
     80     * The following function, called by the old parse function if necessary, provides parsing new URLs
     81     * the new URLs follow the scheme http://www.openstreetmap.org/#map=18/51.71873/8.76164&layers=CN
     82     * @param url
     83     * @return
     84     */
     85    private static Bounds parseHashURLs(String url) {
     86        int startIndex = url.indexOf("=");
     87        int endIndex = url.indexOf("&");
     88        String coordPart = url.substring(startIndex+1, endIndex);
     89        System.out.println(coordPart);
     90
     91        String[] parts = coordPart.split("/");
     92        Bounds b = positionToBounds(Double.parseDouble(parts[1]),
     93                Double.parseDouble(parts[2]),
     94                Integer.parseInt(parts[0]));
     95        return b;
     96    }
     97
    7398    private static double parseDouble(HashMap<String, String> map, String key) {
    7499        if (map.containsKey(key))
    75100            return Double.parseDouble(map.get(key));