diff --git a/README.md b/README.md index 743c77a..f2d666e 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,10 @@ Returns detailed information about a specific LUQS station Source: https://www.lanuv.nrw.de/luqs/messorte/steckbrief.php?ort={KUERZEL} +Optionally accepts an `options` object as first parameter: + +- `format: json|geojson` return the details in the specified format. + ### luqs.aktuell() Returns the current measurements for all LUQS stations. diff --git a/index.js b/index.js index 24348cb..50424f6 100644 --- a/index.js +++ b/index.js @@ -94,6 +94,7 @@ const luqs = (options = {}) => { * details of the station. * * @param string kuerzel + * @param options.format {String=json,geojson} returns the selected format * @returns Promise resolves with an object */ luqs.station = (kuerzel, options = {}) => { @@ -133,9 +134,34 @@ luqs.station = (kuerzel, options = {}) => { steckbrief.start_messung, steckbrief.ende_messung ] = tmpSteckbrief + steckbrief.image = `${messortBildUrl}${steckbrief.kuerzel.toUpperCase()}.jpg` steckbrief.longitude = steckbrief.longitude.replace(',', '.') steckbrief.latitude = steckbrief.latitude.replace(',', '.') + + if (options.format === 'geojson') { + const geojson = { + type: 'FeatureCollection', + features: [] + } + + geojson.features.push({ + type: 'Feature', + geometry: { + type: 'Point', + coordinates: [ + Number(steckbrief.longitude), + Number(steckbrief.latitude) + ] + }, + properties: { + ...steckbrief + } + }) + resolve(geojson) + return + } + resolve([steckbrief]) }) .catch(error => {