Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptD3.js geoAzimuthalEqualArea() Function

D3.js geoAzimuthalEqualArea() Function

The geoAzimuthalEqualArea() function in d3.js is used to draw the Lambert azimuthal equal-area projection from the given geojson data. It is a projection that tries to maintain land features to their correct relative sizes while also maintaining the correct sense of direction from the center. The world here is projected onto a flat surface from any point on the globe.

Syntax:

d3.geoAzimuthalEqualArea()

Parameters: This method does not accept any parameters.

Return Value: This method returns the azimuthal equal-area projection.

Example 1: The following example draws the Lambert azimuthal equal-area projection of North and South America.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src="https://d3js.org/d3.v4.js">
    </script>
    <script src=
    </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>


Output:

Example 2: The following example draws the Lambert azimuthal equal-area projection of Africa.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src="https://d3js.org/d3.v4.js">
    </script>
    <script src=
    </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>


Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments