The following is a map of Chicago which I've created in D3.js, and the JS code to render it.
I had a very hard time centering Chicago within my viewfinder (the white box). After much trial and error, I was finally able to make it work, with the long/lat of [8.25, 41.88205]
and a rotation of [92.35, .5, -4]
, using the Albers projection. This seems weird to me, since the long/lat of Chicago should be [87.627815, 41.88205]
.
So, my questions are: what is up with the 8.25
longitude? Why doesn't D3 center Chicago on my screen simply with the long/lat of [87.627815, 41.88205]
? And why do I need to apply the rotation at all?
BTW, the community_areas_sm.geojson
file comes off the City of Chicago website, and contains correct long/lat values.
<script>
var width = 600,
height = 750
var svg = d3.select("#map").append("svg")
.attr("width", width)
.attr("height", height)
var map = d3.json(
"/static/data/community_areas_sm.geojson", function(error, map) {
if (error) return console.error(error)
var proj = d3.geo.albers()
.center([8.25, 41.88205])
.parallels([40, 45])
.scale(105000)
.rotate([92.35, .5, -4])
.translate([width / 2, height / 2])
svg.selectAll("path")
.data(map.features)
.enter().append("path")
.attr("d", d3.geo.path().projection(proj))
}
)
</script>