Skip to content

Instantly share code, notes, and snippets.

@rveciana
Last active April 14, 2016 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rveciana/f00299fdacf079ecf3a60aca63eef66d to your computer and use it in GitHub Desktop.
Save rveciana/f00299fdacf079ecf3a60aca63eef66d to your computer and use it in GitHub Desktop.
mercatorEcuador
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.region{
fill: #aca;
stroke: #000;
stroke-width: 0.5px
}
.graticule {
fill: none;
stroke: #777;
stroke-width: .5px;
stroke-opacity: .5;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="https://rawgit.com/rveciana/d3-composite-projections/v0.4.0/mercatorEcuador-proj.min.js"></script>
<script>
var width = 600,
height = 500;
var projection = d3.geo.mercatorEcuador();
var graticule = d3.geo.graticule().step([2, 2]);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("d", path);
d3.json("https://rawgit.com/rveciana/5919944/raw/b85030e7d66e7273c19e371179b23c3e671f6838/ecuador.json", function(error, ecuador) {
var land = topojson.feature(ecuador, ecuador.objects.ecuador);
svg.selectAll(".region")
.data(land.features)
.enter()
.append("path")
.attr("d", path)
.attr("class","region")
.on("mouseover", function(d,i) {
d3.select(this)
.transition()
.style("fill", "red");
})
.on("mouseout", function(d,i) {
d3.select(this)
.transition()
.style("fill", "#aca");
});
svg
.append("path")
.style("fill","none")
.style("stroke","#000")
.attr("d", projection.getCompositionBorders());
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment