|
3 | 3 | const queryOverpass = require('@derhuerst/query-overpass')
|
4 | 4 | const osmtogeojson = require('osmtogeojson')
|
5 | 5 | const turf = require('@turf/turf')
|
6 |
| - |
7 | 6 | const fp = require('fastify-plugin')
|
8 | 7 |
|
9 | 8 | module.exports = fp(async function (fastify, opts) {
|
10 |
| - fastify.decorate('osm', async (bbox, queries, buffer, unit) => { |
11 |
| - const u = unit !== null && unit !== undefined ? unit : 'kilometers' |
| 9 | + fastify.decorate('osm', async (params) => { |
| 10 | + const endpoint = params.endpoint ? params.endpoint : 'https://overpass-api.de/api/interpreter'; |
| 11 | + const u = params.unit !== null && params.unit !== undefined ? params.unit : 'kilometers' |
12 | 12 | /** invert lat/lon */
|
13 |
| - const bboxInverted = [bbox[1], bbox[0], bbox[3], bbox[2]] |
| 13 | + const bboxInverted = [params.bbox[1], params.bbox[0], params.bbox[3], params.bbox[2]] |
14 | 14 | const bb = bboxInverted.join(',')
|
15 | 15 | let q = '[out:json][timeout:25];('
|
16 |
| - queries.forEach(c => (q += `node[${c}](${bb}); way[${c}](${bb}); relation[${c}](${bb});`)) |
| 16 | + params.queries.forEach(c => (q += `node[${c}](${bb}); way[${c}](${bb}); relation[${c}](${bb});`)) |
17 | 17 | q += ');out body; >; out skel qt;'
|
18 | 18 | const resultOsmGeojson = osmtogeojson({
|
19 |
| - elements: await queryOverpass(q) |
| 19 | + elements: await queryOverpass(q, { endpoint: endpoint }) |
20 | 20 | })
|
21 | 21 | if (buffer !== null && buffer !== undefined) {
|
22 |
| - const resultOsmGeojsonBuffered = turf.buffer(resultOsmGeojson, buffer, { units: u }) |
| 22 | + const resultOsmGeojsonBuffered = turf.buffer(resultOsmGeojson, params.buffer, { units: u }) |
23 | 23 | return resultOsmGeojsonBuffered
|
24 | 24 | } else {
|
25 | 25 | return resultOsmGeojson
|
|
0 commit comments