72 lines
2.0 KiB
JavaScript
72 lines
2.0 KiB
JavaScript
/**
|
|
* @fileoverview
|
|
*
|
|
* Interface with the OpenStreetMap collaborative mapping database.
|
|
*/
|
|
|
|
const axios = require("axios");
|
|
const { isObject } = require("../../util");
|
|
|
|
/**
|
|
* Submit a query to an Overpass endpoint.
|
|
*
|
|
* See <https://wiki.osm.org/Overpass_API/Overpass_QL> for more
|
|
* information on the Overpass Query Language (Overpass QL).
|
|
* @async
|
|
* @param {string} query Query to send.
|
|
* @param {string} [endpoint] Overpass endpoint to use.
|
|
* @returns {string|Object} Results returned by the endpoint. If JSON output
|
|
* is requested in the query, the result will automatically be parsed into
|
|
* a JS object.
|
|
*/
|
|
const runQuery = (
|
|
query,
|
|
endpoint = "https://lz4.overpass-api.de/api/interpreter"
|
|
) => (
|
|
axios.post(endpoint, `data=${query}`)
|
|
.then(res => res.data)
|
|
);
|
|
|
|
exports.runQuery = runQuery;
|
|
|
|
/**
|
|
* Create a link to view a node.
|
|
* @param {string|number} id Identifier for the node to view.
|
|
* @returns {string} Link to view this node on the OSM website.
|
|
*/
|
|
const viewNode = id => `https://www.osm.org/node/${id}`;
|
|
|
|
exports.viewNode = viewNode;
|
|
|
|
/**
|
|
* Determine if an OSM way is one-way or not.
|
|
*
|
|
* See <https://wiki.osm.org/Key:oneway> for details.
|
|
* @param {Object} obj OSM way object.
|
|
* @returns {boolean} Whether the way is one-way.
|
|
*/
|
|
const isOneWay = obj => (
|
|
obj.type === "way" &&
|
|
isObject(obj.tags) &&
|
|
(obj.tags.oneway === "yes" || obj.tags.junction === "roundabout" ||
|
|
obj.tags.highway === "motorway")
|
|
);
|
|
|
|
exports.isOneWay = isOneWay;
|
|
|
|
/**
|
|
* Determine if an OSM object is a public transport line (route master).
|
|
*
|
|
* See <https://wiki.osm.org/Relation:route_master>
|
|
* and <https://wiki.osm.org/Public_transport#Route_Master_relations>.
|
|
* @param {Object} obj OSM relation object.
|
|
* @returns {boolean} Whether the relation is a public transport line.
|
|
*/
|
|
const isTransportLine = obj => (
|
|
obj.type === "relation" &&
|
|
isObject(obj.tags) &&
|
|
obj.tags.type === "route_master"
|
|
);
|
|
|
|
exports.isTransportLine = isTransportLine;
|