Skip to content

Instantly share code, notes, and snippets.

@wsvekla
Last active December 10, 2015 19:58
Show Gist options
  • Save wsvekla/4485308 to your computer and use it in GitHub Desktop.
Save wsvekla/4485308 to your computer and use it in GitHub Desktop.
Datos de Guatemala con D3 y CartoDB

Estos límites municipales de Guatemala se extraen de un archivo GeoJSON guardado en una tabla en CartoDB. Shapefile original fue recogido de GADM, la base de datos de global áreas administrativas.

<!DOCTYPE html>
<meta charset="utf-8">
<style>
path {
fill: #aaa;
stroke: #fff;
stroke-width: .5px;
}
path:hover {
fill: red
}
</style>
<body>
<script src="http://d3js.org/d3.v3.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)
.call(d3.behavior.zoom()
.on("zoom", redraw))
.append("g");
d3.json("http://wsvekla.cartodb.com/api/v2/sql?format=GeoJSON&q=SELECT * FROM gtm_adm2", function(error, geojson) {
svg.selectAll("path")
.data(geojson.features)
.enter().append("path")
.attr("d", path)
});
function redraw() {
svg.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment