Skip to content

Instantly share code, notes, and snippets.

@josecarlosgonz
Created May 29, 2014 18:41
Show Gist options
  • Save josecarlosgonz/06654c2c0692923044bc to your computer and use it in GitHub Desktop.
Save josecarlosgonz/06654c2c0692923044bc to your computer and use it in GitHub Desktop.
Map of Mexico with d3
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.municipalities {
fill: #222;
}
.municipalities :hover {
fill: orange;
}
.state-boundary {
fill: none;
stroke: #fff;
pointer-events: none;
}
.municipality-boundary {
fill: none;
stroke: #fff;
stroke-opacity: .25;
stroke-width: .5px;
pointer-events: none;
}
</style>
<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 = 628;
var path = d3.geo.path()
.projection(null);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("states.json", function(error, mx) {
svg.append("g")
.attr("class", "municipalities")
.selectAll("path")
.data(topojson.feature(mx, mx.objects.shp_vic).geometries)
.enter().append("path")
.attr("d", path)
.append("title")
.text(function(d) { return d.properties.name; });
});
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