-
-
Save ebraminio/f20acf3bf605066d069bf313f52e2b68 to your computer and use it in GitHub Desktop.
Open a coordinate in JOSM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/openstreetmap/openstreetmap-website/blob/e72acaca9b988d41298415d51a10533d3a27e958/lib/osm.rb#L452 | |
function bounds(lat, lon, radius) { | |
lat = lat * Math.PI / 180; | |
lon = lon * Math.PI / 180; | |
var latradius = 2 * Math.asin(Math.sqrt(Math.sin(radius / 6372.795 / 2)**2)); | |
try { | |
var lonradius = 2 * Math.asin(Math.sqrt(Math.sin(radius / 6372.795 / 2)**2 / Math.cos(lat)**2)) | |
} catch (e) { | |
var lonradius = PI; | |
} | |
return { | |
minLat: Math.max((lat - latradius) * 180 / Math.PI, -90), | |
maxLat: Math.min((lat + latradius) * 180 / Math.PI, 90), | |
minLon: Math.max((lon - lonradius) * 180 / Math.PI, -180), | |
maxLon: Math.min((lon + lonradius) * 180 / Math.PI, 180) | |
}; | |
} | |
var result = bounds(51.0217, 35.67719, 0.2); | |
fetch(`http://127.0.0.1:8111/load_and_zoom?left=${result.minLat}&top=${result.maxLon}&right=${result.maxLat}&bottom=${result.minLon}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment