I'm new to d3.js.
I want to draw many circles in each city portion of the map.
I have tried to fetch data from an API and it work.
However, it doesn't display the circles on each city without giving me any error.
Here is my script.js code:
//Define path generator
var path = d3.geo.path().projection(projection);
//Group SVG elements together
var features = svg.append("g");
//Load TopoJSON data
d3.json("Lebanon_Level2.json", function (error, syr) {
if (error) return console.error(error);
var subunits = topojson.feature(syr, syr.objects.gadm36_LBN_2);
// Bind data and create one path per TopoJSON feature
features.selectAll("path")
.data(topojson.feature(syr, syr.objects.gadm36_LBN_2).features)
.enter()
.append("path")
.attr("d", path)
.attr("fill", "#e8d8c3")
});
Fetch API data in d3.js
d3.json('https://localhost/API/covidinfo/read.php',function(data)
{
var location = data.records;
console.log(location);
features.selectAll('circle')
.data(location)
.enter()
.append('circle')
.attr('cx',function(d){
location.map(d=>{
return projection([d.lng,d.lat])[0];
})
})
.attr('cy',function(d){
location.map(d=>{
return projection([d.lng,d.lat])[1];
})
})
.attr("r", 15)
.style("fill", "red")
.style("opacity", 0.75);
});