D3.js geoEckert1() Function
D3.js is a JavaScript library for producing dynamic, interactive data visualizations in web browsers. It makes use of Scalable Vector Graphics, HTML5, and Cascading Style Sheets standards.
The geoEckert1() function in d3.js is used to draw the Eckert I projection which is a compromise pseudocylindrical map projection with rectilinear meridians and an odd appearance. The projection was introduced by Max Eckert in 1906. The geoEckert1() function makes an Eckert1 projection from given geo JSON data.
Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!
Syntax:
d3.geoEckert1()
Parameters: This method does not accept any parameters.
Return Value: This method creates an Eckert1 projection from JSON data.
Example 1: The following example makes the Eckert1 projection of the Africa Continent.
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <script src= </script> <script src= </script></head> <body> <div style="width:400px; height:300px;"> <svg width="600" height="300"> </svg> </div> <script> var svg = d3.select("svg"), width = +svg.attr("width"), height = +svg.attr("height"); // creating Eckert1 projection var gfg = d3.geoEckert1() .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", "grey") .attr("d", d3.geoPath() .projection(gfg) ).style("stroke", "#ffff") }) </script></body> </html> |
Output:
Ecart1 Projection of Africa
Example 2: The following example makes the Eckert1 projection of the world.
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <script src= </script> <script src= </script></head> <body> <div style="width:700px; height:600px;"> <center> <h3 style="color:grey"> Eckart1 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"); // Eckart1 projection var gfg = d3.geoEckert1() .scale(width / 1.5 / Math.PI) .translate([width / 2, height / 2]) // Loading the json 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", "blue") .attr("d", d3.geoPath() .projection(gfg) ).style("stroke", "#ffff") }) </script></body> </html |
Output:


