Created
August 8, 2017 17:33
-
-
Save milafrerichs/b58ac6a81e05c3f98471cb75e6239ba4 to your computer and use it in GitHub Desktop.
JS Bin Map with Schools sized Num Students // source http://jsbin.com/casuvat
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> | |
<html> | |
<head> | |
<meta name="description" content="Map with Schools sized Num Students"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.3/d3.min.js"></script> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
path | |
fill: #ccc | |
</style> | |
</head> | |
<body> | |
<div id="map" style="width: 600px; height: 600px;"> | |
<svg width="600" height="600"> | |
<g class="background"></g> | |
<g class="overlay"></g> | |
</svg> | |
</div> | |
<script id="jsbin-javascript"> | |
var projection = d3.geoAlbers(); | |
var geoGenerator = d3.geoPath() | |
.projection(projection); | |
var circle = d3.geoCircle().radius(5);//.center([0.1278, 51.5074]).radius(5) | |
var map = d3.select('#map g.background'); | |
var overlay = d3.select('#map g.overlay'); | |
var q = d3.queue(); | |
q.defer(d3.json,'https://raw.githubusercontent.com/codeforamerica/click_that_hood/master/public/data/boston.geojson'); | |
q.defer(d3.json,'http://bostonopendata-boston.opendata.arcgis.com/datasets/cbf14bb032ef4bd38e20429f71acb61a_2.geojson') | |
.awaitAll(function(error, results) { | |
boston = results[0]; | |
points = results[1]; | |
var extent = d3.extent(points.features, function(d) { return d.properties.NumStudents13;}); | |
var scale = d3.scaleLinear().domain(extent).range([1,10]); | |
projection | |
.fitExtent([[20, 20], [600, 600]], boston) | |
u = map.selectAll('path') | |
.data(boston.features); | |
u.enter() | |
.append('path') | |
.attr('d', geoGenerator) | |
.attr('fill', '#ccc') | |
.attr('stroke', '#ccc') | |
; | |
overlay.selectAll('g').data(points.features) | |
.enter() | |
.append("g") | |
.attr('transform', function(d) { | |
return 'translate('+projection(d.geometry.coordinates)+')'; | |
}).attr('width', 20).attr('d', geoGenerator) | |
.style("fill", "yellow") | |
.style("opacity", 0.75).append('circle').attr('r',function(d) { return scale(d.properties.NumStudents13);}); | |
}) | |
</script> | |
<script id="jsbin-source-css" type="text/css">path | |
fill: #ccc</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var projection = d3.geoAlbers(); | |
var geoGenerator = d3.geoPath() | |
.projection(projection); | |
var circle = d3.geoCircle().radius(5);//.center([0.1278, 51.5074]).radius(5) | |
var map = d3.select('#map g.background'); | |
var overlay = d3.select('#map g.overlay'); | |
var q = d3.queue(); | |
q.defer(d3.json,'https://raw.githubusercontent.com/codeforamerica/click_that_hood/master/public/data/boston.geojson'); | |
q.defer(d3.json,'http://bostonopendata-boston.opendata.arcgis.com/datasets/cbf14bb032ef4bd38e20429f71acb61a_2.geojson') | |
.awaitAll(function(error, results) { | |
boston = results[0]; | |
points = results[1]; | |
var extent = d3.extent(points.features, function(d) { return d.properties.NumStudents13;}); | |
var scale = d3.scaleLinear().domain(extent).range([1,10]); | |
projection | |
.fitExtent([[20, 20], [600, 600]], boston) | |
u = map.selectAll('path') | |
.data(boston.features); | |
u.enter() | |
.append('path') | |
.attr('d', geoGenerator) | |
.attr('fill', '#ccc') | |
.attr('stroke', '#ccc') | |
; | |
overlay.selectAll('g').data(points.features) | |
.enter() | |
.append("g") | |
.attr('transform', function(d) { | |
return 'translate('+projection(d.geometry.coordinates)+')'; | |
}).attr('width', 20).attr('d', geoGenerator) | |
.style("fill", "yellow") | |
.style("opacity", 0.75).append('circle').attr('r',function(d) { return scale(d.properties.NumStudents13);}); | |
})</script></body> | |
</html> |
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
path | |
fill: #ccc |
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
var projection = d3.geoAlbers(); | |
var geoGenerator = d3.geoPath() | |
.projection(projection); | |
var circle = d3.geoCircle().radius(5);//.center([0.1278, 51.5074]).radius(5) | |
var map = d3.select('#map g.background'); | |
var overlay = d3.select('#map g.overlay'); | |
var q = d3.queue(); | |
q.defer(d3.json,'https://raw.githubusercontent.com/codeforamerica/click_that_hood/master/public/data/boston.geojson'); | |
q.defer(d3.json,'http://bostonopendata-boston.opendata.arcgis.com/datasets/cbf14bb032ef4bd38e20429f71acb61a_2.geojson') | |
.awaitAll(function(error, results) { | |
boston = results[0]; | |
points = results[1]; | |
var extent = d3.extent(points.features, function(d) { return d.properties.NumStudents13;}); | |
var scale = d3.scaleLinear().domain(extent).range([1,10]); | |
projection | |
.fitExtent([[20, 20], [600, 600]], boston) | |
u = map.selectAll('path') | |
.data(boston.features); | |
u.enter() | |
.append('path') | |
.attr('d', geoGenerator) | |
.attr('fill', '#ccc') | |
.attr('stroke', '#ccc') | |
; | |
overlay.selectAll('g').data(points.features) | |
.enter() | |
.append("g") | |
.attr('transform', function(d) { | |
return 'translate('+projection(d.geometry.coordinates)+')'; | |
}).attr('width', 20).attr('d', geoGenerator) | |
.style("fill", "yellow") | |
.style("opacity", 0.75).append('circle').attr('r',function(d) { return scale(d.properties.NumStudents13);}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment