/** * @file * * Interface with the OpenStreetMap collaborative mapping database. */ const axios = require('axios'); const {isObject} = require('../../util'); /** * Submit a query to an Overpass endpoint. * * See 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 . * * @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 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 * and . * * @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;