Changeset 6155 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2013-08-19T11:42:28+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java
r6119 r6155 2 2 package org.openstreetmap.josm.tools; 3 3 4 import java.awt.HeadlessException; 4 5 import java.awt.Toolkit; 5 6 import java.io.UnsupportedEncodingException; … … 27 28 if (b != null) 28 29 return b; 29 int i = url.indexOf('?'); 30 int i = url.indexOf("#map"); 31 if (i >= 0) { 32 // probably it's a URL following the new scheme? 33 return parseHashURLs(url); 34 } 35 i = url.indexOf('?'); 30 36 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; 37 return null; 36 38 } 37 39 String[] args = url.substring(i+1).split("&"); … … 80 82 * The following function, called by the old parse function if necessary, provides parsing new URLs 81 83 * the new URLs follow the scheme http://www.openstreetmap.org/#map=18/51.71873/8.76164&layers=CN 82 * @param url 83 * @return 84 * @param url string for parsing 85 * @return Bounds if hashurl, {@code null} otherwise 84 86 */ 85 87 private static Bounds parseHashURLs(String url) { 86 int startIndex = url.indexOf(" =");88 int startIndex = url.indexOf("#map="); 87 89 if (startIndex == -1) return null; 88 int endIndex = url.indexOf( "&");90 int endIndex = url.indexOf('&', startIndex); 89 91 if (endIndex == -1) endIndex = url.length(); 90 92 try 91 93 { 92 String coordPart = url.substring(startIndex+ 1, endIndex);94 String coordPart = url.substring(startIndex+5, endIndex); 93 95 String[] parts = coordPart.split("/"); 94 96 Bounds b = positionToBounds(Double.parseDouble(parts[1]), … … 181 183 public static Bounds positionToBounds(final double lat, final double lon, final int zoom) { 182 184 int tileSizeInPixels = 256; 183 int height = Toolkit.getDefaultToolkit().getScreenSize().height; 184 int width = Toolkit.getDefaultToolkit().getScreenSize().width; 185 if (Main.isDisplayingMapView()) { 186 height = Main.map.mapView.getHeight(); 187 width = Main.map.mapView.getWidth(); 185 int height; 186 int width; 187 try { 188 height = Toolkit.getDefaultToolkit().getScreenSize().height; 189 width = Toolkit.getDefaultToolkit().getScreenSize().width; 190 if (Main.isDisplayingMapView()) { 191 height = Main.map.mapView.getHeight(); 192 width = Main.map.mapView.getWidth(); 193 } 194 } catch (HeadlessException he) { 195 // in headless mode, when running tests 196 height = 480; 197 width = 640; 188 198 } 189 199 double scale = (1 << zoom) * tileSizeInPixels / (2 * Math.PI * R);
Note:
See TracChangeset
for help on using the changeset viewer.