Created
August 2, 2018 18:00
-
-
Save radzionc/c87a450846fc6c79e63da02aee0ec72a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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