当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


d3.js geoAzimuthalEqualArea()用法及代码示例


d3.js中的geoAzimuthalEqualArea()函数用于从给定的geojson数据绘制兰伯特方位角equal-area投影。它是一种投影,试图将地物保持在正确的相对大小,同时也保持从中心的正确方向感。从地球上的任何角度,这里的世界都投影到平坦的表面上。

用法:

d3.geoAzimuthalEqualArea()

参数:此方法不接受任何参数。

返回值:此方法返回方位角equal-area投影。

范例1:以下示例绘制了北美和南美的Lambert方位角equal-area投影。



HTML

<!DOCTYPE html> 
<html> 
  
<head> 
    <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:300px;  
              height:700px;"> 
        <center> 
            <h4 style="color:green"> 
                AzimuthalEqualArea Projection 
                of America 
            </h4> 
        </center> 
        <svg width="400" height="300"> 
        </svg> 
    </div> 
    <script> 
        var svg = d3.select("svg"), 
            width = +svg.attr("width"), 
            height = +svg.attr("height"); 
  
        // AzimuthalEqualArea projection 
        var gfg = d3.geoAzimuthalEqualArea() 
            .scale(width / 1.5 / Math.PI) 
            .translate([width / 2, height / 2]); 
  
        // Loading the json data  
        d3.json("https://raw.githubusercontent.com/" + 
            "janasayantan/datageojson/master/" + 
            "america.json", 
            function (data) { 
  
                // Draw the map 
                svg.append("g") 
                    .selectAll("path") 
                    .data(data.features) 
                    .enter().append("path") 
                    .attr("fill", "green") 
                    .attr("d", d3.geoPath() 
                        .projection(gfg) 
                    ) 
                    .style("stroke", "#ffff") 
            }); 
    </script> 
</body> 
  
</html>

输出:

范例2:以下示例绘制了非洲的Lambert方位equal-area投影。

HTML

<!DOCTYPE html> 
<html> 
  
<head> 
    <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:600px; 
              height:300px;"> 
        <center> 
            <h4 style="color:green"> 
                AzimuthalEqualArea Projection 
                of Africa 
            </h4> 
        </center> 
        <svg width="600" height="300"> 
        </svg> 
    </div> 
    <script> 
        var svg = d3.select("svg"), 
            width = +svg.attr("width"), 
            height = +svg.attr("height"); 
  
        // AzimuthalEqualArea 
        var gfg = d3.geoAzimuthalEqualArea() 
            .scale(width / 1.5 / Math.PI) 
            .translate([width / 2, height / 2]); 
  
        // Loading the json data  
        d3.json("https://raw.githubusercontent.com/" + 
            "janasayantan/datageojson/master/" + 
            "geoAfrica.json", 
            function (data) { 
  
                // Draw the map 
                svg.append("g") 
                    .selectAll("path") 
                    .data(data.features) 
                    .enter().append("path") 
                    .attr("fill", "olive") 
                    .attr("d", d3.geoPath() 
                        .projection(gfg) 
                    ) 
                    .style("stroke", "#ffff") 
            }); 
    </script> 
</body> 
  
</html>

输出:




相关用法


注:本文由纯净天空筛选整理自jana_sayantan大神的英文原创作品 D3.js geoAzimuthalEqualArea() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。