Skip to content

Instantly share code, notes, and snippets.

@radzionc
Created August 2, 2018 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radzionc/c87a450846fc6c79e63da02aee0ec72a to your computer and use it in GitHub Desktop.
Save radzionc/c87a450846fc6c79e63da02aee0ec72a to your computer and use it in GitHub Desktop.
export function* selectCity({ payload }) {
const url = `https://nominatim.openstreetmap.org/search/${encodeURIComponent(payload)}?format=json&polygon_geojson=1&type=city`
const places = yield call(get, url)
const city = places.find(p => (p.type === 'city' || p.class === 'boundary') && ['MultiPolygon', 'Polygon'].includes(p.geojson.type))
if (!city) {
yield put(toggleSnackbar('fail to find the boundaries'))
yield put(startSearchingNewCity())
} else {
const [minLng, maxLng, minLat, maxLat] = city.boundingbox.map(Number)
yield put(receiveCity(({ ...city, boundingbox: [[minLat, minLng], [maxLat, maxLng]] })))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment