From 21aa8a97bbcbb4d1215a6af42f680e9a4498740f Mon Sep 17 00:00:00 2001 From: Giuseppe Zileni Date: Wed, 19 Oct 2022 08:50:48 +0200 Subject: [PATCH 1/3] added custom endpoint --- index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 4aa55231..36f09cce 100644 --- a/index.js +++ b/index.js @@ -3,23 +3,23 @@ const queryOverpass = require('@derhuerst/query-overpass') const osmtogeojson = require('osmtogeojson') const turf = require('@turf/turf') - const fp = require('fastify-plugin') module.exports = fp(async function (fastify, opts) { - fastify.decorate('osm', async (bbox, queries, buffer, unit) => { - const u = unit !== null && unit !== undefined ? unit : 'kilometers' + fastify.decorate('osm', async (params) => { + const endpoint = params.endpoint ? params.endpoint : 'https://overpass-api.de/api/interpreter'; + const u = params.unit !== null && params.unit !== undefined ? params.unit : 'kilometers' /** invert lat/lon */ - const bboxInverted = [bbox[1], bbox[0], bbox[3], bbox[2]] + const bboxInverted = [params.bbox[1], params.bbox[0], params.bbox[3], params.bbox[2]] const bb = bboxInverted.join(',') let q = '[out:json][timeout:25];(' - queries.forEach(c => (q += `node[${c}](${bb}); way[${c}](${bb}); relation[${c}](${bb});`)) + params.queries.forEach(c => (q += `node[${c}](${bb}); way[${c}](${bb}); relation[${c}](${bb});`)) q += ');out body; >; out skel qt;' const resultOsmGeojson = osmtogeojson({ - elements: await queryOverpass(q) + elements: await queryOverpass(q, { endpoint: endpoint }) }) if (buffer !== null && buffer !== undefined) { - const resultOsmGeojsonBuffered = turf.buffer(resultOsmGeojson, buffer, { units: u }) + const resultOsmGeojsonBuffered = turf.buffer(resultOsmGeojson, params.buffer, { units: u }) return resultOsmGeojsonBuffered } else { return resultOsmGeojson From f056b2594d05e001def6d559ef745df67bdca92f Mon Sep 17 00:00:00 2001 From: Giuseppe Zileni Date: Wed, 19 Oct 2022 08:55:46 +0200 Subject: [PATCH 2/3] added custom endpoint --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e13cc495..adeb8efc 100644 --- a/README.md +++ b/README.md @@ -37,15 +37,15 @@ const bbox = [ * highway -> all roads * landuse=industrial * */ -const queries = ['military=airfield', 'highway', 'landuse=industrial'] -/** Calculates a buffer for input features for a given radius. */ -const buffer = 0.5 -/** Units supported are miles, kilometers (default), and degrees. */ -const units = 'kilometers' +const params = { + queries: ['military=airfield', 'highway', 'landuse=industrial'], + buffer: 0.5, // Calculates a buffer for input features for a given radius. + units: 'kilometers', // Units supported are miles, kilometers (default), and degrees. + endpoint: 'https://overpass-api.de/api/interpreter' // DEFAULT: https://overpass-api.de/api/interpreter +} /** GeoJSON results */ -const response = fastify.osm(bbox, queries, buffer, units) +const response = fastify.osm(params) console.log(JSON.stringify(response)); - fastify.listen(3000) ``` From 48dd3b8c9d8df62fd720617c11704b110be64e8b Mon Sep 17 00:00:00 2001 From: Giuseppe Zileni Date: Wed, 19 Oct 2022 08:56:53 +0200 Subject: [PATCH 3/3] added custom endpoint --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 12f4674e..1fc0ebbd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fastify-osm", - "version": "1.0.1", + "version": "1.0.2", "description": "Plugin for Fastify to perform queries on OpenStreetMap", "main": "index.js", "repository": {