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.
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
+ "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
+ "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:
Last Updated :
23 Sep, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...