Skip to content

Commit

Permalink
Merge pull request #9 from gzileni/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
gzileni authored Oct 19, 2022
2 parents 28d8b5c + 48dd3b8 commit 25f6681
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

Expand Down
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 25f6681

Please sign in to comment.