Skip to content

Instantly share code, notes, and snippets.

@jonsadka jonsadka/.block
Last active Feb 13, 2017

What would you like to do?
TopoJSON Map of Los Angeles
license: mit
<!DOCTYPE html>
<meta charset="utf-8">
<script src=""></script>
<script src=""></script>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
path {
stroke: gray;
fill: none;
const width = 960;
const height = 960;
const svg ='body').append('svg')
.attr('height', width)
.attr('width', height);
.defer(d3.json, 'la.json')
function render(error, la) {
if (error) return console.warn(error);
// Create a unit projection.
const laProjection = d3.geoAlbers()
.translate([0, 0]);
// Create a path generator
const path = d3.geoPath()
// Compute the bounds of a feature of interest,
// then derive scale & translate.
const laBounds = path.bounds(la);
const laScale = 0.95 / Math.max(
(laBounds[1][0] - laBounds[0][0]) / width,
(laBounds[1][1] - laBounds[0][1]) / height
const laTranslate = [
(width - laScale * (laBounds[1][0] + laBounds[0][0])) / 2,
(height - laScale * (laBounds[1][1] + laBounds[0][1])) / 2
// Update the projection to use computed scale & translate.
console.log(laScale, laTranslate)
.attr('d', path);
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.