import React, { useState, useEffect } from "react" import { geoEqualEarth, geoPath } from "d3-geo" import { feature } from "topojson-client"; import "./WorldMap.css"; const cities = [ // { name: "Jakarta", coordinates: [106.8650,-6.1751], population: 30539000 }, // { name: "Delhi", coordinates: [77.1025,28.7041], population: 24998000 }, // { name: "Manila", coordinates: [120.9842,14.5995], population: 24123000 }, // { name: "Karachi", coordinates: [67.0099,24.8615], population: 22123000 }, // { name: "Mumbai", coordinates: [72.8777,19.0760], population: 17712000 }, // { name: "Dhaka", coordinates: [90.4125,23.8103], population: 15669000 }, // { name: "Kolkata", coordinates: [88.3639,22.5726], population: 14667000 }, { name: "Nagpur", coordinates: [79.088860, 21.146633], population: 24667000 }, ] const projection = geoEqualEarth() .scale(160) .translate([ 800 / 2, 450 / 2 ]) const WorldMap = () => { const [geographies, setGeographies] = useState([]) useEffect(() => { fetch("/world-110m.json") .then(response => { if (response.status !== 200) { console.log(`There was a problem: ${response.status}`) return } response.json().then(worlddata => { setGeographies(feature(worlddata, worlddata.objects.countries).features) }) }) }, []) const handleCountryClick = countryIndex => { console.log("Clicked on country: ", geographies[countryIndex]) } const handleMarkerClick = i => { console.log("Marker: ", cities[i]) } return ( { geographies.map((d,i) => ( handleCountryClick(i) } /> )) } { cities.map((city, i) => ( handleMarkerClick(i) } /> )) } ) } export default WorldMap