Changeset 1722 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2009-07-03T12:33:32+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java
r1689 r1722 55 55 return Double.parseDouble(map.get("m"+key)); 56 56 } 57 58 static public int getZoom(Bounds b) 59 { 60 // convert to mercator (for calculation of zoom only) 61 double latMin = Math.log(Math.tan(Math.PI/4.0+b.min.lat()/180.0*Math.PI/2.0))*180.0/Math.PI; 62 double latMax = Math.log(Math.tan(Math.PI/4.0+b.max.lat()/180.0*Math.PI/2.0))*180.0/Math.PI; 63 double size = Math.max(Math.abs(latMax-latMin), Math.abs(b.max.lon()-b.min.lon())); 64 int zoom = 0; 65 while (zoom <= 20) { 66 if (size >= 180) 67 break; 68 size *= 2; 69 zoom++; 70 } 71 return zoom; 72 } 73 74 static public String getURL(Bounds b) 75 { 76 return getURL(b.center(), getZoom(b)); 77 } 78 79 static public String getURL(LatLon pos, int zoom) 80 { 81 // Truncate lat and lon to something more sensible 82 int decimals = (int) Math.pow(10, (zoom / 3)); 83 double lat = (Math.round(pos.lat() * decimals))/decimals; 84 double lon = (Math.round(pos.lon() * decimals))/decimals; 85 return new String("http://www.openstreetmap.org/?lat="+lat+"&lon="+lon+"&zoom="+zoom); 86 } 57 87 }
Note:
See TracChangeset
for help on using the changeset viewer.