-
-
Save Andrew-Reid/759e0101223c1f029c26b56ca7ad7759 to your computer and use it in GitHub Desktop.
Geo.transform d3v3 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,offsetX,offsetY) { | |
return d3.geoTransform({ | |
point: function(x, y) { | |
this.stream.point( (x - width/2) * scaleFactor + width/2 - offsetX , - (y - height/2) * scaleFactor + height/2 + offsetY); | |
} | |
}); | |
} | |
d3.json("sa-all.json", function (error, sa){ | |
var path = d3.geoPath().projection(scale(0.04,width,height,150,225)) | |
svg.append("g") | |
.selectAll("path") | |
.data(sa.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