🏠 back to Observable

Cannot hightlight the regions in a simple map code

Dear all, I’m trying to highlight the selected country in green with lines of simple codes, but it didn’t work, I cannot find the bug currently. I think the error may occurs in the line 'if (label.includes(d.properties.name)) '? Thank you for your time!

The link is attached: simple world map code

The objects in the TopoJSON file that you are using have no name property. To fix this, simply replace your TopoJSON file here:

world = d3.json("https://unpkg.com/world-atlas@1/world/50m.json")

with this:

world = d3.json('https://unpkg.com/world-atlas@2.0.2/countries-50m.json')