Friday, January 10, 2025
Google search engine
HomeLanguagesJavascriptD3.js geoAzimuthalEquidistant() Function

D3.js geoAzimuthalEquidistant() Function

The geoAzimuthalEquidistant() function in d3.js is used to draw the Azimuthal equidistant projection from the given geojson data. It is a map projection where all the points on the map are at correct distances from the center point proportionally. Also, all points on the map are in the correct direction from the center point.

Syntax:

d3.geoAzimuthalEquidistant()

Parameters: This method does not accept any parameters.

Return Value: This method returns the Azimuthal equidistant projection.

Example 1: The following example draws the Azimuthal equidistant projection of the world with the center at (0,0).

HTML




<html>
 
<head>
    <script src="https://d3js.org/d3.v4.js">
    </script>
    <script src=
    </script>
</head>
 
<body>
    <div style="width:800px;
              height:600px;">
        <center>
            <h3 style="color:black">
                AzimuthalEquidistant 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");
 
        // AzimuthalEquidistant projection
        var gfg = d3.geoAzimuthalEquidistant()
            .scale(width / 1.5 / Math.PI)
            .translate([width / 2, height / 2]);
 
        // Loading the geojson 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", "Silver")
                    .attr("d", d3.geoPath()
                        .projection(gfg)
                    )
                    .style("stroke", "#ffff")
            });
    </script>
</body>
 
</html>


Output:

Example 2: The following example makes Azimuthal equidistant projection centered at(-10,0) and rotated 10 degrees anti-clockwise with respect to the x-axis.

HTML




<!DOCTYPE html>
<html>
 
<head>
    <script src="https://d3js.org/d3.v4.js">
    </script>
    <script src=
    </script>
</head>
 
<body>
    <div style="width:700px;
              height:600px;">
        <center>
            <h3 style="color:grey">
                AzimuthalEquidistant 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");
 
        // AzimuthalEquidistant  projection
        // Center(0,-10) and rotating -10 degree
        var gfg = d3.geoAzimuthalEquidistant()
            .scale(width / 1.5 / Math.PI)
            .rotate([-10, 0])
            .center([0, -10])
            .translate([width / 2, height / 2]);
 
        // Loading the geojson data
        d3.json("https://raw.githubusercontent.com/" +
            "janasayantan/datageojson/master/" +
            "world.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:

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