I have a USA country with states map drawn using d3.js. I want to show few locations on this map (as dots or small circles). The following code shows the map with states. I have the longitude and latitude values for a few locations. How do I draw these locations on this map?
(async function getMapData() {
const DATA_URL = "https://cdn.jsdelivr.net/npm/us-atlas@3/states-albers-10m.json";
let resp = await fetch(DATA_URL);
const topoJson = await resp.json();
const geoJson = await topojson.feature(topoJson, topoJson.objects.states).features
await drawMap(geoJson);
console.log("Done");
})();
async function drawMap(data) {
const w = 1000;
const h = 800;
const svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
svg.append("g")
.selectAll("path")
.data(data)
.join("path")
.attr("d", d3.geoPath())
.style("fill", "none")
.style("stroke", "black")
.style("stroke-width", "1px");
const locations = [
{ long: -73.9249, lat: 40.6943 },
{ long: -118.4068, lat: 34.1141 },
{ long: -96.7667, lat: 32.7935 }
];
// Show the locations on the map
}
.locations {
fill: blue;
}
<script src='https://d3js.org/d3.v6.min.js'></script>
<script src="https://unpkg.com/topojson@3"></script>
I had tried using the following as an example with my data and the newer versions of d3js - no success: https://plnkr.co/edit/hCYQKhbJKvbefIa0uncC?preview