// @flow import * as React from "react"; import { ComposableMap, ZoomableGroup, Geographies, Geography, } from "react-simple-maps"; import data from "./data/world-50m.json"; import { scaleLinear } from "d3-scale"; const wrapperStyles = { width: "100%", height: "auto", maxWidth: "100%", margin: "0 auto", fontFamily: "Roboto, sans-serif", }; type State = { origin: { x: number, y: number }, content: string, }; const popScale = scaleLinear() .domain([0, 100000000, 1400000000]) .range(["#CFD8DC", "#607D8B", "#37474F"]); class ReactSimpleMap extends React.PureComponent { state = { origin: { x: 0, y: 0 }, content: "", }; handleMove = ( geography: { properties: { name: string, pop_est: string } }, evt: SyntheticMouseEvent<> ): void => { const x = evt.clientX; const y = evt.clientY + window.pageYOffset; this.setState({ origin: { x, y }, content: geography.properties.name + ": " + geography.properties.pop_est, }); }; handleLeave = (): void => { this.setState({ content: "" }); }; render() { return (
{this.state.content && (
{this.state.content}
)} {(geographies, projection) => geographies.map((geography, i) => ( )) }
); } } export default ReactSimpleMap;