Built with blockbuilder.org
Last active
April 8, 2017 00:14
-
-
Save nohevog1/bbb4d9564d6720c67055f1b6e3541a6e to your computer and use it in GitHub Desktop.
HW7_FV_2
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: mit |
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> | |
#streets { | |
fill: none; | |
stroke: black; | |
stroke-width: 1.5px; | |
stroke-linejoin: round; | |
} | |
</style> | |
<svg width="960" height="500"></svg> | |
<script src="//d3js.org/d3.v4.min.js"></script> | |
<script src="//d3js.org/d3-tile.v0.0.min.js"></script> | |
<script src="//d3js.org/topojson.v1.min.js"></script> | |
<script> | |
var pi = Math.PI, | |
tau = 2 * pi; | |
var svg = d3.select("svg"), | |
width = +svg.attr("width"), | |
height = +svg.attr("height"); | |
var projection = d3.geoMercator() | |
.scale((1 << 18) / tau) | |
.translate([width / 2, height / 2]) | |
.center([-83.15, 42.43]); | |
var path = d3.geoPath() | |
.projection(projection); | |
var url = "https://umbcvis.github.io/classes/class-03/us.json" | |
var usgs = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson"; | |
d3.queue()// this function will only be called after both functions are called | |
.defer(d3.json,url) | |
.defer(d3.json,usgs) | |
.await(ready) | |
function ready(error, us, json){ | |
//var states =array of geojson states | |
var states = us.objects.us.geometries.map(function(d) { return topojson.feature(us, d); }) | |
var ok = states.filter(function(d){return d.properties.name === "Oklahoma";}); | |
ok=ok[0]; | |
console.log('HERE I AM', states.length, ok.length); | |
var extent = [[0,0],[width,height]]; | |
projection = projection.fitExtent(extent, ok); | |
console.log("HERE I AM AGAIN", projection.translate()) | |
projection.translate([2225,-672]) | |
var tiles = d3.tile() | |
.size([width, height]) | |
.scale(projection.scale() * tau) | |
.translate(projection([0, 0])) | |
(); | |
svg.selectAll("image") | |
.data(tiles) | |
.enter().append("image") | |
.attr("xlink:href", function(d) { return "http://" + "abc"[d[1] % 3] + ".tile.openstreetmap.org/" + d[2] + "/" + d[0] + "/" + d[1] + ".png"; }) | |
.attr("x", function(d) { return (d[0] + tiles.translate[0]) * tiles.scale; }) | |
.attr("y", function(d) { return (d[1] + tiles.translate[1]) * tiles.scale; }) | |
.attr("width", tiles.scale) | |
.attr("height", tiles.scale); | |
svg.append("path") | |
.attr("id", "streets") | |
.datum(topojson.mesh(us, us.objects.us)) | |
.attr("d", path); | |
console.log('HERE I AM BEFORE', json.features.length) | |
var quakes = json.features.filter(function(d){return d3.geoContains(ok, d.geometry.coordinates)}) | |
console.log('HERE I AM AFTER', quakes.length) | |
svg.selectAll("path.quake") | |
.data(quakes)//filtered quakes | |
.enter().append("path") | |
.attr("class", "quake")//defining class quake for consistency | |
.style("fill", "crimson") | |
.attr("d", path) | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment