Plotting points on a map with D3

前端 未结 1 1960
予麋鹿
予麋鹿 2020-12-01 10:10

I\'m trying to plot a few points onto a map using the D3 geo library based on latitudes and longitudes. However, when I pass these values into my projection function, it res

相关标签:
1条回答
  • 2020-12-01 10:38

    You have a simple typo in your code -- coordinates should be passed as (longitude, latitude) to the projection, not the other way round. This code should work fine:

     svg.selectAll(".pin")
      .data(places)
      .enter().append("circle", ".pin")
      .attr("r", 5)
      .attr("transform", function(d) {
        return "translate(" + projection([
          d.location.longitude,
          d.location.latitude
        ]) + ")";
      });
    
    0 讨论(0)
提交回复
热议问题