Last active
August 29, 2015 14:06
-
-
Save mohamed-ali/9d8b802d006baef7fce8 to your computer and use it in GitHub Desktop.
D3.js HTML5 canvas Map of Tunisia.
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://d3js.org/topojson.v1.min.js"></script> | |
<script> | |
var width = 960, | |
height = 700; | |
//computing projection | |
var projection = d3.geo.mercator() | |
.scale(3000) | |
.translate([0,2200]); | |
//preparing the canvas | |
var canvas = d3.select("body").append("canvas") | |
.attr("width", width) | |
.attr("height", height); | |
//adding context | |
var context = canvas.node().getContext("2d"); | |
//computing path | |
var path = d3.geo.path() | |
.projection(projection) | |
.context(context); | |
d3.json("tunisia.json", function(error, topology) { | |
path(topojson.feature(topology, topology.objects.governorates)); | |
context.stroke(); | |
}); | |
//set the height the bl.ocks.org preview | |
d3.select(self.frameElement).style("height", height + "px"); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment