Skip to content

Instantly share code, notes, and snippets.

@milafrerichs
Created August 8, 2017 17:36
Show Gist options
  • Save milafrerichs/ed4f2efdf8c57a8f0e2f2d145759469f to your computer and use it in GitHub Desktop.
Save milafrerichs/ed4f2efdf8c57a8f0e2f2d145759469f to your computer and use it in GitHub Desktop.
JS Bin Map with schools and school sized sized // source http://jsbin.com/tukipip
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Map with schools and school sized sized with circles">
<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 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('circle').data(points.features)
.enter()
.append("circle")
.attr("cx", function(d) {
return projection(d.geometry.coordinates)[0];
})
.attr("cy", function(d) {
return projection(d.geometry.coordinates)[1];
})
.attr("r", function(d) { return scale(d.properties.NumStudents13);})
.style("fill", "yellow")
.style("opacity", 0.75);
})
</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 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('circle').data(points.features)
.enter()
.append("circle")
.attr("cx", function(d) {
return projection(d.geometry.coordinates)[0];
})
.attr("cy", function(d) {
return projection(d.geometry.coordinates)[1];
})
.attr("r", function(d) { return scale(d.properties.NumStudents13);})
.style("fill", "yellow")
.style("opacity", 0.75);
})</script></body>
</html>
var projection = d3.geoAlbers();
var geoGenerator = d3.geoPath()
.projection(projection);
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('circle').data(points.features)
.enter()
.append("circle")
.attr("cx", function(d) {
return projection(d.geometry.coordinates)[0];
})
.attr("cy", function(d) {
return projection(d.geometry.coordinates)[1];
})
.attr("r", function(d) { return scale(d.properties.NumStudents13);})
.style("fill", "yellow")
.style("opacity", 0.75);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment