Skip to content

Instantly share code, notes, and snippets.

@rveciana
Last active March 1, 2016 10:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rveciana/aec08199d43759e98afe to your computer and use it in GitHub Desktop.
d3-composite-projections conicConformalPortugal

This file shows how to use the conicConformalPortugal projection from d3-composite-projections. Since the world layer is used, note that the Iberian Peninsula is clipped at the projection border. These projections work well when used at the place they are intended for.

<!DOCTYPE html>
<meta charset="utf-8">
<style>
.land {
fill: #222;
}
.county-boundary {
fill: none;
stroke: #fff;
stroke-width: .5px;
}
.state-boundary {
fill: none;
stroke: #fff;
}
.border {
stroke: #000;
fill: none;
}
</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://cdnjs.cloudflare.com/ajax/libs/d3-composite-projections/0.3.5/conicConformalPortugal-proj.min.js"></script>
<script>
var width = 900,
height = 500;
var projection = d3.geo.conicConformalPortugal();
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("https://cdn.rawgit.com/mbostock/4090846/raw/8a7f176072d508218e120773943b595c998991be/world-50m.json", function(error, world) {
var land = topojson.feature(world, world.objects.countries);
svg.selectAll("path")
.data(land.features)
.enter()
.append("path")
.attr("d", path)
.style("stroke","#000")
.style("stroke-width",".5px")
.style("fill","#aca")
.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