D3.js geoAzimuthalEquidistant() Function - GeeksforGeeks

18 Sep, 2020
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="https://d3js.org/d3-geo-projection.v2.min.js">    </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="https://d3js.org/d3-geo-projection.v2.min.js">    </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 roating -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:
D3.js
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Convert a string to an integer in JavaScript
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
How to Open URL in New Tab using JavaScript ?
Difference Between PUT and PATCH Request
Roadmap to Become a Web Developer in 2022
Installation of Node.js on Linux
How to fetch data from an API in ReactJS ?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to insert spaces/tabs in text using HTML/CSS?