Skip to content

Instantly share code, notes, and snippets.

@d1i1m1o1n
Created April 26, 2015 06:24
Show Gist options
  • Save d1i1m1o1n/e9c6dc916ca5e7c2ce91 to your computer and use it in GitHub Desktop.
Save d1i1m1o1n/e9c6dc916ca5e7c2ce91 to your computer and use it in GitHub Desktop.
Получаем массив координат здания по osm_id. Для конвертации xml в geojson используется https://github.com/tyrasd/osmtogeojson
/**
* Меняем местами lat и lon в массиве координат
* @param {array} coords массив координат
* @return {array} обработанный массив координат
*/
function swap_coords(coords) {
for (var i = coords.length - 1; i >= 0; i--) {
var first = coords[i][1];
coords[i][1] = coords[i][0];
coords[i][0] = first;
};
return coords;
}
/**
* Получаем координаты здания по osm_id
* @param {int} osm_id
* @return {array} массив точек описывающих здание
*/
function get_building_by_osmid(osm_id, callback) {
var building_arr;
jQuery.ajax({
url: 'http://www.openstreetmap.org/api/0.6/way/'+osm_id+'/full',
type: 'GET',
dataType: 'xml',
data: {param1: 'value1'},
success: function(data, textStatus, xhr) {
var geojson = osmtogeojson(data);
building_arr = swap_coords(geojson.features[0].geometry.coordinates[0]);
return building_arr;
},
error: function(xhr, textStatus, errorThrown) {
alert('error');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment