From 013a7a1049b172d21c876c30bceb8dc2160766a6 Mon Sep 17 00:00:00 2001 From: Sanjay Bhangar Date: Tue, 22 Jan 2019 19:44:20 +0530 Subject: [PATCH] oops, add missed files --- src/reducers/places.js | 38 ++++++++++++++++++++++++++++++++++++++ src/utils/mapbox.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 src/reducers/places.js create mode 100644 src/utils/mapbox.js diff --git a/src/reducers/places.js b/src/reducers/places.js new file mode 100644 index 0000000..254bc55 --- /dev/null +++ b/src/reducers/places.js @@ -0,0 +1,38 @@ +import { + START_LOADING_ALL_PLACES, + LOADED_ALL_PLACES, + START_LOADING_RANDOM_PLACE, + LOADED_RANDOM_PLACE +} from '../actions/action_types'; + +export default function(state={}, action) { + switch (action.type) { + + case START_LOADING_ALL_PLACES: + return Object.assign({}, state, { loadingAllPlaces: true }); + + case LOADED_ALL_PLACES: + return Object.assign({}, state, { + loadingAllPlaces: false, + allPlaces: action.payload + }); + + case START_LOADING_RANDOM_PLACE: + return Object.assign({}, state, { + loadingRandomPlace: true + }); + + case LOADED_RANDOM_PLACE: + return Object.assign({}, state, { + loadingRandomPlace: false, + randomPlace: action.payload.place, + randomPlaceName: action.payload.place.name, + randomPlaceId: action.payload.place.id, + randomPlaceCount: action.payload.itemCount, + randomPlaceVideos: action.payload.videos + }); + + default: + return state; + } +}; \ No newline at end of file diff --git a/src/utils/mapbox.js b/src/utils/mapbox.js new file mode 100644 index 0000000..25514f7 --- /dev/null +++ b/src/utils/mapbox.js @@ -0,0 +1,29 @@ +import config from '../config'; + +function getStaticMapURL(place, size='800x300') { + const area = place.area; + const zoom = getZoom(area); + return `https://api.mapbox.com/v4/mapbox.emerald/pin-s-marker(${place.lng},${place.lat})/${place.lng},${place.lat},${zoom},0,0/${size}.png?access_token=${config.mapboxKey}`; +} + +function getZoom(area) { + if (area < 100000) { + return 16; + } + if (area < 200000) { + return 15; + } + if (area < 500000) { + return 14; + } + if (area < 1000000) { + return 13; + } + if (area < 2000000) { + return 12; + } else { + return 10; + } +} + +export { getStaticMapURL }; \ No newline at end of file