Last active
March 17, 2017 00:01
-
-
Save Andrew-Reid/496078bd5e37fd22a9b43fd6be84b36b to your computer and use it in GitHub Desktop.
geoTransform Example
This file contains 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
<html> | |
<head> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.6.0/d3.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/2.2.0/topojson.js"></script> | |
</head> | |
<body> | |
<script> | |
var width = 900; | |
var height = 450; | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
function scale (scaleFactor,width,height) { | |
return d3.geoTransform({ | |
point: function(x, y) { | |
this.stream.point( (x - width/2) * scaleFactor + width/2 , (y - height/2) * scaleFactor + height/2); | |
} | |
}); | |
} | |
d3.json("us.json", function (error, us){ | |
var path = d3.geoPath().projection(scale(0.2,width,height)) | |
svg.append("g") | |
.attr("class", "states") | |
.selectAll("path") | |
.data(topojson.feature(us, us.objects.states).features) | |
.enter().append("path") | |
.attr("fill", "gray") | |
.attr("d", path); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment