Last active
August 14, 2020 13:50
-
-
Save skflowne/e306acdbd3092d2ec42cc10e840d951e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import React from "react" | |
import DeckGLMap from "./DeckGLMap" | |
import { ScatterplotLayer } from "@deck.gl/layers" | |
import { useRecoilValue } from "recoil" | |
import { statusByDateQuery, countriesQuery, API_DATE_FORMAT } from "../../state/api" | |
import { format } from "date-fns" | |
const DataMap = () => { | |
const date = new Date() | |
const formattedDate = format(date, API_DATE_FORMAT) | |
const todayStatus = useRecoilValue(statusByDateQuery(formattedDate)) | |
const countries = useRecoilValue(countriesQuery) | |
const data = todayStatus.map((status) => { | |
const country = countries[status.country] | |
return { | |
name: country.name, | |
coordinates: [country.longitude, country.latitude], | |
...status, | |
} | |
}) | |
const covidDataLayer = new ScatterplotLayer({ | |
id: "covid-data-layer", | |
data, | |
stroked: false, | |
filled: true, | |
getPosition: (d) => d.coordinates, | |
getRadius: (d) => (d.cases > 0 ? (Math.log10(d.cases) + d.cases / 100000) * 20000 : 0), | |
getFillColor: (d) => [255, 0, 0], | |
}) | |
const layers = [covidDataLayer] | |
return <DeckGLMap layers={layers} /> | |
} | |
export default DataMap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment