Skip to content

Instantly share code, notes, and snippets.

@scottpdawson
Created May 27, 2020 12:55
Show Gist options
  • Save scottpdawson/fa2a46faf465f5b6da30135d353719ad to your computer and use it in GitHub Desktop.
Save scottpdawson/fa2a46faf465f5b6da30135d353719ad to your computer and use it in GitHub Desktop.
Fetching ski resort data
async componentDidMount() {
// trigger data load from openskimap
axios
.get(`//tiles.skimap.org/geojson/ski_areas.geojson`)
.then((res) => {
const resorts =
res.data.features.map((resort) => ({
id: resort.properties.id,
point: getPointForResort(resort),
name: resort.properties.name,
...
isEpic: false,
isIkon: false,
})) || [];
// trigger data load from Firebase to get Epic/Ikon data
const ikonEpicFlags = firebase.database().ref();
ikonEpicFlags.on("value", (snapshot) => {
let epicIkon = snapshot.val();
let currentResorts = resorts;
epicIkon.forEach(function (epicIkonResort) {
// find resort ID within currentResorts
let matchedResort = currentResorts.find(
(o) => o.name === epicIkonResort.name
);
// set isIkon and isEpic within currentResorts
if (matchedResort) {
matchedResort.isEpic = epicIkonResort.epic === 1 ? true : false;
matchedResort.isIkon = epicIkonResort.ikon === 1 ? true : false;
}
});
this.setState({
resorts: currentResorts,
});
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment