Skip to content

Instantly share code, notes, and snippets.

@Andrew-Reid
Created October 31, 2019 20:08
Show Gist options
  • Save Andrew-Reid/f9b269e74bf6618dabf5a62d9420b1a9 to your computer and use it in GitHub Desktop.
Save Andrew-Reid/f9b269e74bf6618dabf5a62d9420b1a9 to your computer and use it in GitHub Desktop.
meteors
<!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>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment