當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


d3.js geoBonne()用法及代碼示例

d3.js中的geoBonne()函數用於繪製Bonne偽圓錐equal-area投影。 Bonne投影可保持沿中央子午線和標準平行線的區域的準確形狀,但會逐漸偏離這些區域。它根據給定的地理JSON數據進行Bonne投影。

用法:

d3.geoBonne()

參數:此方法不接受任何參數。

返回值:此方法返回Bonne偽圓錐equal-area投影。

例:下麵的示例對世界進行Bonne偽圓錐形equal-area投影。



HTML

<!DOCTYPE html>  
<html lang="en">  
  
<head>  
    <meta charset="UTF-8" />  
    <meta name="viewport"
        content="width=device-width,  
                initial-scale=1.0"/>    
    <script src= 
        "https://d3js.org/d3.v4.js"> 
    </script> 
  
    <script src= 
        "https://d3js.org/d3-geo-projection.v2.min.js"> 
    </script>   
</head>  
  
<body>  
    <div style="width:700px; height:600px;">  
        <center>  
            <h3 style="color:grey">  
                Bonne Projection of World 
            </h3>   
        </center> 
  
        <svg width="700" height="550">  
        </svg>  
    </div>  
  
    <script> 
        var svg = d3.select("svg"), 
            width = +svg.attr("width"), 
            height = +svg.attr("height"); 
  
        // Bonne projection 
        var gfg = d3.geoBonne() 
            .scale(width / 1.5 / Math.PI) 
            .translate([width / 2, height / 2]) 
  
        // Loading the json data 
        d3.json("https://raw.githubusercontent.com/" 
            + "janasayantan/datageojson/master/" 
            + "geoworld%20.json",  
            function(data){ 
                // Draw the map 
                svg.append("g") 
                    .selectAll("path") 
                    .data(data.features) 
                    .enter().append("path") 
                    .attr("fill", "black") 
                    .attr("d", d3.geoPath() 
                        .projection(gfg) 
                    ) 
                    .style("stroke", "#ffff") 
        }) 
    </script> 
</body>  
  
</html>

輸出:




相關用法


注:本文由純淨天空篩選整理自jana_sayantan大神的英文原創作品 D3.js geoBonne() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。