D3 albersUsa projection funtion return null

前端 未结 1 1527
無奈伤痛
無奈伤痛 2021-01-29 04:35

I\'m pretty new to D3 and I\'m trying to set point on a map.

I\'m confused as I created a projection with this code:

var projection = d3.geo
      .alber         


        
相关标签:
1条回答
  • 2021-01-29 05:17

    From the documentation

    # projection(location)

    […] May return null if the specified location has no defined projected position, such as when the location is outside the clipping bounds of the projection.

    The Albers USA projection is defined only within its borders and will yield null for coordinates outside the well-defined area.

    See this comparison of calls to projection(location) using [10,20], which is not valid, and [-110,40], which is a valid point:

    var projection = d3.geo
          .albersUsa()
          .scale(500)
          .translate([960, 500]);
          
    d3.selectAll("p")
        .data([[10,20],[-110,40]])
      .enter().append("p")
        .text(function(d) { return d + ": " + projection(d); });
    
     
    <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>

    0 讨论(0)
提交回复
热议问题