Skip to content

Instantly share code, notes, and snippets.

@mohamed-ali
Last active August 29, 2015 14:06
Show Gist options
  • Save mohamed-ali/9d8b802d006baef7fce8 to your computer and use it in GitHub Desktop.
Save mohamed-ali/9d8b802d006baef7fce8 to your computer and use it in GitHub Desktop.
D3.js HTML5 canvas Map of Tunisia.
<!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>
Display the source blob
Display the rendered blob
Raw
Loading
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