facilmap/server/elevation.js

36 wiersze
780 B
JavaScript
Czysty Zwykły widok Historia

2017-04-27 12:42:42 +00:00
const polyline = require("@mapbox/polyline");
const request = require("request-promise").defaults({
gzip: true,
headers: {
'User-Agent': process.env.fmUserAgent
}
});
const API_URL = "https://elevation.mapzen.com/height";
const API_KEY = "mapzen-LWPWRB1";
const elevation = module.exports = {
getElevationForPoint(point) {
return elevation.getElevationForPoints([point]).then((points) => (points[0]));
},
getElevationForPoints(points) {
if(points.length == 0)
return [ ];
let json = {
encoded_polyline: polyline.encode(points.map((point) => ([point.lat, point.lon])), 6),
range: false
};
return request.get({
url: `${API_URL}?json=${encodeURI(JSON.stringify(json))}&api_key=${API_KEY}`,
json: true
}).then((res) => (res.height));
}
};