2020-07-17 10:13:25 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* 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.openstreetmap.org/wiki/Overpass_API/Overpass_QL> for more
|
|
|
|
* information on the Overpass Query Language (Overpass QL).
|
|
|
|
*
|
|
|
|
* @async
|
|
|
|
* @param query Query to send.
|
|
|
|
* @param [endpoint] Overpass endpoint to use.
|
|
|
|
* @return 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'
|
2020-07-17 21:48:32 +00:00
|
|
|
) => (
|
|
|
|
axios.post(endpoint, 'data=' + query)
|
|
|
|
.then(res => res.data)
|
|
|
|
);
|
2020-07-17 10:13:25 +00:00
|
|
|
|
|
|
|
exports.runQuery = runQuery;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a link to add tags into JOSM.
|
|
|
|
*
|
|
|
|
* The JOSM remote control must be activated and JOSM must be running for this
|
|
|
|
* link to work. See <https://wiki.openstreetmap.org/wiki/JOSM/RemoteControl>.
|
|
|
|
*
|
|
|
|
* @param id Identifier for the object to add the tags to.
|
|
|
|
* @param tags List of tags to add, in the `key=value` format.
|
|
|
|
* @return Link for remotely adding the tags.
|
|
|
|
*/
|
2020-07-17 21:48:32 +00:00
|
|
|
const addTagsToNode = (id, tags) => (
|
2020-07-17 10:13:25 +00:00
|
|
|
'http://127.0.0.1:8111/load_object?' + [
|
|
|
|
`objects=n${id}`,
|
|
|
|
'new_layer=false',
|
|
|
|
'addtags=' + tags.join('%7C'),
|
2020-07-17 21:48:32 +00:00
|
|
|
].join('&')
|
|
|
|
);
|
2020-07-17 10:13:25 +00:00
|
|
|
|
|
|
|
exports.addTagsToNode = addTagsToNode;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a link to view a node.
|
|
|
|
*
|
|
|
|
* @param id Identifier for the node to view.
|
|
|
|
* @return Link to view this node on the OSM website.
|
|
|
|
*/
|
|
|
|
const viewNode = id => `https://www.openstreetmap.org/node/${id}`;
|
|
|
|
|
|
|
|
exports.viewNode = viewNode;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if an OSM way is one-way or not.
|
|
|
|
*
|
|
|
|
* See <https://wiki.openstreetmap.org/wiki/Key:oneway> for details.
|
|
|
|
*
|
|
|
|
* @param tags Set of tags of the way.
|
|
|
|
* @return True iff. the way is one-way.
|
|
|
|
*/
|
2020-07-17 21:48:32 +00:00
|
|
|
const isOneWay = object => (
|
2020-07-17 10:13:25 +00:00
|
|
|
object.type === 'way'
|
|
|
|
&& isObject(object.tags)
|
|
|
|
&& (object.tags.oneway === 'yes' || object.tags.junction === 'roundabout'
|
2020-07-17 21:48:32 +00:00
|
|
|
|| object.tags.highway === 'motorway')
|
|
|
|
);
|
2020-07-17 10:13:25 +00:00
|
|
|
|
|
|
|
exports.isOneWay = isOneWay;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if an OSM object is a public transport line (route master).
|
|
|
|
*
|
|
|
|
* See <https://wiki.openstreetmap.org/wiki/Relation:route_master>
|
|
|
|
* and <https://wiki.openstreetmap.org/wiki/Public_transport#Route_Master_relations>.
|
|
|
|
*
|
|
|
|
* @param object OSM object.
|
|
|
|
* @return True iff. the relation is a public transport line.
|
|
|
|
*/
|
2020-07-17 21:48:32 +00:00
|
|
|
const isTransportLine = object => (
|
2020-07-17 10:13:25 +00:00
|
|
|
object.type === 'relation'
|
|
|
|
&& isObject(object.tags)
|
2020-07-17 21:48:32 +00:00
|
|
|
&& object.tags.type === 'route_master'
|
|
|
|
);
|
2020-07-17 10:13:25 +00:00
|
|
|
|
|
|
|
exports.isTransportLine = isTransportLine;
|