-
-
Save Andrew-Reid/f9b269e74bf6618dabf5a62d9420b1a9 to your computer and use it in GitHub Desktop.
meteors
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"> | |
<style> | |
</style> | |
<script src="https://d3js.org/d3.v5.min.js"></script> | |
<script src="https://unpkg.com/topojson-client@3"></script> | |
<body> | |
<svg width="960" height="600"></svg> | |
<script> | |
var us = d3.json('us.json'); | |
var meteoriteData = d3.json('https://raw.githubusercontent.com/FreeCodeCamp/ProjectReferenceData/master/meteorite-strike-data.json'); | |
var svg = d3.select("svg") | |
.style("width", "960px") | |
.style("height", "600px"); | |
var projection = d3.geoAlbersUsa(); | |
var path = d3.geoPath().projection(projection); | |
Promise.all([us, meteoriteData]).then(function (values) { | |
var map = values[0]; | |
console.log("map", map); | |
var meteoriteData = values[1]; | |
console.log("meteoriteData", meteoriteData); | |
svg.append("g") | |
.attr("fill", "#ccc") | |
.selectAll("path") | |
.data(topojson.feature(map, map.objects.states).features) | |
.enter().append("path") | |
.attr("d", path), | |
svg.append("path") | |
.datum(topojson.mesh(map, map.objects.states, (a, b) => a !== b)) | |
.attr("fill", "none") | |
.attr("stroke", "white") | |
.attr("stroke-linejoin", "round") | |
.attr("pointer-events", "none") | |
.attr("d", path), | |
svg.selectAll("circle") | |
.data(meteoriteData.features.filter(function(d) { | |
return d.geometry && d.geometry.coordinates && projection(d.geometry.coordinates); | |
})) | |
.enter() | |
.append("circle") | |
.attr("class", "circles") | |
.attr("r", 2) | |
.attr("cx", function(d) { return projection(d.geometry.coordinates)[0]; }) | |
.attr("cy", function(d) { return projection(d.geometry.coordinates)[1]; }) | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment