Skip to content

Instantly share code, notes, and snippets.

@ebraminio
Last active March 7, 2020 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebraminio/f20acf3bf605066d069bf313f52e2b68 to your computer and use it in GitHub Desktop.
Save ebraminio/f20acf3bf605066d069bf313f52e2b68 to your computer and use it in GitHub Desktop.
Open a coordinate in JOSM
// 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