Skip to content

Instantly share code, notes, and snippets.

@wsvekla
Last active October 24, 2018 16:40
Show Gist options
  • Save wsvekla/4348435 to your computer and use it in GitHub Desktop.
Save wsvekla/4348435 to your computer and use it in GitHub Desktop.
Guatemala TopoJSON
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.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
path {
fill: none;
stroke: #000;
stroke-width: .5px;
}
.country {
stroke-width: 1px;
}
.municipality {
stroke: #aaa;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v0.min.js"></script>
<script>
var width = 960,
height = 500;
var projection = d3.geo.mercator()
.center([-90.22, 15.78])
.scale(6700);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("guatemala.json", function(error, topology) {
svg.append("path")
.datum(topojson.object(topology, topology.objects.guatemala0))
.attr("d", path)
.attr("class", "country");
svg.append("path")
.datum(topojson.mesh(topology, topology.objects.guatemala1, function(a,b){return a.id !== b.id;}))
.attr("d", path)
.attr("class", "department");
svg.append("path")
.datum(topojson.mesh(topology, topology.objects.guatemala2, function(a,b){return a.id !== b.id;}))
.attr("d", path)
.attr("class", "municipality");
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment