FitTrackee/mpwo_client/src/utils.js

34 lines
845 B
JavaScript
Raw Normal View History

2018-05-03 21:42:54 +02:00
import togeojson from '@mapbox/togeojson'
import bbox from 'geojson-bbox'
2018-04-29 17:02:08 +02:00
export const apiUrl = `${process.env.REACT_APP_API_URL}/api/`
2018-05-03 14:07:31 +02:00
export const thunderforestApiKey = `${
process.env.REACT_APP_THUNDERFOREST_API_KEY
}`
2018-04-29 17:02:08 +02:00
2017-12-25 20:11:10 +01:00
export const isLoggedIn = () => !!window.localStorage.authToken
2018-01-14 12:48:52 +01:00
export function generateIds(arr) {
let i = 0
2018-01-14 17:19:02 +01:00
return arr.map(val => {
const obj = { id: i, value: val }
2018-01-14 12:48:52 +01:00
i++
return obj
})
}
2018-05-03 21:42:54 +02:00
export function getGeoJson(gpxContent) {
let jsonData, bboxCorners
let bounds = [[0, 0], [0, 0]]
if (gpxContent) {
const gpx = new DOMParser().parseFromString(gpxContent, 'text/xml')
jsonData = togeojson.gpx(gpx)
bboxCorners = bbox(jsonData)
bounds = [
[bboxCorners[1], bboxCorners[0]],
[bboxCorners[3], bboxCorners[2]]
]
}
return { jsonData, bounds }
}