Built with blockbuilder.org
Created
October 4, 2018 16:01
-
-
Save almccon/1bcde7452450c153d8a0684085f249fd to your computer and use it in GitHub Desktop.
D3v5 map example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v5.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
svg { width: 100%; height: 90%;} | |
</style> | |
</head> | |
<body> | |
<script> | |
var svg = d3.select("body").append("svg"); | |
var projection = d3.geoEqualEarth().rotate([90, 0, 0]); | |
var path = d3.geoPath().projection(projection); | |
var url = "http://enjalot.github.io/wwsd/data/world/world-110m.geojson"; | |
var data_url = "http://enjalot.github.io/wwsd/data/world/ne_50m_populated_places_simple.geojson"; | |
Promise.all([d3.json(url), d3.json(data_url)]).then(function(data) { | |
var world = data[0]; | |
var places = data[1]; | |
svg.append("path") | |
.attr("d", path(world)) | |
.attr("fill", "lightgray") | |
.attr("stroke", "white"); | |
svg.selectAll("circle") | |
.data(places.features) | |
.enter() | |
.append("circle") | |
.attr("r", function(d) { | |
return d.properties.pop_max / 1000000; | |
}) | |
.attr("cx", function(d) { | |
return projection(d.geometry.coordinates)[0] | |
}) | |
.attr("cy", function(d) { | |
return projection(d.geometry.coordinates)[1] | |
}) | |
.attr("fill", "darkgreen") | |
.attr("opacity", 0.5) | |
window.setTimeout(function() { | |
svg.selectAll("circle") | |
.transition().duration(5000) | |
.attr("r", function(d) { | |
return d.properties.pop_min / 1000000; | |
}); | |
}, 5000); | |
}); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment