And then in another cell, you’ve got the following:
const svg = d3.select("#map")
.append("svg")
But there’s no reason to think that your first cell, with ID map is even in the DOM at that point. In fact, if you run the following in it’s own cell:
d3.select("#map").node()
I think you’ll find that you get null. I would recommend that you read through the documentation in general and, particularly How Observable runs to more fully understand that.
My recommendation would be an idiom like so:
{
let svg = d3.create('svg')
...
return svg.node();
}
You can have a look at this notebook to see how that works:
Observable is a notebook based platform that allows easy access to quite a lot of Javascript libraries. Your code uses a library called D3, which is designed largely with power and flexibility in mind. While I like and use it often, it admittedly has a reputation of having a steep learning curve. The “complications” you refer to likely arise there, rather than within Observable itself.
If you want to create data based maps on Observable using a simpler library, I’d recommend looking into Plot.geo. That link contains several examples illustrating how to plot points on a map.
If that leads to new questions, feel free to open new topics here on the forum.