Skip to content

Instantly share code, notes, and snippets.

@tobi
Created May 17, 2013 21:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobi/5602135 to your computer and use it in GitHub Desktop.
Save tobi/5602135 to your computer and use it in GitHub Desktop.
A CodePen by Tobias Lütke.
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/d3.geo.projection.v0.min.js"></script>
<script src="http://d3js.org/topojson.v0.min.js"></script>
// NYC 40.7142° N, 74.0064° W
var nyc = [40.718119,-73.991547]
var sf = [37.76678,-122.423916]
var tokyo = [35.682956,139.703522]
var places = [nyc, sf, tokyo]
var width = 960,
height = 480;
var projection = d3.geo.kavrayskiy7()
.scale(153)
//.translate([width / 2, height / 2])
.precision(.1);
console.log(projection(nyc))
var path = d3.geo.path()
.projection(projection);
var graticule = d3.geo.graticule();
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://raw.github.com/mbostock/topojson/master/examples/world-50m.json", function(error, world) {
svg.insert("path", ".graticule")
.datum(topojson.feature(world, world.objects.land))
.attr("class", "land")
.attr("d", path);
svg.insert("path", ".graticule")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
.attr("class", "boundary")
.attr("d", path);
});
translate = function(d) {
return "translate(" + projection([d[1], d[0]]) + ")";
}
var place = svg.selectAll("circle").data(places).enter().append("circle")
place.attr("transform", translate)
.attr("class", "marker")
.attr("r", 3)
.transition()
.attr("r", 5)
.duration(750)
place.append("circle")
.style("fill", "none")
.attr("r", 20)
.style("fill", "none")
.style("stroke", "red")
.style("stroke-opacity", 1e-6)
.style("stroke-width", 3)
d3.select(self.frameElement).style("height", height + "px");
.graticule {
fill: none;
stroke: #777;
stroke-width: .5px;
stroke-opacity: .5;
}
.land {
fill: #222;
}
.marker {
fill: rbg(242, 247, 250);
}
.boundary {
fill: none;
stroke: #fff;
stroke-width: .5px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment