Created
August 8, 2017 17:34
-
-
Save milafrerichs/0b4b88ed0b2e979ef5c6f60fe12964c1 to your computer and use it in GitHub Desktop.
JS Bin Map with Ward 13 Buildings colored with number of floors // source http://jsbin.com/naxewa
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 Ward 13 Buildings colored with number of floors"> | |
<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,'https://gist.githubusercontent.com/milafrerichs/65d46d3815be79faed5a2b7f4976ad51/raw/41c6c6cd7bf37e8539bab1d843b73b80de4e852c/ward_18.geojson') | |
.awaitAll(function(error, results) { | |
boston = results[0]; | |
buildings = results[1]; | |
projection | |
.fitExtent([[20, 20], [600, 600]], buildings) | |
u = map.selectAll('path') | |
.data(boston.features); | |
u.enter() | |
.append('path') | |
.attr('d', geoGenerator) | |
.attr('fill', '#fff') | |
.attr('stroke', '#fff') | |
; | |
floorExtent = d3.extent(buildings.features, function(d) { return d.properties.NUM_FLOORS;}); | |
scale = d3.scaleLinear().domain(floorExtent).range(['red', 'yellow']).interpolate(d3.interpolateHcl); | |
overlay.selectAll('path').data(buildings.features) | |
.enter() | |
.append("path") | |
.attr('d', geoGenerator) | |
.style("fill", function(d) { | |
return scale(d.properties.NUM_FLOORS) | |
}) | |
.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,'https://gist.githubusercontent.com/milafrerichs/65d46d3815be79faed5a2b7f4976ad51/raw/41c6c6cd7bf37e8539bab1d843b73b80de4e852c/ward_18.geojson') | |
.awaitAll(function(error, results) { | |
boston = results[0]; | |
buildings = results[1]; | |
projection | |
.fitExtent([[20, 20], [600, 600]], buildings) | |
u = map.selectAll('path') | |
.data(boston.features); | |
u.enter() | |
.append('path') | |
.attr('d', geoGenerator) | |
.attr('fill', '#fff') | |
.attr('stroke', '#fff') | |
; | |
floorExtent = d3.extent(buildings.features, function(d) { return d.properties.NUM_FLOORS;}); | |
scale = d3.scaleLinear().domain(floorExtent).range(['red', 'yellow']).interpolate(d3.interpolateHcl); | |
overlay.selectAll('path').data(buildings.features) | |
.enter() | |
.append("path") | |
.attr('d', geoGenerator) | |
.style("fill", function(d) { | |
return scale(d.properties.NUM_FLOORS) | |
}) | |
.style("opacity", 0.75); | |
})</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 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,'https://gist.githubusercontent.com/milafrerichs/65d46d3815be79faed5a2b7f4976ad51/raw/41c6c6cd7bf37e8539bab1d843b73b80de4e852c/ward_18.geojson') | |
.awaitAll(function(error, results) { | |
boston = results[0]; | |
buildings = results[1]; | |
projection | |
.fitExtent([[20, 20], [600, 600]], buildings) | |
u = map.selectAll('path') | |
.data(boston.features); | |
u.enter() | |
.append('path') | |
.attr('d', geoGenerator) | |
.attr('fill', '#fff') | |
.attr('stroke', '#fff') | |
; | |
floorExtent = d3.extent(buildings.features, function(d) { return d.properties.NUM_FLOORS;}); | |
scale = d3.scaleLinear().domain(floorExtent).range(['red', 'yellow']).interpolate(d3.interpolateHcl); | |
overlay.selectAll('path').data(buildings.features) | |
.enter() | |
.append("path") | |
.attr('d', geoGenerator) | |
.style("fill", function(d) { | |
return scale(d.properties.NUM_FLOORS) | |
}) | |
.style("opacity", 0.75); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment