Skip to content

Commit 25f6681

Browse files
authored
Merge pull request #9 from gzileni/develop
Develop
2 parents 28d8b5c + 48dd3b8 commit 25f6681

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ const bbox = [
3737
* highway -> all roads
3838
* landuse=industrial
3939
* */
40-
const queries = ['military=airfield', 'highway', 'landuse=industrial']
41-
/** Calculates a buffer for input features for a given radius. */
42-
const buffer = 0.5
43-
/** Units supported are miles, kilometers (default), and degrees. */
44-
const units = 'kilometers'
40+
const params = {
41+
queries: ['military=airfield', 'highway', 'landuse=industrial'],
42+
buffer: 0.5, // Calculates a buffer for input features for a given radius.
43+
units: 'kilometers', // Units supported are miles, kilometers (default), and degrees.
44+
endpoint: 'https://overpass-api.de/api/interpreter' // DEFAULT: https://overpass-api.de/api/interpreter
45+
}
4546
/** GeoJSON results */
46-
const response = fastify.osm(bbox, queries, buffer, units)
47+
const response = fastify.osm(params)
4748
console.log(JSON.stringify(response));
48-
4949
fastify.listen(3000)
5050
```
5151

index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
const queryOverpass = require('@derhuerst/query-overpass')
44
const osmtogeojson = require('osmtogeojson')
55
const turf = require('@turf/turf')
6-
76
const fp = require('fastify-plugin')
87

98
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'
1212
/** 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]]
1414
const bb = bboxInverted.join(',')
1515
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});`))
1717
q += ');out body; >; out skel qt;'
1818
const resultOsmGeojson = osmtogeojson({
19-
elements: await queryOverpass(q)
19+
elements: await queryOverpass(q, { endpoint: endpoint })
2020
})
2121
if (buffer !== null && buffer !== undefined) {
22-
const resultOsmGeojsonBuffered = turf.buffer(resultOsmGeojson, buffer, { units: u })
22+
const resultOsmGeojsonBuffered = turf.buffer(resultOsmGeojson, params.buffer, { units: u })
2323
return resultOsmGeojsonBuffered
2424
} else {
2525
return resultOsmGeojson

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fastify-osm",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Plugin for Fastify to perform queries on OpenStreetMap",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)