World map with rivers and lakes using Natural Earth data.
Last active
July 3, 2020 17:46
-
-
Save animateddata/0949801eba0d51c80f22490db665f8c3 to your computer and use it in GitHub Desktop.
World map with rivers
This file contains 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: gpl-3.0 | |
height: 960 | |
border: no |
This file contains 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> | |
<meta charset="utf-8"> | |
<head> | |
<title>Geo (spinning))</title> | |
</head> | |
<style> | |
body { | |
background-color: #eee; | |
} | |
</style> | |
<body> | |
<canvas id="content"></canvas> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/3.0.0/topojson.min.js"></script> | |
<script> | |
var context = document.getElementById('content').getContext('2d'); | |
var width = window.innerWidth; | |
var height = window.innerHeight; | |
var size = d3.min([width, height]); | |
var landGeojson, riversGeojson, lakesGeojson; | |
d3.select('#content') | |
.attr('width', width + 'px') | |
.attr('height', height + 'px'); | |
var projection = d3.geoOrthographic() | |
.scale(0.45 * size) | |
.translate([0.5 * width, 0.5 * height]); | |
var geoGenerator = d3.geoPath() | |
.projection(projection) | |
.context(context); | |
function drawFeatures(features, fill) { | |
context.beginPath(); | |
geoGenerator({type: 'FeatureCollection', features: features}); | |
fill ? context.fill() : context.stroke(); | |
} | |
function update(t) { | |
context.clearRect(0, 0, width, height); | |
projection.rotate([-t / 1000 - 40]) | |
context.lineWidth = 0.3; | |
context.strokeStyle = '#999'; | |
drawFeatures(landGeojson.features, false); | |
context.strokeStyle = '#3882bc'; | |
context.lineWidth = 0.5; | |
drawFeatures(riversGeojson.features, false); | |
context.fillStyle = '#3882bc'; | |
drawFeatures(lakesGeojson.features, true); | |
window.requestAnimationFrame(update); | |
} | |
// REQUEST DATA | |
d3.json('ne.json', function(err, json) { | |
landGeojson = topojson.feature(json, json.objects.ne_50m_admin_0_countries) | |
riversGeojson = topojson.feature(json, json.objects.ne_10m_rivers_lake_centerlines) | |
lakesGeojson = topojson.feature(json, json.objects.ne_10m_lakes) | |
window.requestAnimationFrame(update); | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment