95 lines
2.6 KiB
JavaScript
95 lines
2.6 KiB
JavaScript
/**
|
|
* @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'
|
|
) => (
|
|
axios.post(endpoint, 'data=' + query)
|
|
.then(res => res.data)
|
|
);
|
|
|
|
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.
|
|
*/
|
|
const addTagsToNode = (id, tags) => (
|
|
'http://127.0.0.1:8111/load_object?' + [
|
|
`objects=n${id}`,
|
|
'new_layer=false',
|
|
'addtags=' + tags.join('%7C'),
|
|
].join('&')
|
|
);
|
|
|
|
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.
|
|
*/
|
|
const isOneWay = object => (
|
|
object.type === 'way'
|
|
&& isObject(object.tags)
|
|
&& (object.tags.oneway === 'yes' || object.tags.junction === 'roundabout'
|
|
|| object.tags.highway === 'motorway')
|
|
);
|
|
|
|
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.
|
|
*/
|
|
const isTransportLine = object => (
|
|
object.type === 'relation'
|
|
&& isObject(object.tags)
|
|
&& object.tags.type === 'route_master'
|
|
);
|
|
|
|
exports.isTransportLine = isTransportLine;
|