Changeset 1677 in josm for trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java
- Timestamp:
- 2009-06-17T10:04:22+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java
r1307 r1677 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 package org.openstreetmap.josm.tools; 3 4 import java.util.HashMap; 5 6 import org.openstreetmap.josm.data.Bounds; 7 import org.openstreetmap.josm.data.coor.LatLon; 8 9 public class OsmUrlToBounds { 10 public static Bounds parse(String url) { 11 int i = url.indexOf('?'); 12 if (i == -1) 13 return null; 14 String[] args = url.substring(i+1).split("&"); 15 HashMap<String, String> map = new HashMap<String, String>(); 16 for (String arg : args) { 17 int eq = arg.indexOf('='); 18 if (eq != -1) { 19 map.put(arg.substring(0, eq), arg.substring(eq + 1)); 20 } 21 } 22 23 Bounds b = null; 24 try { 25 if (map.containsKey("bbox")) { 26 String bbox[] = map.get("bbox").split(","); 27 b = new Bounds( 28 new LatLon(Double.parseDouble(bbox[1]), Double.parseDouble(bbox[0])), 29 new LatLon(Double.parseDouble(bbox[3]), Double.parseDouble(bbox[2]))); 30 31 } else { 32 double size = 180.0 / Math.pow(2, Integer.parseInt(map.get("zoom"))); 33 b = new Bounds( 34 new LatLon(parseDouble(map, "lat") - size/2, parseDouble(map, "lon") - size), 35 new LatLon(parseDouble(map, "lat") + size/2, parseDouble(map, "lon") + size)); 36 } 37 } catch (NumberFormatException x) { 38 } catch (NullPointerException x) { 39 } 40 return b; 41 } 42 43 private static double parseDouble(HashMap<String, String> map, String key) { 44 if (map.containsKey(key)) 45 return Double.parseDouble(map.get(key)); 46 return Double.parseDouble(map.get("m"+key)); 47 } 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 package org.openstreetmap.josm.tools; 3 4 import java.util.HashMap; 5 6 import org.openstreetmap.josm.data.Bounds; 7 import org.openstreetmap.josm.data.coor.LatLon; 8 9 public class OsmUrlToBounds { 10 public static Bounds parse(String url) { 11 int i = url.indexOf('?'); 12 if (i == -1) 13 return null; 14 String[] args = url.substring(i+1).split("&"); 15 HashMap<String, String> map = new HashMap<String, String>(); 16 for (String arg : args) { 17 int eq = arg.indexOf('='); 18 if (eq != -1) { 19 map.put(arg.substring(0, eq), arg.substring(eq + 1)); 20 } 21 } 22 23 Bounds b = null; 24 try { 25 if (map.containsKey("bbox")) { 26 String bbox[] = map.get("bbox").split(","); 27 b = new Bounds( 28 new LatLon(Double.parseDouble(bbox[1]), Double.parseDouble(bbox[0])), 29 new LatLon(Double.parseDouble(bbox[3]), Double.parseDouble(bbox[2]))); 30 31 } else { 32 double size = 180.0 / Math.pow(2, Integer.parseInt(map.get("zoom"))); 33 b = new Bounds( 34 new LatLon(parseDouble(map, "lat") - size/2, parseDouble(map, "lon") - size), 35 new LatLon(parseDouble(map, "lat") + size/2, parseDouble(map, "lon") + size)); 36 } 37 } catch (NumberFormatException x) { 38 } catch (NullPointerException x) { 39 } 40 return b; 41 } 42 43 private static double parseDouble(HashMap<String, String> map, String key) { 44 if (map.containsKey(key)) 45 return Double.parseDouble(map.get(key)); 46 return Double.parseDouble(map.get("m"+key)); 47 } 48 48 }
Note:
See TracChangeset
for help on using the changeset viewer.