Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add geojson format #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 26 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) => {
Expand Down Expand Up @@ -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)
mpfeil marked this conversation as resolved.
Show resolved Hide resolved
return
}

resolve([steckbrief])
})
.catch(error => {
Expand Down